Jisang Yoo
Jisang Yoo

Reputation: 3745

highlight incorrect use of eval-after-load

An often made mistake when using eval-after-load is forgetting to quote the form:

(eval-after-load 'dired
  (progn
    ...
    ...))

(eval-after-load "foo" (let ...))

How can I highlight such mistakes? Maybe paint the word eval-after-load in red when the form is not quoted?

Upvotes: 4

Views: 179

Answers (1)

gbrener
gbrener

Reputation: 5835

The most straightforward way I know of is to add font-lock keywords:

(font-lock-add-keywords 'lisp-mode
  '(("(\\(eval-after-load\\)\s+[^\s]+\s+(" 1 'font-lock-warning-face t)
    ("(\\(setq\\)\s+'" 1 'font-lock-warning-face t)))

To apply these keywords across lisp-mode and all of its derived modes:

(add-hook 'lisp-mode
  (lambda ()
    (font-lock-add-keywords nil
      '(("(\\(eval-after-load\\)\s+[^\s]+\s+(" 1 'font-lock-warning-face t)
        ("(\\(setq\\)\s+'" 1 'font-lock-warning-face t)))))

This solution won't support errors across multiple lines (as in your first example) but it's a start.

More information can be found at: http://www.gnu.org/software/emacs/manual/html_node/elisp/Search_002dbased-Fontification.html#Search_002dbased-Fontification

Upvotes: 1

Related Questions