- 18.11 (released) ...
Recompiling and Editing
- Recompiling and executing after a change
- Views in the Editing Tool
- Basic editing facilities
- Search and replace
- Let the editor do the typing
- Using your own editor
So far we have relied on existing class texts. Fascinating as it may be to explore excellent software such as EiffelBase, you probably want to write your own too (with the help of the reusable components in the Eiffel libraries). EiffelStudio provides a built-in editor -- as well as the ability to use some other editor if you prefer -- and sophisticated compilation mechanisms.
When we started, we compiled the example system. Let's recompile it, just to see. We'll see compilation entries in the
Project menu, but the easiest for the moment is to use the compilation button () in the Project toolbar. Click this button. You haven't changed anything in the project since it was compiled (at least you were not supposed to!), so EiffelStudio will very quickly detect this and finish compilation. On our test platform this takes less than a second. Now of course we should see what happens if you do change something.
We don't want to touch EiffelBase classes (and in fact can't, since it is used in precompiled form), so let's focus on classes of our small root cluster. In the Groups tool, expand cluster
root_cluster and click class
PARENT to retarget the Development Window to it.
Make sure that the Editing Tool is big enough to display the text of the class:
The Editing Tool hosts a text editor which you can use to change the class text. Here the routine
display starts by outputting a simple message; let's precede it by another line of display to check that we affected the outcome. We'll want to add the following two lines just after the
do, before the first two instructions of the routine:
io.put_string ("THIS IS SOME ADDED TEXT")
You can just use copy-paste from the example above: select the two lines with the mouse, copy them using
Copy from the
Edit menu), then paste them just after the
Paste from the
Edit menu). Add or remove tabs to align with the rest of the routine, so that the result will look like what's shown on the next figure. Please check the result and be careful not to introduce any mistakes; in the next section we'll study how EiffelStudio will report syntax and other errors, but right now we want to see what happens when everything is right!
Now save your changes; you may indifferently use
Save entry from the
Edit menu, or the Save button (), at the cursor location on the figure. (If you forget to save, the next compilation will tell you so, and ask you if from now on you want all non-saved class edits to be saved automatically.)
Recompiling and executing after a change
Next compile again, using the Compilation button. Some "degree" messages appear quickly; EiffelStudio has found out what class has changed and deduced what exactly to recompile -- only a subset of the whole system. So this again will proceed very quickly.
Execute the system again now, using one of the execution buttons, with or without breakpoints, on the right in the bottom Project toolbar. You will see that the message output by the execution has changed to include the added string.
Views in the Editing Tool
In studying the Class tool we discovered a number of views of a class text. For convenience, you can also display a number of these views in the Editing Tool, although only the basic Text view is editable. A row of buttons next to the Class and Feature fields lets you choose between them.
You can try some of these view now, although there is nothing exciting to show about class
PARENT. Make sure to come back to the
Text view -- through the leftmost of these buttons -- so that we can continue exploring the editing facilities.
Basic editing facilities
The editing facilities in the Editing Tool are provided by the EiffelStudio Editor, a specialized tool supporting the development and update of Eiffel texts. As we'll see next, if you have a preferred editor you can use it instead, but the EiffelStudio Editor is worth knowing.
The EiffelStudio Reference section on the Editor provides many more details about editing functions. Here are the essentials.
First, the key property of any interactive system: Undo. You can cancel the latest editing command, or any earlier one performed during the current session, by choosing
Undo from the
Edit menu, or typing
CTRL-Z. To cancel more than one command, apply
Undo repetitively; there is no limit to the number of undoable commands within a session. (When you exit EiffelStudio, however, the editing history is lost.) To redo an undone command, use
Redo from the
Edit menu or
To copy, cut and paste use the corresponding entries in the
Edit menu or the familiar keyboard shortcuts
When you edit text, it will be automatically indented according to standard Eiffel style rules. If you prefer to remain in charge of your own indenting, you can disable this facility through
Tools --> Preferences --> Editor
To indent a sequence of lines, select the lines, then use
Edit --> Advanced --> Indent selection
You can also use the Tab key, but only if the selection consists of one or more entire lines; otherwise typing Tab will simply replace the selected text with a Tab character. Shift-Tab will similarly decrease indentation by one step.
To comment out a sequence of lines, select them and use
Edit --> Advanced --> Comment
CTRL-Shift-K will uncomment. Also in the
Edit --> Advanced menu are "set to upper case", with the keyboard shortcut
CTRL-U, and to lower case,
Other useful facilities of the
Edit --> Advanced menu are:
Embed in "if", or
CTRL-I, which will create a conditional instruction and include the selected instructions in it.
Embed in "debug",
CTRL-D, which will include the selected instructions in a
endinstruction, so that their execution becomes conditional on a Debug compilation option.
Search and replace
The editor lets you search for text and replace occurrences, individually or globally. We assume you have seen a text search facility before, so we'll just emphasize some of the less obvious features.
To start a search, make sure the Search Tool is active by clicking the Search button in the top toolbar (this one we'll let you find) or using the
Edit --> Findmenu entry.
The Search Tool presents a number of self-explanatory options:
You can enter a term to replace your search term in the
Replace with box.
Having filled the two fields, you can elect to replace the last found occurrence, or all occurrences at once.
Search for field has an associated drop-down list, so that you can reuse a recently entered search string without retyping it.
Let the editor do the typing
Particularly interesting are the editor's automatic completion facilities (often, we shorten the name to auto-completion). Well, particularly interesting for most people: maybe you like your editor to do the grunt work for you, or maybe you don't. In the latter case -- if you prefer to be in control of all the details -- don't worry: through
Tools --> Preferences --> Editor you can easily disable any facility that you don't like. The behavior described here is the default.
The EiffelStudio Editor knows about Eiffel syntax and will recognize syntactic elements as you type them. It will color them according to standard conventions: basic elements in black, keywords in blue, comments in dark red. You can change these conventions through Preferences.
If you start typing a control structure through its opening keyword, such as
from for a loop, the editor will automatically display the structure of the whole construct. Here for example is the result if you type the
from followed by Return/Enter at the beginning of our example routine:
This has produced the structure of an Eiffel loop:
end. You can then fill in the blanks with the appropriate expression and instructions. The generated lines start with the appropriate number of Tab characters to support the standard Eiffel indenting conventions. If you want a more compact style, follow the
from with a space rather than Return. Typing
if followed by Return or a space will similarly produce the outline of a conditional instruction.
Also interesting is feature completion. Feature completion is activated by default, and it works at two levels:
- You can type the beginning of the name of a feature of the current class, then
CTRL-SPACEto get possible completions.
- Once you have typed the name of a query (attribute or function), either all by yourself or aided by the previous completion technique, you can type a period to get the list of possible features to be applied, deduced from the list of features in the corresponding class (the type of the query).
In both cases, if more than one completion is possible, you will get a menu of the possibilities. You can scroll through it with the up and down arrow keys, or the mouse, and select one through Enter or double-click. You can also or give up through the Escape key.
Here for example is the menu you will see in the body of our example routine if you type
io. , where
io is the feature, coming from class
ANY, that provides access to standard input and output facilities:
If only one completion is possible, no menu appears; the completion is selected.
When a menu of possible completions is displayed, you can use the arrow keys to traverse the list.
If you select a routine with arguments, auto-complete will show the arguments and their types, allowing you to provide your value for each argument. The figure below shows auto-completion of a routine with only one argument.
You can see that the argument is pre-selected and is of type
STRING_8. As soon as you begin to type your substitution for the argument, the pre-selected argument definition is replaced with what you type. When you complete an argument, the
Tab key will either pre-select the next argument (in the case of routines with multiple arguments), or place the cursor to the right of the right parenthesis that terminates the routine call (in the case of the last argument).
Auto-completion will only work for queries that were present at the time of the last successful compilation. So if you add an attribute, say
attr, to the current class, and do not recompile, typing
CTRL-SPACE will not display
attr. To make sure that it's included in completion proposals, save and recompile. (Remember, incremental compilation is fast in EiffelStudio, so there is nothing wrong in compiling early and often.) The same rule holds for features of other classes, those that will appear in proposed completions after a period.
The features proposed for auto-completion include all features of the class: those declared in the class itself, or immediate features, and those inherited from proper ancestors, direct or indirect, with one exception: by default the list will not include features from the universal class
ANY, which serves as ancestor to all classes and provides many features for comparison, copying, input-output, reflection etc. Including
ANY's features would clutter all menus with too many features. So for example typing
i followed by
CTRL-SPACE will not suggest
io among the possible completions. You can change this policy through Preferences. The policy does not apply to remote feature completion for an entity
x declared of type
ANY. In the case that you type
x., auto-completion will produce the list of
Using your own editor
You may have a favorite editor and prefer to use it, at least in some cases. The EiffelStudio incremental compilation mechanism, to be studied shortly, recognizes that files have been modified outside of EiffelStudio (by checking their time stamps) and will without any fuss take their modified versions into account.
You can also call an outside editor on a class from within EiffelStudio. Just use
File --> External editor or the corresponding button in the top toolbar.
This will call the editor of your choice. The default is Notepad on Windows and Vi on Unix and Linux. You can easily change this to any editor by entering the desired editor command in
Tools --> Preferences --> General --> External editor command
In this command text you can use the two special notations
$line ; when EiffelStudio calls the selected command, it will replace any occurrence of
$target by the name of the file where the current class resides, and
$line by the line number at which the Editing Tool is currently scrolled. If you include one or both of these markers at the appropriate argument positions for the command, this will enable you -- assuming the editor supports the appropriate options -- to make sure it starts at exactly the right place. For example the default editor command under Unix is
vi +$line $target
meaning: start the Vi editor on the
$target file, initially positioned at line
line_number command-line option of Vi directs it to start at line
If you start an external editor on a class, then exit the editor after possibly making changes, EiffelStudio will immediately update the class text in the Editing Tool. More generally, note that EiffelStudio will detect changes made separately on the same class, and warn you of possible conflicts.
Several important text editors from various providers have Eiffel modes, which support the syntax-directed editing of Eiffel texts. They include:
- Vim, for Vi iMproved, an extension of Vi available on both Unix/Linux and Windows -- see www.vim.org
- Emacs -- see www.emacs.org.
- Editeur, a Windows syntax highlighting editor -- see www.studioware.com.