Search code examples
emacslispelispsyntax-highlightingfont-lock

How to highlight all the function's name in Emacs' lisp-mode?


How to highlight all the function's name in Emacs' lisp-mode? I want them bolded.

In other words, all the words from ( to the first space. Don't care exceptions like (a . b)

Just like GitHub:

enter image description here


Solution

  • Use this:

    (defface font-lock-func-face 
        '((nil (:foreground "#7F0055" :weight bold))
          (t (:bold t :italic t)))
      "Font Lock mode face used for function calls."
      :group 'font-lock-highlighting-faces)
    
    (font-lock-add-keywords 
     'emacs-lisp-mode
     '(("(\\s-*\\(\\_<\\(?:\\sw\\|\\s_\\)+\\)\\_>"
        1 'font-lock-func-face)))
    

    A funny thing: this messes up with let bindings, just like Github. But that's what you asked for, right:)?