Script Editing Window
These windows allow one to edit scripts. For a list of available commands see Script Commands; for general information about scripts see About scripts. Several basic editing functions are available in the window. Text can be selected with the mouse. Text can be cut with Ctrl X, copied with Ctrl C, and pasted with Ctrl V. Ctrl Z will undo the last action. While you are editing a script, the text in the window will not match the version of the script stored in the program. However, running the script, closing the editing window with the OK button, switching the editing window to another script, or even exiting the program will transfer the text in the window to the program's memory.
The buttons above the text area can be used to switch the Editor window to the next or previous available script, or to shift the current script down or up in the list of scripts. Specifically:
Left and Right Editor buttons - Switch the editor window to the previous or next script that is not already open in an editor.
Up and Down Script buttons - Shift a script in the list of scripts; i.e., swap it with the previous or next numbered script. 'Up' and 'down' here refer to the vertical position of scripts in the menu and toolbar. The window will stay with the current script and change its number. If the adjacent script is also open in an editor, both windows will change. These buttons can be disabled unless in Administrator mode with the property 'ShiftScriptOnlyInAdmin'.
Indentation Buttons - This row of buttons is useful for scripting in Python; they can be hidden with the Show Indent Buttons command in the script menu.
Indent - Fix - Adjust the indentation of all selected (highlighted) lines to be the nearest multiple of the indent size. The program will examine all the selected to see what deviations need to be fixed. If they all involve changes by 1 space, it will make the changes. If any of the deviations cannot be resolved because they are half of the indent size, it will ask whether to cancel the operation so that you can examine the lines first. If any of them involve more than one space but are not ambiguous (you would need an indent size over 4 for this to happen), it will ask whether you want to fix just the ones that are off by one space or to fix all of them.
Indent - Increase - Add one unit of indentation (the indent size) to all of the selected lines.
Indent - Reduce - Remove one unit of indentation from all of the selected lines if possible. If any lines are indented by less than one unit, nothing will be done.
Completions and Auto-indenting - Below these buttons is a line of text that starts out with a reminder that you can use Tab or ` (the back-tick character) to automatically complete a command name (the first word on a line) as well as convert it to a standard mixed-case form. Tab may not work on non-US keyboards, but ` always will. When you start editing in a window, this line will list up to 10 possible completions of the current text as you type a command. Only a few will show up at the default window size; make the window wider to see more completions.
Another consequence of typing Tab or ` anywhere on the line is that the editor will set the indentation of the current line based on the indentation of the previous line, whether the previous line starts a block (i.e., with If, Else, Elseif, Loop, or Function), whether the current line ends such a block, and whether it is a continuation line. The amount of additional space in a block or for continuation lines can be controlled with the Set Indent Size command in the Script menu.
Behavior for Python scripts - If a script starts with "#!Pyth", the editor scans the start of the script to see how Serialem script functions should be prefixed, stopping at the first non-blank line that is neither a comment nor an import line. If it encounters either a line importing serialem, or a '#serialemPrefix' line specifying the prefix, that determines what prefix it expects to find before commands: either no prefix if you import as 'from serialem import *', prefix 'serialem' if you use 'import serialem', or the alias if you import with an alias, such as 'import serialem as sem'. When you type the completion character, it looks back to the beginning of the word to see if there is already a namespace prefix. If so, and it does not match the expected prefix, it will not attempt to complete the word, just manage indentation. If it does match or is not present, then it will try to complete the word unless it is a Python keyword, and insert the prefix if appropriate. For example, if you use 'import serialem' and type the completion character after 'choo', it will insert 'serialem.ChooserForNewFile'.
Completion works both at the beginning of the line and for a word after an '='.
Indentation will follow the indentation of the previous line, adding a unit of indentation if that line ends in ':'. However, there is no way for it to tell in general when to remove indentation, as there is with regular scripting. One mildly helpful feature is available if you leave a blank line after the end of a block. Typing the completion character more than once will make it toggle between the indentation of the previous line and one less unit of indentation.
A controllable way to remove one unit of indentation at a time on any line is to hold down the Shift key while typing the completion character. This allows you to close a block without a blank line or close more than one block. The 'Indent' buttons at the bottom of the editor should also be helpful.
The buttons below the text area perform the following functions:
Run - will save the script in program memory and run it. Pressing Ctrl-Enter within the editing window will also run the script.
Cancel - will close the window without saving the most recent changes in program memory.
OK - will save the script in program memory and close the window.
Load - will allow you to read a script from a file into the current script. Once a script has been read from a file, the Save button will save it back to that file.
Find - will search for text in the script. An entry box will open for the text to find. The search is case-insensitive.
To Line - will allow you to enter a line number to go to. After an error in a Python script, the default value i nthe entry box will be line with the error. The cursor will be moved to the specified line, the window will be scrolled, and the first three characters on the line will be selected to make it more visible.
Save - will allow you to save this script to a text file. If you have saved it to a file before, or if you loaded it from a file, it will be saved to the same file. Otherwise you will enter the Save As dialog box to specify a file
Save As - will allow you to save this script to a different file via the Save As dialog box.