regex - face font in c-mode when adding new keyword -
i trying customize added words colored differently default face-font colors.
this doing:
(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 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 ) )
unfortunately when opening c file see #include , #define being black colored. although should match regular expressions , turn dark blue. #ifdef , #endif in light dark color , not bold.
any appreciated.
here examples modify -- e.g., change c-mode instead of latex-mode, , modify colors , regexp. definitions become more complex, order in appear in list may trump previous definitions -- if doing should working, check order in 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)
Comments
Post a Comment