Code Edit Region
Insert a code edit region in a Standard Maple worksheet or document.
Steps to Inserting and Collapsing the Code Edit Region
Selecting a Programming Language (MapleSim Users)
Syntax and Error Checking
Copying and Pasting Embedded Components
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
The code edit region lets you enter Maple 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 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 Enter 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.
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.
Enter your program or commands. A comment may be included before the program (see step 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.
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).
If you have MapleSim installed, you can choose between the Maple programming language or the Modelica programming language.
To select a programming language for the code editor, do the following:
Click in the code edit region.
In the Code Edit Region context panel select either Maple or Modelica from the language list.
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.
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:
In your standard Maple worksheet, select the embedded component that you want to copy.
Right-click the embedded component, then select Copy from the context menu. Alternatively, press Ctrl + C to copy the embedded component.
Right-click inside the code edit region, then select Paste from the context menu. Alternatively, press Ctrl + V to copy the embedded component.
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.)
Syntax templates are available in the Code Editor for automatic completion of certain common programming tasks, such as if statements. The following tables outline the available templates for Maple and Modelica syntax and how to invoke them. Note that for the entries in the To Insert... column in each table, the pipe character (|) represents the position of the cursor after the template has been inserted.
if | then
"if" followed by Ctrl + Shift + Space
if | then
"ife" followed by Ctrl + Shift + Space
proc( | )
"proc" followed by Ctrl + Shift + Space
"module" followed by Ctrl + Shift + Space
"block" followed by Ctrl + Shift + Space
"model" followed by Ctrl + Shift + Space
"function" followed by Ctrl + Shift + Space
"connector" followed by Ctrl + Shift + Space
"package" followed by Ctrl + Shift + Space
"record" followed by Ctrl + Shift + Space
for | loop
"for" followed by Ctrl + Shift + Space
if | then
elseif ___ then
"ifei" followed by Ctrl + Shift + Space
when | then
"when" followed by Ctrl + Shift + Space
elsewhen ___ then
"whene" followed by Ctrl + Shift + Space
while | loop..
"while" followed by Ctrl + Shift + Space
"loop" followed by Ctrl + Shift + Space
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:
Open the Code Editor by clicking the Startup Code button (
) from the toolbar.
In the Code Editor window, select File, then Import Code (or Export Code).
Locate and specify your target file.
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.
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:
Click anywhere inside the code edit region or select the code edit region.
Click the execute button (
) from the toolbar.
The code in the code edit region is executed. Any output from this code is displayed in the worksheet, below the code edit region.
Click anywhere inside the code edit region and use Evaluate > Execute Code or any of the following key combinations:
Ctrl + E (Command + E, for Mac)
Ctrl + = (Command + =, for Mac)
Alt + Enter
Executing Code in a Collapsed Code Edit Region
When collapsed, execute the code contained in the code edit region by doing the following:
If the code edit region is collapsed, click on the code editor icon.
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.
You can hide the border or line numbers in a code edit region.
To hide or show the border or line numbers:
Click inside the code edit region.
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.
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.
true or false
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.
Display (true) or hide (false) line numbers.
Specifies if the code edit region component is expanded or collapsed. By default, the value is true.
The height of the expanded code edit region, in pixels. By default, the value is 500. This option is only used if autofit=false.
The width of the expanded code edit region, in pixels. By default, the value is 200. This option is only used if autofit=false.
Display (true) or hide (false) borders.
The type of the component. This returns "CodeEditRegion".
The contents of the code edit region.
Specifies if the code edit region component is visible. By default, the value is true.
Maple Worksheet Toolbar
Setting the Autoexecute Feature
Download Help Document
What kind of issue would you like to report? (Optional)