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 easi开发者_运维百科ly 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:
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.
You could use a hook in combination to local vars. For example, you could add a local variable dohighlight
or something and then write a function like this:
(defun condhighl ()
(when (boundp 'dohighlight)
(highlight-regexp "regexp")))
and then add that function as a hook for AucTex
(add-hook 'tex-mode-hook 'condhighl)
You can then add the dohighlight var in your local vars to buffers you want to highlight the code in.
After using highlight-regexp
to set up your highlighting, hi-lock-write-interactive-patterns
(M-s h w) will write the patterns into the buffer as a magic comment.
You probably want to add a mode: hi-lock
after the mode: latex
line too, to activate the highlighting as soon as you open the file.
精彩评论