12.9. Programming Assistance

vile's programming assistance capabilities are discussed in this section.

12.9.1. Edit-Compile Speedup

vile uses two straightforward vi mode commands to manage program development, shown in Table 12.6.

Table 12.6. vile Program Development vi Mode Commands

CommandFunction
^X !commandRETURN

Run command, saving the output in a buffer named [Output].

^X ^X

Find the next error. vile parses the output and moves to the location of each successive error.

vile understands the Entering directory XXX and Leaving directory XXX messages that GNU make generates, allowing it to find the correct file, even if it's in a different directory.

The error messages are parsed using regular expressions in the buffer [Error Expressions]. vile automatically creates this buffer, and then it uses the buffer when you use ^X ^X. You can add expressions to it as needed, and it has an extended syntax that allows you to specify where filenames, line numbers, columns and so on appear in the error messages. Full details are provided in the online help, but you probably won't need to make any changes, as it works pretty well "out of the box."

vile's error finder also compensates for changes in the file, keeping track of additions and deletions as you progress to each error.

The error finder applies to the most recent buffer created by reading from a shell command. For example, ^X!command produces a buffer named [Output], and :e !command produces a buffer named [!command]. The error finder will be set appropriately.

You can point the error finder at an arbitrary buffer (not just the output of shell commands) using the :error-buffer command. This lets you use the error finder on the output of previous compiler or egrep runs.

12.9.2. Syntax Highlighting

vile supports syntax highlighting in all configurations. It uses custom syntax filter programs to perform syntax coloring. These may be built into vile, or run as external programs. [1] [2] vile sends the contents of the buffer to be colored by the syntax filter, reads a marked-up version of it and applies the markup to color the buffer.

There are currently 71 programs, as well as a separate program for UNIX man pages. Some of the programs are used for more than one type of file. For instance, C, C++ and Java have similar syntax, but use different keywords.

vile provides macros which run the syntax filters on demand, or automatically as you modify the buffer. These are summarized in Table 12.7.

Table 12.7. vile Syntax Highlighting Commands

Key bindingCommandFunction
 :HighlightFilterRETURN

Invoke syntax-highlighting filter on the current buffer. vile chooses a filter based on an extended property of the buffer, called a major mode (discussed in Section 12.10.2).

If the filters are built-in, vile's initialization sets the autocolor mode to invoke this macro 5 seconds after you stop modifying a buffer.

^X-q:HighlightFilterMsgRETURN

Attach highlighting to the current buffer using HighlightFilter. Display a message on completion.a

^X-Q:HighlightClearRETURN

Clear all highlighting from the current buffer. This does not alter the buffer's major mode.

 :set-highlighting majormodeRETURN

Change the buffer's major mode to majormode and run the syntax highlighter.

 :show-filtermsgs

Show syntax-filter error messages for the current buffer. If the syntax filter finds any errors, it reports them, and vile displays them in the [Filter Messages] buffer, and sets the error-buffer to allow you to step through the places where an error is found.

Notes:
a. When syntax highlighting was first implemented in vile in the mid-1990s, it was important to show that it was completed. Times change—machines are faster.

Each time a syntax filter runs, it reads one or more external files containing the keywords to be highlighted, along with their corresponding color and video attributes (bold, underline, italic). It searches for these files (suffixed .keywords), using the name of the buffer's majormode. The search rules are documented in the online help. You can use the :which-keywords macro to show the locations where vile will look for the files, and where it finds them.

Example 12-1. Sample output of ":which-keywords cmode"


Show which keyword-files are tested for:
	cmode                           (1)
(* marks found-files)

$cwd                                    (2)
  ./.c.keywords
$HOME
  ~/.c.keywords
  ~/.vile/c.keywords
$startup-path                           (3)
* /usr/local/share/vile/c.keywords
(1)
The major mode, which always ends with "mode".
(2)
Your current working directory.
(3)
vile's search-path for scripts.

Whether the configuration is X11, terminal (termcap, terminfo, curses), or Windows, vile's syntax filters use a common set of colors, defined in classes: Action, Comment, Error, Ident, Ident2, Keyword, Keyword2, Literal, Number, Preproc, Type. Most of the keyword definitions refer to a class. Doing this allows you to modify all of the colors by changing just one file. Normally that is your $HOME/.vile.keywords file. The online help gives details on customizing the syntax colors.

On the one hand, because syntax highlighting is accomplished with an external program, it should be possible to write any number of highlighters for different languages. On the other hand, because the facilities are rather low-level, doing so is not for non-programmers. The online help describes how the highlight filters should work.

The directory ftp://invisible-island.net/vile/utilities contains user-contributed filters for coloring makefiles, input, Perl, HTML, and troff. It even contains a macro that will color the lines in RCS files according to their age!

Notes

[1]

Built-in filters are faster than external programs, and eliminate interference from your shell when displaying in a terminal.

[2]

For some platforms, the syntax filters can be dynamically loaded. This allows the editor executable to be smaller, though not as fast as with the built-in filters.