I use several minor modes, which are enabled globally by default:

  • whitespace-mode
  • linum-mode
  • fci-mode

I'm finding them very helpful when editing code sources and text files, however I does not want to activate them with some major modes, e.g. dired-mode, eshell.

I've tried to solve this as following:

(add-hook 'prog-mode-hook '(linum-mode 1))

(require 'whitespace)
(add-hook 'prog-mode-hook '(whitespace-mode 1))

(require 'fill-column-indicator)
(add-hook 'prog-mode-hook '(fci-mode 1))
(add-hook 'text-mode-hook '(fci-mode 1))

But this solution does not works well:

  • reverting buffer toggles off linum-mode
  • whitespace-mode not activating
  • fci-mode not activating, producing error message

    File mode specification error: (invalid-function (fci-mode 1)) [2 times]

What is the correct way to make smart toggle mentioned modes only with source code buffers and text buffers?

P.S. A note about fci-mode: error message looks odd to me, because I can either use M-x fci-mode to toggle it, or evaluate (fci-mode 1) or (fci-mode -1).

  • What version of Emacs are you using?
    – erikstokes
    Commented Apr 4, 2015 at 21:08
  • @erikstokes GNU Emacs 24.4.2 (x86_64-apple-darwin14.1.0, Carbon Version 157 AppKit 1344.72) of 2015-02-05 Commented Apr 4, 2015 at 21:34

2 Answers 2


In Emacs 23 (some-mode 1) was the typical way to turn on minor modes (but see this answer for the proper way to add them to the hooks). But Emacs 24 changed the rules for turning on minor modes. The argument to mode functions is no longer needed to turn the mode on anymore:

Toggle display of line numbers in the left margin (Linum mode). With a prefix argument ARG, enable Linum mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil.

So to simply turn on a minor mode, what you want is just #'linum-mode in your hooks.

  • @Malabarba, quite strange, because this works as expected without lambda and hash: (add-hook 'prog-mode-hook 'whitespace-mode). BTW, what that # means? Commented Apr 4, 2015 at 22:10
  • @Geradlus_RU 'whitespace-mode is fine. It is essentially the same as #'whitespace-mode. See this: endlessparentheses.com/…
    – Malabarba
    Commented Apr 4, 2015 at 22:13
  • @Geradlus_RU The code that is just plain wrong is: (add-hook 'prog-mode-hook '(whitespace-mode 1))
    – Malabarba
    Commented Apr 4, 2015 at 22:13
  • 1
    @Malabarba I have clarified the first sentence.
    – erikstokes
    Commented Apr 4, 2015 at 22:23
  • @Malabarba, thank you for good explanation article! Commented Apr 5, 2015 at 7:38

A hook expects its entries to be functions. (fci-mode 1) is not a function.

What you want to use as a function is presumably turn-on-fci-mode, if that function exists, or (lambda () (fci-mode 1)), if not.

See the Elisp manual, node Defining Minor Modes, particularly macro define-globalized-minor-mode.

You give no references for the global-mode functions you cite, so I don't know how they were defined. But if they were defined using define-globalized-minor-mode then there is likely a TURN-ON function that you can use on a hook.

  • I've accepted erikstokes's answer, however, your answer is very valuable too, because it solves issue with fci-mode. Voted up, thanks! Commented Apr 4, 2015 at 21:53
  • It's OK to accept a different answer. ;-) But be aware that you can change which one you like best (i.e., accept a different one) at any time. Tomorrow you might receive an answer that you find is better still.
    – Drew
    Commented Apr 4, 2015 at 22:01
  • I've defined global-mode function only for fill-column-indicator according to wiki: (define-globalized-minor-mode global-fci-mode fci-mode (lambda () (fci-mode 1))). But now I've just followed your suggestion: (add-hook 'text-mode-hook '(lambda () (fci-mode 1))) Commented Apr 4, 2015 at 22:02
  • 2
    (Note: You do not need to quote lambda forms, and in fact it is not a good idea to do so.)
    – Drew
    Commented Apr 4, 2015 at 22:07

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.