Script editor
Script Editor - is a Engee workspace tool designed for working with interactive scripts.
An Interactive script (or simply a script) is a file containing several commands that are executed sequentially.
To open Script Editor, click on the icon in the workspace:
Working with scripts
Creating a script
To create a script, press + in the script editor and select the desired format:
->
By default, Engee scripts are in
|
You can create a script using file browser . To do this, right-click in an empty area of the file browser window to bring up the context menu, then select Create and Script:
Script editor sections
In the script editor, you can create a code cell or a text cell.
To create cells, move the mouse pointer to the upper edge of the script editor window to display the cell selection button:
-
+ Code - creates a new section with a code (code cell). In this cell all possibilities of writing code in programming language Engee are available.
-
+ Text - creates a new section with text (text cell). In this section you can add and format any description, pictures, tables, links, etc.
New sections can be added anywhere in the workspace of the script editor (e.g., at the beginning, end, or between two other sections). |
Section with code
Let’s create a code section and look at its interface:
-
Run and advance - executes the code in the given section.
-
Run to end - executes all sections with a code below the selected section.
-
Run before cell - executes all sections with code above the selected section.
-
Change position of output - selects the position for output. Has two options:
-
4.1. Code output on the right - Outputs the result on the right for a specific section.
-
4.2. Hide code output - hides the result selection for a specific section.
-
-
Mask - adds a mask for the selected code cell (for details see Code cell masks).
-
Move down - moves the section one down.
-
Move up - moves the section one up.
-
Copy - copies a section.
-
Paste - pastes a section.
-
Remove - deletes a section.
In a code cell you can also:
-
Execute the highlighted code section (PCM on the highlighted line or hotkey Shift+F7):
-
Execute the current line with the cursor (Ctrl+Shift+F5 on Windows/Linux or Shift+⌘+F5 on macOS).
Text section
By default, the WYSIWYG ("What you see is what you get") editor is used to work with text cells. Read more about marking up text with the editor at link. |
Let’s create a section with text:
Double click on the section to open the input field, now you can enter the desired text in the cell that appears.
The markup languages Markdown are used for text formatting, with the possibility of extending the functionality with HTML and LaTeX. For more information about markup in a text cell, see Text markup in Engee.
Let’s take a look at the text cell interface:
-
- cancels the last action
-
- repeats the last cancelled action
-
- applies boldface to selected text
-
- italicise selected text
-
- applies a strikethrough effect to the text
-
- sets the heading level (H1-H6)
-
- creates a bulleted or numbered list
-
- hyperlink
-
- format text as a quote
-
- highlights text as a code snippet
-
- adds a checkbox to track tasks
-
- underlines the highlighted section
-
- monospaced font
-
- highlights text background
-
- change text colour
-
- adds a note block
-
- adds a hiding section
-
- insert an image
-
- adds a table
-
- edit mode, select one of three modes:
-
- WYSIWYG visual editor, immediately displays formatting without markup languages (used by default, recommended)
-
- Markdown markup, manual editing of source text
-
- displaying the result (preview) without the possibility of editing
-
Similar to code sections, the following commands are used in text cells: move, copy, paste and delete.
Hiding cells and content
To hide cells in the Engee script editor, a text cell must be marked as a paragraph using Markdown and have the appropriate level and location:
-
the cell must contain a Markdown-formatted header from level 1 to level 6 (
,
#
, etc.). -
a cell with a lower level header must be below the top level header.
You can hide it in the script editor:
-
code cells (have the lowest heading level);
-
text cells without headers (also the lowest level);
-
text cells with lower level headings.
If a text cell with a first-level heading has, for example, 10 code cells below it, this forms one section that will be hidden. When the 11th cell appears - a new paragraph with a first-level heading or the same level as the first text cell - a new section starts.
The first through sixth level text cell headings form Contents :
In the content you can:
-
Add a nested paragraph
- adds a text cell with a title to the level above. For example, if a nested paragraph is added to a first level text cell (
), it will become a second level cell (
#
). When the maximum nesting is reached (the last text cell has a sixth level heading) - the button is not available. -
Run paragraph
- starts execution of all cells with the code of the selected paragraph. If the paragraph does not contain any code cells - the button is unavailable.
-
Delete paragraph
- deletes the selected paragraph. Headers and code cells nested in the paragraph section will not be deleted.
Starting/stopping scripts
To start or stop a script, click the Start or Stop button. The buttons are located on the start panel of the script:
To run the section with the code, click on Execute. The result will be displayed below the section:
You can collapse the code execution output into a more compact form in case it takes up too much space. To do this, use the Limit output button:
To return the output to its previous state use the Disable output button.
To clear the results of executing code sections in the script, click the Clear output icon on the script launch panel.
Autosave
The autosave feature allows you to automatically save changes to interactive scripts, preventing data loss. To enable this feature, open the script editor window or any interactive script, click the triplet in the upper right corner and enable autosave:
Three autosave options are available in the menu:
-
afterDelay - the script is automatically saved after a certain delay time. When this parameter is selected, the delay is 1000 ms by default.
-
onFocusChange - the script is automatically saved after the editor loses focus. This means that when switching to another Engee window, changes in the script editor will be saved;
-
onWindowChange - the script is automatically saved when switching from the browser tab on which Engee is open to another tab. This means that when you change the browser tab from Engee to any other tab, changes in the script editor will be saved.
Masking code cells
Script Editor supports the ability to turn variables in code cells into convenient interactive elements - drop-down lists, input fields, sliders and other control components. For this purpose, the code cell masking mechanism is used to improve visual representation of scripts, hide technical implementation details and simplify data input.
To apply a mask, use the tool Mask , which appears when you hover over a code cell:
For more information on mask types, settings, and manual operation, see Code cell masks.
Breakpoints
The Engee editor supports adding breakpoints to code cells. This is useful when debugging scripts - code execution is paused at the desired line, which allows you to examine the behaviour of the program step by step and find errors.
To set a breakpoint, place the cursor on the left border of the required line and click the left mouse button:
To set the conditions, delete or temporarily disable a breakpoint, you can use the context menu (PCM on the red dot).
Engee offers different types of breakpoints: basic, conditional, delayed execution and others. The triggering conditions can be set via expressions, number of iterations or dependency on other points.
For more information about working with breakpoints, see Breakpoints in scripts.
Methods of programme control
The public methods (see Public methods of programme management for details) allow you to control Engee scripts without using the script editor interface. These commands are designed to work with script editor files and are invoked via engee.script
. Let’s look at each of these methods:
@include - includes (embeds) script code instead of calling a macro.
For example, we have a script named new.ngscript, in which the code a = 1
is written. Let’s create another script new_1.ngscript, in which we refer to the first script by the absolute path via @include
:
engee.script.@include("/user/new.ngscript")
The result of the code execution of the first script a = 1
will be included in the second script and will be equal to 1
.
The @include command and the code it embeds must not be in the same script. Otherwise, a cyclic dependency error will occur when @include must call itself.
|
edit - opens the script for editing.
Opens the script for editing at the specified path. If there is no script file, it is created automatically.
engee.script.edit("/user/new.ngscript")
If an extension other than .ngscript is specified, it will throw an ErrorException("path should end with.ngscriptextension") error.
|
extract_code - extracts code at the specified path.
Extracts code from the script at the specified path. For example, for script new.ngscript with code a = 1
:
engee.script.extract_code("/user/new.ngscript")
Output:
:($(Expr(:toplevel, :(#= none:1 =#), :(a = 1))))
Read more about other public methods used in scripts in the article Software control of modelling.