# Editing Source Files

## The Editor

&kapp; does not provide its own editor. Instead, it utilises KDE's KTextEditor infrastructure to embed the system's default editor. This means that any editor that supports the KTextEditor interface (e.g., &kate;, KVim) can be used with &kapp;. The editor is defined in KDE's control centre.

In any matter related to operating or configuring the editor, please refer to the manual of the editor itself.

## Opening Files for Editing

Files are usually opened for editing as part of a project. However, &kapp; enables the user to edit an occasional file that is not related to the project, through the File Open... menu command. Note, however, that query results on files outside a project are meaningless.

Once a project has been opened, the list of all project files appears in the file list, to the right of the editing area. Each file entry in the list shows the file's type, its name, and its full path. Files are opened by either double-clicking their entry in the list, or by selecting the entry, and hitting the Enter key. The edit-box above the list can be used to quickly search for a file. Typing in this box selects the first list entry whose file name begins with the entered text.

Files can also be opened through the file tree, which shares its location with the project's file list (using a tabbed-window.) The file tree displays all files in the system, starting with a specific root directory. A root directory for the file tree is set on a per-project basis by using the Set Root... button. The file tree also sports a Find File... button for launching the file search Cscope query.

To decrease the loading time of projects, files and directories are only added to the tree when their parent directory is expanded. Therefore directories will not be marked as expandable by default, even if they are not empty.

For each file opened, &kapp; creates a separate editor window, inside the editing area. Each editor is associated with a tab, displaying the name of the edited file. Thus &kapp; provides a convenient multi-editor environment. You can switch between open files by selecting their respective tabs, or by using the Window menu.

To work on a new file, the user first needs to create it using the File New... menu command. This opens an empty editor, that is not associated with a file name or path. Upon saving the work in this new editor, &kapp; will prompt the user for a file name and directory. Note that this does not add the file to the project. The user still needs to invoke the Project Files dialogue and add the new file to an open project.

## File Tags

In addition to being a front-end to Cscope, &kapp; also uses Ctags to display a list of symbols defined in the current file. Each editor window is added a list of these symbols to its left. This list displays the name of a symbol, its type (as a graphic shape), and the line where it is defined. Double-clicking a symbol, or selecting it and hitting the Enter key, sets the cursor to the beginning of this symbol's definition line. The list of symbols is refreshed whenever a file is saved.

The edit-box above the list of symbols can be used for quick symbol look-ups. Entering text in this box selects the first symbol whose name begins with this text.

By default, tags are sorted by to their name in ascending order. Click on a column header to sort the tags according to that column. A triangle to the side of a column name indicates this is the sorting column, and shows the sorting order (ascending or descending.) Once a sorting order is chosen, it becomes the default, and is used for all newly created lists (though not for currently open, unmodified, editor windows.)

## Other File Options

&kapp;'s File menu includes further options, such as saving, printing and closing files. In addition, specific editors can offer extended features under the Tools menu (e.g., syntax highlighting, indentation, etc.)

## Symbol Completion

Symbol completion is a convenient feature that enables the user to enter previously declared symbols with fewer key strokes. Since the cross-reference database keeps record of all globally declared symbols, it can be queried for a complete symbol name based on a given prefix. There are two types of symbol completion: manual and automatic. Manual symbol completion is always available, and can be invoked by the Edit Complete Symbol menu command (or, more conveniently, by pressing Ctrl Space). Once a completion request has been issued, &kapp; uses the characters immediately preceding the current cursor position as a prefix, and queries the database for possible completions. These completions are displayed in a list box, which can be browsed using the arrow keys. Pressing Enter replaces the prefix with the selected symbol. The Esc key hides the list without completing the symbol.

### Automatic Symbol Completion

In addition to manual symbol completion, &kapp; can also provide automatic completion based on changes made by the user to the edited source code. Specifically, &kapp; tracks changes to the edited file, and if certain criteria are met, initiates a symbol completion query to the cross-reference database. Once a completion list is displayed, symbol completion behaves in the same way as in the manual case.

Automatic symbol completion is configured on a per-project basis. This feature is enabled or disabled via the Use Symbol Auto-Completion check-box in the New Project dialogue (this option can also be changed after a project has been created by invoking the Project Properties dialogue).

For performance reasons, it is highly recommended that automatic symbol completion will be used in conjunction with the inverted-index option.

As mentioned above, &kapp; uses several parameters to decide whether automatic symbol completion should be initiated. These parameters can be configured by clicking on the Options... button in the New Project dialogue (or, later, in the Project Properties dialogue). Clicking this button invokes the Auto-Completion Properties dialogue. The auto-completion properties dialogue The auto-completion properties dialogue

Minimum Characters

- The minimal length of a symbol for which completion is provided.

Delay (ms)

- Specifies a time interval that should elapse after the last change to the edited text and before the symbol completion query is executed.

Maximum Entries

- The symbol completion list will display at most this number of possible completions. If the number of matched symbols in the database is greater, a message will be displayed (and no symbols will be available).

The main purpose of these parameters is to reduce the load on the system caused by frequent queries to the database. The default values have been tested in various scenarios, and are usually adequate.