Collapse Code Edit Region - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Getting Started : Menus : Document Menu Bar : View Menu : Collapse Code Edit Region

Code Edit Region

insert a code edit region in a worksheet or document

 

Description

Steps to Inserting and Collapsing the Code Edit Region

Selecting a Programming Language

Using Syntax Templates

Syntax and Error Checking

Copying and Pasting Embedded Components

Inserting Expressions from the Expression Palette

Inserting Units from the Units Palette

Importing and Exporting Code with the Code Editor

Executing Code within the Code Editor

Changing the Appearance of a Code Edit Region

Code Edit Region Properties

Description

• 

The code edit region lets you enter Maple or Python commands and programs in one confined region. If you have MapleSim installed, Modelica syntax is also available to you.

• 

You can execute your code and then collapse the region to hide it.

• 

The code editor includes many features to make it easier to write, read, and debug Maple code, such as syntax highlighting, error checking, bracket matching, command completion, automatic text wrapping, optional line number display, and automatic indenting. The editor is available for managing Startup Code, inline Code Edit Regions, and code attached to Embedded Components.

• 

When writing a program within the code edit region, you can press Shift + Enter (Shift + Return, for Mac) to advance the cursor to the next line. Indenting is done automatically. After entering the first line of a new module, procedure, or if/then statement, subsequent lines are automatically indented.

• 

You can use command completion within this region to reduce the amount of typing. Invoking command completion in the code edit region is done by typing the first few characters of a Maple command in the code editor. This displays a popup list of matching commands to choose from.

• 

The code edit region can be embedded in the Standard Maple worksheet or document.

• 

You can enter or exit the Code Edit Region using up and down arrow keys.

• 

To display properties for the code edit region, click  to open the Code Edit Region context panel.

Steps to Inserting and Collapsing the Code Edit Region

1. 

To insert a code edit region, from the Maple worksheet toolbar, click the Insert Code Edit Region button ( ). Alternatively, from the Insert menu, select Code Edit Region.

2. 

Enter your program or commands. A comment may be included before the program (see step 3).

3. 

To collapse the code edit region, click the region, then in the Code Edit Region context panel, clear the check box for Expanded.  Alternatively, press Alt + C (Command + Alt + C, for Mac), or use View > Collapse Code Edit Region.
When a code edit region is collapsed, an icon displays within the worksheet or document marking the code edit region, and all but the first line of the procedure will be suppressed. The first line of the procedure displays to the right of the icon. A comment may be included before the procedure to display a descriptive heading instead of the first line of the procedure. To suppress the printing of the first line of the procedure, insert a blank line on the first line of the code edit region.

4. 

To expand the region, click the collapsed icon    , then from the Code Edit Region context panel check Expanded. Alternatively you can expand the region by selecting Expand Code Edit Region from the View menu, or by pressing Alt + X (Command + Alt + X, for Mac).

Selecting a Programming Language

You can choose between the Maple programming language (the default), the Python programming language, and plain text. Plain text means that the region is not executed.  If you have MapleSim installed, you can also choose the Modelica programming language.

To select a programming language for the code editor, do the following:

1. 

Click in the code edit region.

2. 

In the Code Edit Region context panel select either Maple, Python, Plain Text, or Modelica from the language list.

Using Syntax Templates

Syntax templates are available in the Code Editor for automatic completion of certain common programming tasks, such as if statements.  For information on the available templates and how to invoke them, see Syntax Templates for Code Editing.

Syntax and Error Checking

The following applies only to Code Edit Regions using the Maple programming language.

The Code Editor contains the following syntax and error checking features:

• 

Code is checked for errors continuously as you type.

• 

Syntax errors are displayed inline.

• 

Syntax Highlighting. Maple keywords and operators are colored to help spot typographical errors and identify code blocks.

• 

Bracket Matching. Typing a new bracket character or positioning the cursor next to an existing one produces a visual highlight on its counterpart.

• 

Quote Matching:  Mismatched or missing single-, double-, and back-quote characters are highlighted.

Controlling Syntax Checks

You can set the syntax checking level using Edit > Check Syntax Level or through the Display tab of the Options Dialog.  Select one of the following three options:

• 

Display only severe errors.

• 

Display severe and serious errors (default)

• 

Display warnings as well as severe and serious errors.

When you change this setting, the new level applied to all code editors in the document, including startup code.

Syntax checking is done using mint, and the syntax checking levels correspond to infolevel 1, 2, or 3 for mint.

By default, automatic syntax checking is enabled. This provides continuous syntax checking.  To turn this feature off, clear the check box Check Syntax Automatically in the Edit menu. As an alternative, perform a syntax check: From the Edit menu, select Check Syntax Now. It is recommended that you check the syntax before saving, so that your startup code doesn't prevent Maple from successfully opening. You can also turn automatic syntax checking on or off through the Options dialog.

Copying and Pasting Embedded Components

In a standard Maple worksheet, you can paste embedded components into the code editor. If you copy an embedded component from the worksheet and then paste it into any code editor (startup code, embedded component code, or a code edit region), the name of the component will be inserted (prefixed with "%", to conform to the convention for DocumentTools:-Do).

To copy and paste an embedded component into a code edit region:

1. 

In your standard Maple worksheet, select the embedded component that you want to copy.

2. 

Right-click the embedded component, then select Copy from the context menu. Alternatively, press Ctrl + C to copy the embedded component.

3. 

Right-click inside the code edit region, then select Paste from the context menu. Alternatively, press Ctrl + V to copy the embedded component.

4. 

The name of the embedded component, preceded by the % symbol, is copied to the code edit region.

 

Note: In any code editor, invoking command completion on something beginning with "%" will bring up a list of embedded components whose names start with whatever comes after the "%". (Invoking completion on "%" with no suffix will list all of the components in the worksheet.)

Inserting Expressions from the Expression Palette

You can use the 2-D expressions from the expression palette to add 1-D math to the code edit region.

To do this, make sure that the Expressions palette is visible in the palette pane.

Postion your cursor in the code edit region where you want to place the 1-D math expression.

From the expanded Expressions palette, select the 2-D math version of the expression you want to add to the code edit region.

Edit the variables in the 1-D expression as required.

Add a semicolon to the end of the expression.

Inserting Units from the Units Palette

Similar to inserting expressions from the Expression palette, you can insert units from the Units palette in to the code edit region.

To do this:

1. Position your cursor in the code edit region where you want to insert the units.

2. From the Units palette, select the desired Dimensionality from the list (e.g. length, mass, etc.)

3.Select the appropriate units from the palette.

Note: You can also use the CTRL + Shift + U key combination to enter units in the code edit region.

 

Importing and Exporting Code with the Code Editor

You can import code from an MPL file or other text format directly into your code editor, or export the contents of a code editor to a text file.

To import or export Maple code using the Code Editor:

1. 

Open the Code Editor by clicking the Startup Code button ( ) from the toolbar.

2. 

In the Code Editor window, select File, then Import Code (or Export Code).

3. 

Locate and specify your target file.

4. 

Click OK.

To export an entire worksheet that includes a code edit region to an MPL file, export the worksheet as Maple Input.  For details on what is maintained, see Translation of Maple Worksheets to Maple Input.

Executing Code within the Code Editor

You can execute the code inside the code edit region, whether it is collapsed or expanded.

 Executing Code in an Expanded Code Edit Region

When expanded, execute the code contained in the code edit region by doing the following:

1. 

Click anywhere inside the code edit region or select the code edit region. From here you can execute the code doing any of the following:

• 

Click the execute button ( ) from the toolbar.

• 

Press Enter (Return, for Mac)

• 

Evaluate > Execute Code

• 

Ctrl + E (Command + E, for Mac)

• 

Ctrl + = (Command + =, for Mac)

• 

Alt + Enter (Alt + Return, for Mac)

Executing Code in a Collapsed Code Edit Region

When collapsed, execute the code contained in the code edit region by doing the following:

1. 

If the code edit region is collapsed, click on the code editor icon.

2. 

The code in the code edit region is executed. Any output from this code is displayed in the worksheet, below the code edit region.

 

Notes: 

• 

If you select Python as the programming language, the code will be executed by a Python session associated with the Python package. Any state changed can be queried tools from this package such as Python:-GetVariable or Python:-EvalString.

• 

The option to execute code in the code edit region is not available if you select Modelica as your programming language.

• 

You can set autoexecute on a code edit region by selecting Set Selection to Autoexecute from the Evaluate menu or by right-clicking in the marker area and selecting Autoexecute->Set Selection to Autoexecute. For more information on setting the autoexecute feature, see Setting the Autoexecute Feature.

Changing the Appearance of a Code Edit Region

You can hide the border or line numbers in a code edit region.

To hide or show the border or line numbers:

1. 

Click inside the code edit region.

2. 

From the Code Edit Region Properties in the Context Panel, select or clear the check boxes corresponding to the options you want to display or hide.

By default, code edit regions have an auto-fit property, meaning the code edit region's width fits your Maple window and the code edit region automatically expands as lines of code are added.

If you turn off the auto-fit property, you can control the options for the width and height of the code edit region and whether automatic text wrapping is used in the Code Edit Region Properties in the Context Panel.

Code Edit Region Properties

• 

The following table describes the control and use of the code edit region options.

  

An x in the Get column indicates that the option can be read, that is, retrieved by using the DocumentTools[GetProperty] tool.

  

An x in the Set column indicates that the option can be written, that is, set by using the DocumentTools[SetProperty] tool.

  

 

Option

Get

Set

Option Type

autofit

x

x

true or false

codelanguage

x

x

string

codelinenumbers

x

x

true or false

expanded

x

x

true or false

pixelheight

x

x

positive integer

pixelwidth

x

x

positive integer

showborders

x

x

true or false

type

x

 

string

value

x

x

string

visible

x

x

true or false

  

 

  

autofit 

  

Specifies if the code edit region's width fits your Maple window and the code edit region automatically expands as lines of code are added. By default, the value is true. Note: The autofit feature only stays enabled as long as you don't resize the window manually.

  

codelanguage

  

The language expected in the code edit region, one of text/maple (Maple),  text/x-python (Python), or text/plain (plain text, non-executable). The default value is text/maple.

  

codelinenumbers

  

Display (true) or hide (false) line numbers.

  

expanded 

  

Specifies if the code edit region component is expanded or collapsed. By default, the value is true.

  

pixelheight 

  

The height of the expanded code edit region, in pixels. By default, the value is 500. This option is only used if autofit=false.

  

pixelwidth 

  

The width of the expanded code edit region, in pixels. By default, the value is 200. This option is only used if autofit=false.

  

showborders

  

Display (true) or hide (false) borders.

  

type 

  

The type of the component. This returns "CodeEditRegion".

  

value

  

The contents of the code edit region.

  

visible 

  

Specifies if the code edit region component is visible. By default, the value is true.

See Also

comment

DocumentTools

DocumentTools[GetProperty]

DocumentTools[SetProperty]

Embedded Components

for

Maple Worksheet Toolbar

module

proc

Setting the Autoexecute Feature

Startup Code