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.

2

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.