首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >添加新关键字时以c模式显示字体

添加新关键字时以c模式显示字体
EN

Stack Overflow用户
提问于 2013-07-31 22:01:36
回答 1查看 392关注 0票数 0

我正在尝试自定义一些添加的单词,使其与默认的字体颜色不同。

这就是我要做的:

代码语言:javascript
复制
(defconst lconfig-font-lock-faces  
  (list

   '(font-lock-function-name-face
     ((((class color)) (:foreground "DarkBlue"  :bold t))))

   '(font-lock-constant-face
     ((((class color)) (:foreground "Black"     :bold t))))


   '(font-lock-builtin-face
     ((((class color)) (:foreground nil))))

   '(font-lock-preprocessor-face
     ((((class color)) (:foreground nil))))

   )
  )

(autoload 'custom-set-faces "font-lock" "Set the color scheme" t)
(autoload 'font-lock-fontify-buffer "font-lock" "Fontify Buffer" t)
(progn (apply 'custom-set-faces lconfig-font-lock-faces)
       (add-hook 'c-mode-common-hook 'font-lock-fontify-buffer)
       (add-hook 'emacs-lisp-mode-hook 'font-lock-fontify-buffer)
       )
(global-font-lock-mode t)

(font-lock-add-keywords
 'c-mode
 '(
   ("^#[ \t]*\\(ifdef\\|else\\|ifndef\\|if !?defined\\|if\\|elif\\|endif\\|ident\\).*$" 1 font-lock-constant-face)                  ;#defines
   ("\\(^#[ \t]*define\\|^#[ \t]*include\\|^#[ \t]*undef\\).*$" 1 font-lock-function-name-face)                                     ;other #s
 )
)

不幸的是,当打开c文件时,我看到#include和#define是黑色的。虽然它们应该匹配正则表达式,然后转到深蓝色。而且#ifdef和#endif都是浅色的,而不是粗体的。

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-31 23:18:36

下面是一些你可以修改的例子--例如,改为c模式,而不是乳胶模式,然后用你的颜色和regexp来修改它。随着定义变得更加复杂,它们在列表中出现的顺序可能超过先前的定义--因此,如果您的操作应该有效,那么检查它们的出现顺序。

代码语言:javascript
复制
(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)

编辑

代码语言:javascript
复制
(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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17981738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档