| Online Eiffel Documentation

EiffelStudio

# 11 RECOMPILING AND EDITING

Help reading this manual

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.

## Recompiling

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, the lower toolbar in the Development Window. Click this button. You haven't changed anything in the project since it was compiled (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.

## Editing

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 Cluster tree on the left, 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 more added text")
    	io.new_line

They are very similar to the current first two lines of the routine, so you can just use copy-paste: select the first two lines with the mouse, copy them using CTRL- C (or Copy from the Edit menu), then paste them just after the do using CTRL- V (or Paste from the Edit menu). Add or remove tabs to align with the rest of the routine, and change the string to THIS IS SOME MORE ADDED TEXT so that the result will look like what's shown on the next figure. This is all there is to change; the second line remains untouched. 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 CTRL- S , the Save entry from the Edit menu, or the Save button highlighted 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 Context 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 online documentation 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 CTRL- Y .

Since right now we don't need to do any actual editing to continue this Guided Tour, we suggest that you don't change the text of class PARENT but simply look up the menu entries described next, without actually selecting them. If you do make a change, voluntary or not, you should at the end of this editor discussion perform enough Undo commands to get the text of class PARENT back to its original state.

To copy, cut and paste use the corresponding entries in the Edit menu or the familiar keyboard shortcuts CTRL- C , CTRL- X and CTRL- V .

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 or CTRL- K . Conversely, 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, CTRL-Shift- U .

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 debug ... end instruction, 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 --> Find menu entry.

Note that although we are studying Search as part of the Editor, this function also applies to any textual form displayed in the Context Tool; make sure to start a Search from the tool that you want to search.

If you press CTRL - F in a tool you will get a quick search bar that quickly allows to search for something in the current text.

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.

The 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. 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 if , or 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: from ... until ... 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.

To start a routine, type the routine name followed by the keyword is and a Return. The editor generates the basic structure of a routine text:

This prompts you to enter the header comment (no self-respecting Eiffel developer even thinks of writing a feature without a header comment). At the end of the header comment, type Return if the header comment continues, otherwise type a down arrow to continue with the indentation for the beginning of the routine, with one of the keywords require , local , do , external , once . Once you type do , followed by a Return or space, the completion mechanism will insert the appropriate end , but other than that it doesn't try to produce an entire routine structure because there are too many syntactical choices (precondition or not, postcondition or not, locals or not etc.).

Also interesting is feature completion, using the CTRL-SPACE key. It works at two levels:

- You can type the beginning of the name of a feature of the current class, then CTRL-SPACE to 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 followed by CTRL-SPACE 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 . followed by CTRL-SPACE, where io is the feature, coming from class ANY , that provides access to standard input and output facilities:

The following properties enhance the convenience of the completion mechanisms:

- If only one completion is possible, no menu appears; the completion is selected.
- If the cursor is just after the name of a query (which you have fully typed, or obtained through completion), typing CTRL-SPACE once more will produce a period, as if you had typed it.
- When a menu of possible completions is displayed, typing CTRL-SPACE will select the first of them.

The combination of these facilities means that you can often obtain what you want simply by typing CTRL-SPACE repeatedly.

Also note the following properties of automatic feature completion:

- The mechanism 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 a -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.
- Automatic completion is applicable to features, not local entities or formal arguments.
- The features proposed for automatic 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 : typing CTRL-SPACE after x . will produce the list of ANY 's features.

## 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 --> Global Preferences . In this command text you can use the two special notations $target and $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 (the + line_number command-line option of Vi directs it to start at line line_number ).

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.

<< Previous Next >>