emacs AUCTeX macros fontification

守給你的承諾、 提交于 2019-12-06 06:06:15

问题


I recently started using the excellent package xargs that provides \newcommandx. It shares a syntax similar to the default \newcommand. I would like font-lock to reflect this. I did

(custom-set-variables
 '(font-latex-user-keyword-classes
   (quote (("cx" ("newcommandx" "*|{\\[[{")
        (:family "font-lock-type-face") command)))))

But this fontifies just the command name itself, not its body (\newcommand fontifies the body with 'font-lock-function-name-face, which in my case is bold). I want \newcommandx to fontify its body with 'font-lock-function-name-face.

To summarize the question: how to make fontification for \newcommandx be exactly the same as for \newcommand (i.e. bold body in my case)?


回答1:


Here is an example that you can modify to suit your needs. See lines 280 to 436 of font-latex.el within auctex-11.86 for a complete list of predefined keywords. The following examples are used to add additional keywords, and/or define your own coloration for the contents of wavy / square brackets.

;; \EFFECT{[font-lock-function-name-face]}
(setq font-latex-match-function-keywords
    '(
        ("newcommandx" "*|{\\[[{")
    )
 )


;; \EFFECT{[font-lock-constant-face]}
(setq font-latex-match-reference-keywords
    '(
        ("fancypagestyle" "[{")
        ("fancyhead" "[{")
        ("fancyfoot" "[{")
    )
 )


;; \EFFECT{[font-lock-type-face]}
(setq font-latex-match-textual-keywords
    '(
        ("parentext" "{")
        ("hybridblockquote" "[{")
        ("parskip" "")
        ("footskip" "")
    )
)


;; \EFFECT{[font-lock-variable-name-face]}
(setq font-latex-match-variable-keywords
    '(
        ("newgeometry" "[{")
        ("quotingsetup" "[{")
        ("TabPositions" "[{")
        ("rfoot" "")
    )
)


;; \font-latex-warning-face
(setq font-latex-match-warning-keywords
    '(
        ("fixme" "{") 
    )
)


;; only affects inside wavy brackets
(setq font-latex-user-keyword-classes
          '(("my-warning-commands"
                (("fixme" "{"))
                (:foreground "purple" :background "yellow")
                command)))

See also: http://www.gnu.org/software/auctex/manual/auctex/Fontification-of-macros.html


I have chosen the following method to customize all of my special keywords:

(defvar lawlist-face-01 (make-face 'lawlist-face-01))
(set-face-background 'lawlist-face-01 "black")
(set-face-foreground 'lawlist-face-01 "white")
(set-face-bold-p 'lawlist-face-01 t)
(set-face-italic-p 'lawlist-face-01 t)
(set-face-underline-p 'lawlist-face-01 t)
(set-face-underline 'lawlist-face-01 "yellow")

(defvar lawlist-face-02 (make-face 'lawlist-face-02))
(set-face-attribute 'lawlist-face-02 nil :background "gray" :foreground "red" :font "Courier" :height 180 :bold t :underline "yellow" :italic t)

(font-lock-add-keywords 'latex-mode '(
("\\\\test01\\|insert\\|BUGS\\|FIXME\\|TODO\\|and\\|or\\|not" 0 lawlist-face-01 prepend) ;; 0 = highlight all
("\\\\test02\\|INSERT\\|document-name\\|\\\\begin{document}" 0 lawlist-face-02 prepend) ;; 0 = highlight all
("\\test01{\\([^}]*\\)}" 1 lawlist-face-02 prepend) ;; 1 = colorize contents of wavy brackets
))


来源:https://stackoverflow.com/questions/16338466/emacs-auctex-macros-fontification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!