Code Edit Region - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : CodeEditRegion

Code Edit Region

Insert a code edit region in a Standard Maple worksheet or document.

 

Description

Steps to Inserting and Collapsing the Code Edit Region

Selecting a Programming Language (MapleSim Users)

Syntax and Error Checking

Copying and Pasting Embedded Components

Syntax Templates

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 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, 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.

• 

Command completion is also active within this region to reduce the amount of typing. Invoking command completion in the code edit region is done by entering the start of a command and pressing Ctrl + Space.

• 

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

• 

To display properties for the code edit region, right-click the region (for Macintosh, Control-click) and select Component Properties.

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, right-click the region (for Macintosh, Control-click) and select Collapse Code Edit Region. Alternatively, press Alt + C (for Macintosh, Meta + Alt + C), or use View > Collapse Code Edit Region. When collapsing the code edit region, 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. You can also collapse the code edit region by selecting Collapse Code Edit Region from the View menu.

4. 

To expand the region, right-click the collapsed icon    (for Macintosh, Control-click) and select Expand Code Edit Region. Alternatively you can expand the region by selecting Expand Code Edit Region from the View menu, or by pressing Alt + X (for Macintosh, Meta + Alt + X).

Selecting a Programming Language (MapleSim Users)

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:

1. 

Right click on the code edit region.

2. 

From the context menu select Component Properties...

3. 

In the Code Edit Region Properties window, select either Maple or Modelica from the Language list.

4. 

Click OK.

Syntax and Error Checking

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

• 

Code is checked for errors continuously as you type.

• 

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.

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.)

Syntax Templates

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.

To insert...

Type this...

if  |  then

    

     end if:

"if" followed by Ctrl + Shift + Space

if  | then

     

else

         

end if:

"ife" followed by Ctrl + Shift + Space

proc( | )

end proc:

"proc" followed by Ctrl + Shift + Space

module()

           export |

end module:

"module" followed by Ctrl + Shift + Space

To insert...

Type this...

block  |

 

protected

             

equation

                 

end ___;

"block" followed by Ctrl + Shift + Space

model  |

        

protected

  

equation

                        

end ___;

"model" followed by Ctrl + Shift + Space

function  |

        

protected

   

algorithm

   

end ___;

"function" followed by Ctrl + Shift + Space

connector  |

     

end ___;

"connector" followed by Ctrl + Shift + Space

package  |

   

end ___;

"package" followed by Ctrl + Shift + Space

record  |  

 

end ___;

"record" followed by Ctrl + Shift + Space

for  |  loop

 

end for;

"for" followed by Ctrl + Shift + Space

if  |  then

 

end if;

"if" followed by Ctrl + Shift + Space

if  |  then

 

else

 

end if;

"ife" followed by Ctrl + Shift + Space

if  |  then

 

elseif ___ then

           

else

 

end if;

"ifei" followed by Ctrl + Shift + Space

when  |  then

  

end  when;

"when" followed by Ctrl + Shift + Space

when  |  then

 

elsewhen ___  then

   

end when;

"whene" followed by Ctrl + Shift + Space

while  |  loop..

 

end while;

"while" followed by Ctrl + Shift + Space

loop

      |

end loop;

"loop" followed by Ctrl + Shift + Space

Importing and Exporting Code with the Code Editor

You can import code from .mpl or other text formats 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.

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. 

Right-click anywhere inside the code edit region to display the context menu.

2. 

From the context menu, select Execute Code.

3. 

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

Alternatively,

1. 

Click anywhere inside the code edit region and use any of the following key combinations:

• 

 Ctrl + E

• 

 Ctrl + =

• 

 Alt + Enter

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.

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: 

• 

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

• 

You can set auto-execute on a code edit region by selecting Autoexecute from the Format menu or by right-clicking in the marker area and selecting Autoexecute->Set. For more information on setting the autoexecute feature, click here.

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. 

Right-click inside the code edit region.

2. 

From the CodeEditRegion Properties window, select or clear the check boxes corresponding to the options you want to display or hide.

3. 

Click OK.

Code Edit Region Properties

• 

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

  

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

  

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

Option

G

S

Option Type

autoexpand

x

x

true or false

pixelHeight

x

x

positive integer

pixelWidth

x

x

positive integer

visible

x

x

true or false

value

x

x

string

codeLineNumbers

x

x

true or false

showBorders

x

x

true or false

              

  

autoexpand 

  

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

  

pixelHeight 

  

The height of the expanded code edit region, in pixels. By default, the value is 500.

  

pixelWidth 

  

The width of the expanded code edit region, in pixels. By default, the value is 200.

  

visible 

  

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

  

value

  

The contents of the code edit region.

  

codeLineNumbers

  

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

  

autoexpand

  

Display (true) or hide (false) borders.

See Also

comment

for

module

proc

Startup Code

Embedded Components

Maple Worksheet Toolbar

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam