ElementaryCodeEditor
Aus ExpeccoWiki
The code editor is used to view and edit the code of elementary blocks. It is found in the "Code" tab after selecting an elementary block in the navigation tree. This editor is also used in the file-viewer, the inspector and the debugger windows (actually: everywhere within expecco, where plaintext is shown). The file-editor is a powerful tool by itself; providing a much more sophisticated editing environment as some of the standard tools, such as "vi" or "notepad".
Inhaltsverzeichnis |
Edit Functions
The editor is based on the Smalltalk/X code editor. It offers a number of functions via its popup (right-button) menu. In addition to the wellknown copy-cut-paste functions, the editor supports:
- Arbitrary levels of undo/redo
- Macros (learn / execute)
- Code indent/undent and format
- Repeat-last-operation for search, cut and replace operations
- Search for class, implementation and users of a function (method search)
- Immediate code execution (doIt/printIt/inspectIt)
- Code sniplets and code completion
Immediate Execution
One of the most useful functions is "Immediate Execution (doIt/printIt)". This executes the selected piece of text as a program in the current programming language (i.e. JavaScript or Smalltalk). For example, to compute a mathematical value like "10.factorial() / 10", type it anywhere in the code-editor, select it and apply the "printIt" menu function. The result will be inserted after the selection. This function is very useful to test and try a piece of code while writing it. For example, if you want to check if your code is actually performing the desired operation, simply try it with some test data. Experienced programmers usually even add a piece of commented test-code to the end of more complicated elementary blocks, to give the next programmer an example of its operation.
Search for Implementation / Uses of a Function
Another very useful function is the "Implementor"-search (which is found in the "more"-submenu. It is best described by an example: assume, that you want to know how the "indexOf:" array search-function is implemented. To do this, select the name of the function (indexOf:) in the text (or type it, if not already somewhere present) and select the "Implementors" menu function. A browser will be opened which shows all the implementations of that function in the system.
The complementary function is "Senders" - this opens a browser on all uses of a particular function. This is helpful to see examples of "how-things are done" by looking at how that function is used by other parts of the system.
Notice, that for those functions to be useful, the system's source code must have been installed (make sure to check the "Install Source Code" option during the installation procedure.
Macros
Pressing the "Learn Key" (CTRL-F2) enters the learn mode. The editor will remember all keyboard input (both text and command keys) in an internal macro buffer, until the learn-key is pressed again. Then, these operations can be repeated via the "Execute Key" (ALT-F2). For example, if you have some text pasted from some external data source (for example: measurement data) and want to bring it into the correct form for an array constant (for example, insert a comma after every digit), perform the operation once using function keys only (i.e. cursor movements, search forward, skip word etc.) while in learn mode. Make sure, that the cursor is finally positioned before the next possible application of the macro. Then, simply press ALT-F2 and get your edit operation repeated for every value. Using macros, it is very easy to get linear sequences of numbers into a tabular or other formats. Other applications are the grouping of linear data into groups of N, inserting parenthesises, commas or semicolons or to add a number prefix such as "0x" for javascript or "16r" for smalltalk to a collection of number values.
Search and Replace
To replace, simply select the original and type in the replacement. Choose the "Again (i.e. repeat)" function to search for the next occurrence of the original text and have it also replaced. You can also "Search-forward" and then press "Again" for a more controlled operation. The same scheme is used for "Cut" and "Search and Cut".
If you have many such replacements to perform, select the "Again for All" function from the popup-menu. It repeats the last cut or replace until the end of your text.
Function Keys
The most common edit functions are also found on convenient function keys:
| CTRL-x | cut |
| CTRL-c | copy |
| CTRL-v | paste |
| CTRL-d | doIt |
| CTRL-p | printIt |
| ALT-B | browse the class (press shift for upper-case b) |
| ALT-I | implementors (upper-case i) |
| CTRL-l | goto line (lower-case l) |
| CTRL-( | goto matching parenthesis |
| ALT-f | search again, forward |
| ALT-b | search again, backward |
| F6 | change case of selection (multitoggle) |
| F9 | undent by 4 (current line or selected range) |
| F10 | indent by 4 (current line or selected range) |
| F11 | undent by 1 (current line or selected range) |
| F12 | indent by 1 (current line or selected range) |
| F8 | repeat last cut or replace (i.e. search and replace) |
| CTRL-F2 | toggle learn-mode |
| ALT-F2 | execute learned macro |
Function Key Customization
The above keyboard shortcuts are read and installed by a file named "keyboard.rc", which is consulted and read for keyboard definitions during startup time.
Thus, it is possible to both modify the current shortcut key settings or to add new keyboard commands and macros by modifying that file in any text editor. The format there is pretty straight-forward and easy to understand (for details, consult the underlying execution framework's documentation in http://live.exept.de/doc/online/english/custom/TOP.html#KEYBOARD).
For other editors see: Editors
The full online documentation can be found under: Online Documentation