Eiffel Home Page (Web) -- Getting started with Eiffel (local) Eiffel Home PageEiffel Home Page

Previous, Up, NextPrevious sectionUpNext section

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:

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 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 (shown on the figure page 71 ). 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 (shown on the figure on page 13 ), 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 ( "CLASS VIEWS", 7, page 30 ). 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:

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), using the Edit --> Find menu entry, or type CTRL- F in a Text or Context Tool.

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.

The Search Tool presents a number of self-explanatory options:

If you select Use wildcards , two characters will be treated specially in the Search for field: a question mark ? will match any character, and an asterisk will match any sequence of characters.

If you check the Replace with box, a replacement field will appear:

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 menu, 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 gruntwork 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:

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:

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:

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

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:

Previous, Up, NextPrevious sectionUpNext section

Eiffel Home Page (Web) -- Getting started with Eiffel (local)