Chapter 5. Editing Source Code

Table of Contents

Edit Modes

An edit mode specifies syntax highlighting rules, auto indent behavior, and various other customizations for editing a certain file type. This section only covers using and selecting edit modes; information about writing your own can be found in Part II.

Mode Selection

When a file is opened, jEdit first checks the file name against a list of known patterns. For example, files whose names end with ".c" are edited in C mode, and files named Makefile are edited in Makefile mode. If a suitable match based on file name cannot be found, jEdit checks the first line of the file. For example, files whose first line is "#!/bin/sh" are edited in shell script mode.

File name and first line globs can be changed in the Mode-Specific pane of the Utilities>Global Options dialog box (see the section called "The Global Options Dialog Box").

If automatic mode selection is not appropriate, the edit mode can be specified manually. The current buffer's edit mode can be set on a one-time basis in the Utilities>Buffer Options dialog box; see the section called "The Buffer Options Dialog Box". To set a buffer's edit mode for future editing sessions, place the following in one of the first or last 10 lines of the buffer, where edit mode is the name of the desired edit mode:

:mode=edit mode:

A list of edit modes can be found in the Utilities>Buffer Options dialog box.

Syntax Highlighting

Syntax highlighting is the display of programming language tokens using different fonts and colors. This makes code easier to follow and errors such as misplaced quotes easier to spot. All edit modes except for the plain text mode perform syntax highlighting.

The colors and styles used to highlight syntax tokens can be changed in the Styles pane of the Utilities>Global Options dialog box; see the section called "The Global Options Dialog Box".