I wonder if we can set the font in Emacs according to the comments in the file.


-*- fond: "my-font"; -*-

2 Answers 2


You can use the eval file local variable which can evaluate lisp expressions if you allow it.


For full details, see Specifying File Variables

There are two ways to specify file local variable values: in the first line, or with a local variables list. Here's how to specify them in the first line:

 -*- mode: modename; var: value; ... -*-

Here is an example first line that specifies Lisp mode and sets two variables with numeric values:

 ;; -*- mode: Lisp; fill-column: 75; comment-column: 50; -*-

Instead of using a -*- line, you can define file local variables using a local variables list near the end of the file. The start of the local variables list should be no more than 3000 characters from the end of the file, and must be on the last page if the file is divided into pages.

A 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, like this:

 /* Local Variables: */
 /* mode:c           */
 /* comment-column:0 */
 /* End:             */

Note that /* */ is only present to mark these lines as comments to the C source code... Emacs looks only for Local Variables: followed on another line by End:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.