Search code examples
emacselispauctex

Emacs: Define macro in comment and automatically execute it


I'm using Emacs/AucTeX for editing LaTeX files. In some of my LaTeX files, I have defined some "file-specific" command (e.g. \todo{...} in one file, \compute{...} in another, and so on), so I can keep track of what open problems I have in my documents.

The Emacs command highlight-regexp does quite a good joob in highlightning all occurences of \todo{...}s resp. \compute{...}s. But up to now I have to execute the highlightning manually every time I open the corresponding file.

Is there a way of telling Emacs/AucTeX to invoke specific commands when opening a particular file? I would like to define these commands inside the corresponding file, so I can easily adjust it for different files (maybe included in local variables).

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "master"
%%%
%%% here I would like to have something like:
%%% execute highlight-regexp for specific arguments
%%%
%%% End: 

Solution

  • Try this,

    %%% Local Variables: 
    %%% eval: (font-lock-add-keywords nil '(("\\\\todo" (0 font-lock-warning-face))))
    %%% End: 
    

    See Section 57.3.4.1, Specifying File Variables, for more details.