3

Is it possible to customize some, not all, of keywords in a major mode? (Pardon my vocabulary, since this is still new to me.)

For example, let's say these are keywords: function, new, throw, return. And I want to override the look of throw and new, but leave function and return alone.

dgo.a
  • 205
  • 1
  • 7
  • 3
    probably. see http://emacs.stackexchange.com/questions/2957/how-to-customize-syntax-highlight-for-just-a-given-mode and http://www.emacswiki.org/emacs/AddKeywords. Also, this question isn't spacemacs-specific – bmag Jan 29 '16 at 14:03
  • 1
    I don't think the question is a duplicate if it's about **some** keywords. – JeanPierre Jan 30 '16 at 09:44

1 Answers1

2

It is possible to customize some keywords of a mode. For example, here is a way to highlight throw and new in bold yellow, in Java mode:

;; define the look for your modified keywords
(defface my-keyword-face
  '((default :foreground "yellow" :weight bold))
  "Face for my own keywords.")

;; define the keywords you want to modify
(defvar my-modified-java-keywords
  '(("\\<\\(throw\\)\\>" . 'my-keyword-face)
    ("\\<\\(new\\)\\>" . 'my-keyword-face)))

;; modify the keywords
(font-lock-add-keywords 'java-mode my-modified-java-keywords)

More detailed information is found in emacswiki, the manual and the documentation for the relevant functions in Emacs.

bmag
  • 1,703
  • 10
  • 12