[[Property:title|Recompiling and Editing]]
[[Property:weight|-4]]
[[Property:uuid|6574a573-48b9-6088-aa98-53d7119d7c5c]]

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 <code>Project</code> menu, but the easiest for the moment is to use the compilation button ([[Image:compile-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. 


==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 Groups tool, expand cluster <code>root_cluster</code> and click class <code>PARENT</code> to retarget the Development Window to it. 

Make sure that the Editing Tool is big enough to display the text of the class:

[[Image:es gt development window targeted to parent 01|Class PARENT in Editing tool]] 

The Editing Tool hosts a text editor which you can use to change the class text. Here the routine <code>display</code> 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 <code>do</code>, before the first two instructions of the routine: 
<code>
			io.put_string ("THIS IS SOME ADDED TEXT") 
			io.new_line
</code>

You can just use copy-paste from the example above: select the two lines with the mouse, copy them using <code>CTRL-C</code> (or <code>Copy</code> from the <code>Edit</code> menu), then paste them just after the <code>do</code> using <code>CTRL-V</code> (or <code>Paste</code> from the <code>Edit</code> 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! 

[[Image:es gt development window targeted to parent 02|Class PARENT with changes]] 

Now save your changes; you may indifferently use <code>CTRL-S</code>, the <code>Save</code> entry from the <code>Edit</code> menu, or the Save button ([[Image: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. 

[[Image:view-buttons]]

You can try some of these view now, although there is nothing exciting to show about class <code>PARENT</code>. Make sure to come back to the <code>Text</code> 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 Editor|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 <code>Undo</code> from the <code>Edit</code> menu, or typing <code>CTRL-Z</code>. To cancel more than one command, apply <code>Undo</code> 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 <code>Redo</code> from the <code>Edit</code> menu or <code>CTRL-Y</code>. 

{{note|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 <code>PARENT</code> 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 <code>PARENT</code> back to its original state. }}

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

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 
<code lang=text>
Tools --> Preferences --> Editor</code> 

To indent a sequence of lines, select the lines, then use 
<codeang=text>
Edit --> Advanced --> Indent selection</code>
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 
<code lang=text>
Edit --> Advanced --> Comment</code> 
or <code>CTRL-K</code>. Conversely, <code>CTRL-Shift-K</code> will uncomment. Also in the <code lang=text>Edit --> Advanced</code> menu are "set to upper case", with the keyboard shortcut <code>CTRL-U</code>, and to lower case, <code>CTRL-Shift-U</code>. 

Other useful facilities of the <code lang=text>Edit --> Advanced</code> menu are: 
*  <code>Embed in "if"</code>, or <code>CTRL-I</code>, which will create a conditional instruction and include the selected instructions in it. 
*  <code>Embed in "debug"</code>, <code>CTRL-D</code>, which will include the selected instructions in a <code>debug</code> <span>...</span> <code>end</code> 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 
<code lang="text">
Edit --> Find
</code>
menu entry. 

{{note|If you press <code>CTRL-F</code> in a tool you will get a quick search bar that quickly allows you to search for something in the current text.}}

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



[[Image:search-tool]] 

You can enter a term to replace your search term in the <code>Replace with</code> box. 

Having filled the two fields, you can elect to replace the last found occurrence, or all occurrences at once.

The <code>Search for</code> 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 
<code lang=text>
Tools --> Preferences --> Editor</code> 
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 <code>if</code>, or <code>from</code> for a loop, the editor will automatically display the structure of the whole construct. Here for example is the result if you type the <code>from</code> followed by Return/Enter at the beginning of our example routine: 

[[Image:es gt auto complete from 01]]

This has produced the structure of an Eiffel loop: <code>from</code> <span>...</span> <code>until</code> <span>...</span> <code>loop</code> <span>...</span> <code>end</code>. 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 <code>from</code> with a space rather than Return. Typing <code>if</code> 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 <code>CTRL-SPACE</code> 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 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 <code>io.</code> , where <code>io</code> is the feature, coming from class <code>ANY</code>, that provides access to standard input and output facilities: 

[[Image:es gt auto complete feature 01|Feature auto-completion]]

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.

[[Image:es gt auto complete argument 01|Auto-completion of arguments]]

You can see that the argument is pre-selected and is of type <code>STRING_8</code>. 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 <code>Tab</code> 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 <code>attr</code>, to the current class, and do not recompile, typing <code>a</code> then <code>CTRL-SPACE</code> will not display <code>attr</code>. 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 <code>ANY</code>, which serves as ancestor to all classes and provides many features for comparison, copying, input-output, reflection etc. Including <code>ANY's</code> features would clutter all menus with too many features. So for example typing <code>i</code> followed by <code>CTRL-SPACE</code> will not suggest <code>io</code> among the possible completions. You can change this policy through Preferences. The policy does not apply to remote feature completion for an entity <code>x</code> declared of type <code>ANY</code>. In the case that you type <code>x.</code>, auto-completion will produce the list of <code>ANY</code>'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 
<code lang=text>
File --> External editor</code> 
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 
<code lang=text>
Tools --> Preferences --> General --> External editor command
</code>

In this command text you can use the two special notations <code>$target</code> and <code>$line</code> ; when EiffelStudio calls the selected command, it will replace any occurrence of <code>$target</code> by the name of the file where the current class resides, and <code>$line</code> 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 
<code>
vi +$line $target</code>

meaning: start the Vi editor on the <code>$target</code> file, initially positioned at line <code>$line</code> (the <code>+</code> <code>line_number</code> command-line option of Vi directs it to start at line <code>line_number</code> ). 

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. 



