- 1 Introduction
- 2 Programming Language Awareness
- 3 Mouse Click and Selection
- 4 Special Characters
- 5 Editor Functions and Keyboard Shortcuts
- 6 Editor Customization
- 7 Break- and Tracepoints
- 8 Use of an External Editor
- 9 See Also
The code editor is used to view and edit the source code of an elementary block. It is found on the "Code" tab after selecting an elementary block in the navigation tree. The same editor is also used in all tools (File-Browser, Data-Viewers, Inspectors, Notepad, Documentation Editor, Debugger etc.)
An example for some code in the editor is shown on the right.
The editor consists of a language drop down list item at the top, and a code editor area, which covers the rest of the editor's space. The code input area is a regular text editor which provides syntax coloring and some code-related functions on its pop-up (right button) menu.
The drop down list selects the programming language in which the block is to be coded. If changed, the system tries to convert the current code into the newly selected language, which is only possible/supported for some language combinations. The block's icon is adjusted depending on the language.
When an elementary block is initially created, some template code is shown in the editor. This consists of the "
execute" function body, a comment which gives advice on how to access the input and output values, and a transcript command which prints a standard output message to the transcript. Thus, the block can be immediately executed and does "something useful". Once you get familiar with elementary code, this template comment can be disabled via the settings menu ("Extras" → "Settings" → "Look & Feel" → "Code Editor" → "Long Code Template").
Usually, you will cut out the comment and the transcript command, and replace it by your own code. The function name and body delimiters should be left as is. While typing, a just-in-time parser performs syntax coloring and some syntactic and semantic checks. Most errors and typos are thus detected immediately at editing time.
Programming Language Awareness
These built-in languages are fully supported by the code editor and the debugger: you can place breakpoints (or explicit "halts") into the code, single step, inspect local variables etc. Also, syntax coloring, code completion and quick syntax checking are supported for those built-in languages.
The API is described in the the "expecco API" document.
Non Builtin (Bridged) Languages
For some languages a bridge framework is provided. Bridges setup a communication channel to an external language interpreter. This interpreter is started once, when the very first such action is to be executed, and kept alive. So any internal state of the interpreter (open files, protocol channels, objects or frameworks) will be accessible by later actions.
For NodeJS and Python, debugging support is partially implemented or being developed.
Bridged code execution is supported for:
Non Builtin (Script) Languages
Other (non-builtin) script languages are processed and executed by external interpreters, and the editor may not be aware of or support any language specific editing support. For some languages, syntax highlighting and comment detection is provided. For other languages, neither breakpoints, nor single stepping, nor evaluation of expressions or inspection of values in the debugger are possible in general.
For example, shell and batch scripts are executed by forwarding the code to an appropriate command line interpreter.
are executed by an external scripting engine. Debugging facilities are limited for those external languages (no single stepping, for example). Although not normally a major issue (as these languages are less used inside expecco), language support for those is available by defining an external language editor in the settings dialog. For example, under Windows, a Notepad++ or under Unix, an Emacs editor may be useful in some situations.
Mouse Click and Selection
Single click the left mouse button to move the cursor. Click and drag to select a piece of text.
Double click to select a word. Double click and drag (not releasing the mouse button after the second click) will select more text word-wise.
Triple click to select a line. Triple click and drag (not releasing the mouse button after the third click) will select more text line-wise.
Quadruple click to select the whole text.
The selection can extended either by pressing the mouse button and the Shift key simultaneously, or the Shift key and one of the cursor keys. If no previous selection exists, the selection is extended from the previous cursor position.
A right button click shows the editor's menu, which contains more editing functions, including many useful operations in its "Misc" and "More" submenus.
To enter special characters which are not on your keyboard and cannot be entered via ALT-key combinations, open a "special characters"-dialog via the popup menu ("More" → "Special Characters"). This presents all possible characters of the Unicode character set. This dialog can be used like a second keyboard; click on the character to get it inserted at the current cursor position. You can keep this window open and around to enter multiple characters.
Editor Functions and Keyboard Shortcuts
The editor provides the most common edit functions both via its right-button pop-up menu and via keyboard shortcuts. For some functions, more than one keyboard shortcut is present (the reason is that on some systems, some shortcuts are reserved by the operating system or window manager, so that the alternative shortcut must be used).
A more detailed description of the editor's features is found in the Smalltalk/X online manual's "Editing Text" section.
The most useful operations are:
|Cut||Ctrl-x||Cut the selected text. The text is placed into the clipboard and can be pasted via Paste (also into other programs).|
|Copy||Ctrl-c||Copy the selected text. The text is placed into the clipboard and can be pasted via Paste.|
|Paste||Ctrl-v||Paste the previously copied or cut text (i.e. the text from the clipboard). The text can be pasted multiple times.|
|Paste Previous||Ctrl-V||Paste a previously copied or cut text (i.e. from the clipboard history).|
|Undo||Ctrl-z||Undo the previous edit operation or text insertion.|
|Redo||Ctrl-y||Undo the previous undo.|
|Delete||Del or Backspace||Delete the selected text without affecting the clipboard.|
|Again||F8||Repeat the previous cut or replace operation. Implies a search for the next occurrence of the affected text.|
This is a very useful function, eg. to replace multiple occurrences of a string by another, you double-click on the first, type over it, and press "Again" to repeat.
|Goto||Ctrl-g||Goto a given line number|
|Find||Ctrl-f||Open a search / search+replace dialog|
|Find-Forward||Cmd-f||Search forward for the currently selected text or the previous searched text (if the text selection was unchanged).|
|Find-Backward||Cmd-b||Search backward for the currently selected text or the previous searched text.|
|Next-Word||Ctrl-w||Move the cursor to the next word. Press multiple times to advance|
|Select-Word||Cmd-w||Select the word under the cursor, the space between or the next word.|
Press multiple times to advance
If there is no selection, the whole contents of the current cursor line is executed.
|Indent||select+Tab||indent the selected line(s) by one tab|
|Undent||select+Shift-Tab||undent the selected line(s) by one tab|
|Indent4||F12||indent the selected line(s) by 4|
|Undent4||F11||undent the selected line(s) by 4|
|Indent1||F10||indent the selected line(s) by 1|
|Undent1||F9||undent the selected line(s) by 1|
|Change Case||F6||toggle the selection between UPPERCASE, Titlecase and lowercase|
|Rename||F2||rename a variable (not supported by all programming language editors)|
The Cmd key is usually labeled "Cmd", "Alt" or "Meta", depending on your keyboard.
Thus, to search text that is already on the screen, select it and press Cmd-f.
If it is not already visible, press Ctrl-f.
To evaluate and paste, select some text and press Ctrl-p.
To replace a string with another, select it, type in the new text, and press F8 (Again) - and again, and again...
If you want to search first, before replacing, alternate between Cmd-f (Forward search) and F8 (Again).
DoIt and PrintIt
Especially the "DoIt", "PrintIt" and "InspectIt" functions deserve more explanation as they are often very useful.
Date.today() Time.now() UUID.new() OperatingSystem.getHostName() 1234567.nextPrime() 1234567.nextPowerOf2() Math.sin(45.degreesToRadians())
or in Smalltalk:
Date today Time now UUID new OperatingSystem getHostName 1234567 nextPrime 1234567 nextPowerOf2 45 degreesToRadians sin
Of course, this immediate expression evaluation is very useful while programming an elementary block. You can try out code fragments right in the editor. By the way: every window which shows code can evaluate code: the elementary block editor, the workspace windows and especially the debugger. In the debugger, local variables and self (this) can be used in evaluated code. For incremental programming, place a halt in your elementary block's code, and write the program (after testing it with doIt/printIt) right in the debugger (Click on the "Resend" button after a change, to restart the changed function's code).
Again (Repeat Last Edit)
The "Again" operation (press F8 or select it from the operations (= right-button) menu) repeats the last delete or replace operation, after searching for the next occurrence of the original string. So, to incrementally rename all occurrences of "foo" with "bar", find the very first occurrence "foo", select it, type "bar" over it. This is the first edit operation. Then press F8 to repeat this for the next occurrence of "foo" in the text.
The operations menu also offers an "Again until End" function in its "More" sub-menu. This performs multiple "Again" operations, until the original string is no longer found. Use this to replace ALL occurrences of a string by another.
More Useful Editor Commands
The popup-menu and especially the submenus under "More" and "Other" contain a number of additional, often very useful editor commands. Among many others, will find functions to paste the current date and time, to generate UUIDs or to sort your text alphabetically. A very useful function is also "Open Filebrowser on Selected Name", which is enabled if the current selected text is a valid filename.
Line End Behavior
By default, the editor is configured to treat the whole page like a piece of paper, where the cursor can be arbitrarily positioned. If you move the cursor, or click into the view, any short line will be automatically lengthened to the current cursor position, when a non-blank character is entered ("Rand-editor behavior").
This may be an unusual behavior if you are used to vi, emacs, notepad and other editors, which only allow positioning of the cursor to the actual line end, without automatic line lengthening. If you prefer this behavior, go to the editor's settings dialog ("Extras" → "Settings" → "Look & Feel" → "Code Editor") and toggle the "Standard Line-End Behavior" toggle. However, if you do so, it is probably a good idea to also check the "Automatic Indent" toggle.
Changing the Keyboard Mapping
The editor's keyboard-to-command mapping is loaded at startup time from a file named "
keyboard.rc" in the expecco installation folder. Once you get a little familiar with the syntax, you may even change the keyboard mapping and/or add additional macro functions to suit your personal preferences.
Detailed information on how this is one in found in the Smalltalk/X Documentation on Keyboard Customization.
Break- and Tracepoints
To toggle a breakpoint, double-click into the area left of the line-number, where the breakpoint or tracepoint should be placed. With shift pressed, a tracepoint will be placed, without shift, a breakpoint is toggled.
Breakpoints will open a debugger, tracepoints will simple send a trace message to the Transcript window (which should obviously be open).
The debugger allows for stepping, aborting or continuing.
Notice also, that not all language interpreters will handle interrupts at any time - especially interrupts while waiting for I/O or while setting up socket connections are uninterruptable in many interpreters (i.e. Node and Python), in contrast to the builtin languages ST and JS, which are interruptable and proceedable.
Use of an External Editor
If you prefer to use an external text editor, navigate to the externalTools Settings ("Extras" → "Settings" → "External Tools") and enter the path to your editor into the "Code Editor" field.
If that field is non-empty, an icon is shown in the elementary action's code page, which calls the configured editor on the current text.
A very powerful editor for any operating System is VisualStudio Code, other good editors for Windows are "notepad++", "Emacs" and "SciTE".
If an external editor is opened, expecco waits for the editor's executable to finish, then reads back the edited file. Some of the above commands will need an additional command line Argument, to ensure this (see the offered command list in the Settings dialgo for concrete examples).
For the programmer API for the builtin languages see: Expecco API,
Sections of interest are the Pin-API , Activity-API
For information on the functions available in the built-in classes (method protocol), please refer to the Smalltalk/X Online Documentation and especially the Class Reference. For example, some of the mathematical functions are described here and String processing functions are found here and here.
For elementary blocks in general, see ElementaryBlock Element
More information on the Debugger and Inspector are found in the tools section of the Smalltalk/X Online Documentation.