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 (Filebrowser, Data-Viewers, Inspectors, Notepad, Documentation Editor etc.)
To the right, you see an example for some code in the editor.
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 (called "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.
Other (non-builtin) languages are processed and executed by external interpreters, and the editor is not aware of or supporting any language specific editing support.
For example, shell and batch scripts are executed by forwarding the code to an appropriate command line interpreters. Groovy code is forwarded to a Groovy interpreter running inside a Java VM. Ruby, Python, Tcl or Node.js programs can be executed via 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 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 a piece of text word-wise.
Triple click to select a line. Triple click and drag (not releasing the mouse button after the third click) will select a piece of 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.
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 should 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.|
|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|
|Find||Ctrl-f||Open a search dialog|
|Find-Forward||Command-f||Search forward for the currently selected text or the previous searched text (if the text selection was unchanged).|
|Find-Backward||Command-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||Command-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.
|Indent4||F12||indent the selected lines by 4|
|Undent4||F11||undent the selected lines by 4|
|Indent1||F10||indent the selected lines by 1|
|Undent1||F9||undent the selected lines by 1|
|Change Case||F6||toggle the selection between UPPERCASE, Titlecase and lowercase|
Thus, to search text that is already on the screen, select it and press Command-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 Command-f (Forward search) and F8 (Again).
DoIt and PrintIt
Date.today() Time.now() UUID.new() OperatingSystem.getHostName()
or in Smalltalk:
Date today Time now UUID new OperatingSystem getHostName
Of course, this 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. For incremental programming, place a halt in you elementary block's code, and write the program (after testing it with doIt/printIt) right in the debugger.
For a full list of useful expressions, please refer to the Smalltalk/X Online Documentation.
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.
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 for users used to vi, 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 editors 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.
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 Smalltalk 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.
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, 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