face font in c-mode when adding new keyword

不羁岁月 提交于 2019-12-02 09:26:25

Here are some examples that you could modify -- e.g., change to c-mode instead of latex-mode, and modify it with your colors and regexp. As the definitions become more complex, the order in which they appear in the list may trump previous definitions -- so if what your doing should be working, then check the order in which they appear.

(defvar lawlist-super-HotPink1 (make-face 'lawlist-super-HotPink1))
(set-face-attribute 'lawlist-super-HotPink1 nil :background "white" :foreground "HotPink1" :bold t :underline nil :font "Courier" :height 200)

(defvar lawlist-super-SeaGreen (make-face 'lawlist-super-SeaGreen))
(set-face-attribute 'lawlist-super-SeaGreen nil :background "white" :foreground "SeaGreen" :bold t :underline nil :font "Courier" :height 200)

(defvar lawlist-keywords-01
    (concat "\\b\\(?:"
        (regexp-opt (list "INSERT" "CLIENT" "RECIPIENT" "document-name" ))
    "\\)\\b"))

(defvar lawlist-keywords-02
    (list (concat "\\b\\(?:"
        (regexp-opt (list "FIXME" "TO-DO" "BUGS" ))
    "\\)\\b") 0 'lawlist-red t))

(font-lock-add-keywords 'latex-mode (list

    (list (concat "\\(\{\\)\\(\\\\bf\\)\\(\\\\uline\\)\\(\{\\)\\(\\(.\\|\n\\)+?\\)\\(\}\\)\\(\}\\)")
        '(1 lawlist-regular t)
        '(2 lawlist-red t)
        '(3 lawlist-blue t)
        '(4 lawlist-regular t)
        '(5 lawlist-bold-underline t)
        '(7 lawlist-regular t)
        '(8 lawlist-regular t))

    (list (concat
        "\\("lawlist-keywords-01"\\)") 1 'lawlist-bumble-bee t)

    lawlist-keywords-02

    (list (concat "\\(\\blawlist\\b\\)") 1 'lawlist-pink t)

))


(font-lock-add-keywords 'latex-mode '(

("INCLUDE\\|REVISED" 0 lawlist-red t)

("\\(foo\\)-\\(bar\\)" (1 lawlist-super-orange t) (2 lawlist-super-cyan t))

("\\(hello\\) \\(World\\)" (1 lawlist-super-orange t) (2 lawlist-super-blue t))

) 'prepend)

EDIT

(font-lock-add-keywords 'c-mode '(

("^#[ \t]*\\(ifdef\\|else\\|ifndef\\|if !?defined\\|if\\|elif\\|endif\\|ident\\).*$" (1 lawlist-super-HotPink1 t) )

("\\(^#[ \t]*define\\|^#[ \t]*include\\|^#[ \t]*undef\\).*$" (1 lawlist-super-SeaGreen t))

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