This page is a short tutorial on how to turn a emacs mode on, off, or toggle.
When setting a variable that takes {true, false}, use {t, nil}, like this:
(setq make-backup-files nil)
When calling a mode function, use {1, 0}, like this:
(global-linum-mode 1)
If you want to turn on/off a mode, call the function, not set the variable. For example:
(global-linum-mode 1) ; GOOD (setq global-linum-mode t) ; BAD (setq global-linum-mode 1) ; TOTALLY WRONG!
Also, some minor mode have a command for setting it globally, while others do not.
For example, there's linum-mode and global-linum-mode. But there's auto-fill-mode but no “global-auto-fill-mode”. The best thing is to call describe-function and or describe-variable to see their inline docs.
You know, in emacs, “t” is true, and “nil” is false. So, for example, if you want to turn off a minor mode always, you might put this in your emacs init file:
;; turn off some modes? (global-hl-line-mode nil) ; WRONG! (global-linum-mode nil) ; WRONG!
WRONG!
Why is it wrong?
Yes, “t” is true and “nil” is false, but for modes, the proper way is to use “1” to turn it on, and “0” to turn it off. When called with no argument, it act as a toggle. For example, typing 【Alt+x global-linum-mode】 will toggle it.
;; turn on (global-linum-mode 1) ; correct ;; turn off (global-linum-mode 0) ; correct
Sometimes when you put (some-mode nil) in your init file, it will still work, because it happens to toggle to the state you want. But years later when you have added packages or code, you'll scratch your head and wonder what's going on.
Now look in your emacs init file and fix them all!
For minor modes, a argument of t will always turn it on, even though this seems to contradict what the inline doc says. For example, here's a quote from auto-fill-mode:
(auto-fill-mode &optional ARG) Toggle Auto Fill mode. With ARG, turn Auto Fill mode on if and only if ARG is positive.
As of today (emacs 23.2.x), for most or all minor modes, no arg or a nil arg will toggle the mode.
According to Stefan Monnier (one of the current emacs maintainer) in a post in comp.emacs on 2010-06-16 (Source groups.google.com)
, this behavior may change in future emacs because it is too confusing. “t” will always turn it on, “nil” turns it off always. For toggling, i'm guessing there'll be extra function with “toggle” in the name, ⁖
toggle-read-only, toggle-case-fold-search, toggle-debug-on-error, toggle-text-mode-auto-fill, toggle-truncate-lines, …
(thanks to YOO for correcting me about the actual behavior of (auto-fill-mode t).)