I have

(add-hook 'json-mode 'flymake-json-load)

in my .emacs file, but it has no effect. I have to do M-x flymake-json-load whenever I visit a .json file. Why doesn't it work?

1 Answer 1


add-hook does not take a mode symbol as its first parameter; it takes a symbol for a hook variable.

Replace 'json-mode with 'json-mode-hook and you'll be all set.

Note the differences between the symbols. One is a variable used to store a list of functions to run when entering json-mode:

json-mode-hook is a variable defined in ‘json-mode.el’.

Documentation: Hook run after entering JSON mode.

and the other is a function used to enter json-mode.

json-mode is an interactive autoloaded compiled Lisp function in ‘json-mode.el’.

Parent mode: ‘javascript-mode’.

Major mode for editing JSON files

  • 1
    As a general guideline, the name of the hook for a mode is usually <hook mode name>-hook... For example, the hook for org-mode is called org-mode-hook, and the hook for c-mode is c-mode-hook. (And so on.)
    – Archenoth
    Aug 11, 2015 at 14:47
  • Indeed most modes are defined using macros which enforce this naming scheme (and those which do not use the macros invariably adhere strictly to the same rules).
    – phils
    Aug 12, 2015 at 11:17

Your Answer

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

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