Reevaluating Local Variables

An odd but very useful feature of Emacs is (file) local variables. This allows you to specify certain Emacs variables either on the first line of a file or at the end in a special Local Variables block. Typical uses include specifying line lengths, indention amounts, and other formatting features and specifying how to compile the file so that the compile command will work correctly.

I described it as odd because I first encountered the Local Variables block before I became an Emacs user and I thought it was very odd to see that sort of thing in a C source file. Regardless, local variables can be very useful.

One problem with them is what happens if you change a value or when you first add them to a file. How do you get Emacs to recognize the new value? I always solved this problem by reloading the file with Ctrl+x Ctrl+v (find-alternate-file) but there are other, better ways.

Grant Rettke over at Wisdom and Wonder points to two methods for reevaluating local variables. One method re-runs the hooks associated with the file and the other method doesn't. Hop on over and take a look; it will take you less than a minute.

This entry was posted in General and tagged . Bookmark the permalink.
  • If you tangle Org-Mode Literate Documents into source code sometimes you want to re-format the tangled file. File local variables are perfect for a per-file tangle-hook!