![]() |
James Thornton |
| Internet Business Consultant |
| Home | Blog | Bio | Projects | Contact | Latest Blog (new site): How to Get to Genius |
|---|
AD.2.5 Local Variables in FilesA file can specify local variable values for use when you edit the file with Emacs. Visiting the file checks for local variable specifications; it automatically makes these variables local to the buffer, and sets them to the values specified in the file. There are two ways to specify local variable values: in the first line, or with a local variables list. Here's how to specify them in the first line:
You can specify any number of variables/value pairs in this way, each
pair with a colon and semicolon as shown above.
You can also specify the coding system for a file in this way: just
specify a value for the "variable" named
The In shell scripts, the first line is used to identify the script interpreter, so you cannot put any local variables there. To accommodate for this, when Emacs visits a shell script, it looks for local variable specifications in the second line. A local variables list goes near the end of the file, in the last page. (It is often best to put it on a page by itself.) The local variables list starts with a line containing the string `Local Variables:', and ends with a line containing the string `End:'. In between come the variable names and values, one set per line, as `variable: value'. The values are not evaluated; they are used literally. If a file has both a local variables list and a `-*-' line, Emacs processes everything in the `-*-' line first, and everything in the local variables list afterward. Here is an example of a local variables list:
As you see, each line starts with the prefix `;;; ' and each line ends with the suffix ` ***'. Emacs recognizes these as the prefix and suffix based on the first line of the list, by finding them surrounding the magic string `Local Variables:'; then it automatically discards them from the other lines of the list.
The usual reason for using a prefix and/or suffix is to embed the
local variables list in a comment, so it won't confuse other programs
that the file is intended as input for. The example above is for a
language where comment lines start with `;;; ' and end with
`***'; the local values for
Two "variable names" have special meanings in a local variables
list: a value for the variable
You can use the For example, you may be tempted to try to turn on Auto Fill mode with a local variable list. That is a mistake. The choice of Auto Fill mode or not is a matter of individual taste, not a matter of the contents of particular files. If you want to use Auto Fill, set up major mode hooks with your `.emacs' file to turn it on (when appropriate) for you alone (see section AD.7 The Init File, `~/.emacs'). Don't use a local variable list to impose your taste on everyone. The start of the local variables list must be no more than 3000 characters from the end of the file, and must be in the last page if the file is divided into pages. Otherwise, Emacs will not notice it is there. The purpose of this rule is so that a stray `Local Variables:' not in the last page does not confuse Emacs, and so that visiting a long file that is all one page and has no local variables list need not take the time to search the whole file.
Use the command
The variable
The
This document was generated on April 2, 2002 using texi2html |
|
James Thornton, jamesthornton.com>Services: Internet Marketing And Web Site Promotion |
Electric Speed: Online Marketing Solution |