chunsj
chunsj

Reputation: 309

How can I write emacs lisp code for adding new highlighting pattern?

I found that font-lock-add-keywords is the key but I cannot find how to add a pattern. For example, in clojure;

(defn a-function-name [argument vector]
  ...)

a-function-name is highlighted becuase it's after defn and before [argument vector]. How can I write a rule for this?

(font-lock-add-keywords 'lisp-mode XXXXX)

I cannot write XXXXX part for myself.

=======================

Thank you to all of you :-) Yes, I can find clue in docs and clojure-mode.el as of you said.

Here is what I do and it works well (at least for me)

(font-lock-add-keywords
 'lisp-mode
 '(("(\\(@defn\\)\\>[ \r\t\n]*\\(\\sw+\\)+\\>?"
    (2 'font-lock-function-name-face))))

Why I need this is that I define some macros and emacs does not highlight them properly.

Upvotes: 2

Views: 104

Answers (2)

Drew
Drew

Reputation: 30701

To add to what @juanleon said: See the Elisp manual, node Search-Based Fontification for information about font-lock-keywords. That will help you "write the XXXXX part for yourself."

Then, as @juanleon said, try something and ask for more help here if it doesn't work. Code tried gets help.

Upvotes: 1

juanleon
juanleon

Reputation: 9370

Type C-h f font-lock-add-keywords. In the help for that function, there will be a link for font-lock-keywords, where the format for what you call XXXXXX is described.

If with that help you are still having trouble, post your attempt to achieve what you want so you can receive more specific help regarding your problem.

Upvotes: 2

Related Questions