Emacs: defining a macro in a comment and automatically executing it

I am using Emacs / AucTeX to edit LaTeX files. In some of my LaTeX files, I defined some “file-specific” command (for example, \todo{...}in one file, \compute{...}in another, etc.), so I can keep track of what open problems I have in my documents.

The Emacs team highlight-regexpdoes a pretty good joob, highlighting all \todo{...}resp occurrences . \compute{...}s. But so far, I have to perform manual selection every time I open the corresponding file.

Is there a way to tell Emacs / AucTeX to invoke specific commands when opening a specific file? I would like to define these commands inside the corresponding file, so I can easily configure 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: 
+3
source share
3 answers

Try it,

%%% 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 details .

+5
source

You can use the hook in combination with local vars. For example, you can add a local variable dohighlightor something else, and then write a function like this:

(defun condhighl ()
 (when (boundp 'dohighlight)
 (highlight-regexp "regexp")))

and then add this function as a hook for AucTex

(add-hook 'tex-mode-hook 'condhighl)

dohighlight var , .

+2

After use highlight-regexp, to adjust the selection, hi-lock-write-interactive-patterns(Ms hw) will write the templates to the buffer as a magical comment.

You probably want to add a line mode: hi-lockafter a line mode: latexto activate the selection as soon as you open the file.

+2
source

Source: https://habr.com/ru/post/1753706/


All Articles