Init File Examples
Here are some examples of doing certain commonly desired things with Lisp expressions:
- Make <TAB> in C mode just insert a tab if point is in the middle of a
line.
(setq c-tab-always-indent nil)
Here we have a variable whose value is normally t for 'true' and the alternative is nil for 'false'.
- Make searches case sensitive by default (in all buffers that do not
override this).
(setq-default case-fold-search nil)
This sets the default value, which is effective in all buffers that do not have local values for the variable. Setting case-fold-search with setq affects only the current buffer's local value, which is not what you probably want to do in an init file.
- Specify your own email address, if Emacs can't figure it out correctly.
(setq user-mail-address "coon@yoyodyne.com")
Various Emacs packages that need your own email address use the value of user-mail-address.
- Make Text mode the default mode for new buffers.
(setq default-major-mode 'text-mode)
Note that text-mode is used because it is the command for entering Text mode. The single-quote before it makes the symbol a constant; otherwise, text-mode would be treated as a variable name.
- Set up defaults for the Latin-1 character set
which supports most of the languages of Western Europe.
(set-language-environment "Latin-1")
- Turn on Auto Fill mode automatically in Text mode and related modes.
(add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))
This shows how to add a hook function to a normal hook variable (see Hooks). The function we supply is a list starting with lambda, with a single-quote in front of it to make it a list constant rather than an expression.
It's beyond the scope of this manual to explain Lisp functions, but for this example it is enough to know that the effect is to execute (auto-fill-mode 1) when Text mode is entered. You can replace that with any other expression that you like, or with several expressions in a row.
Emacs comes with a function named turn-on-auto-fill whose definition is (lambda () (auto-fill-mode 1)). Thus, a simpler way to write the above example is as follows:
(add-hook 'text-mode-hook 'turn-on-auto-fill)
- Load the installed Lisp library named foo (actually a file
foo.elc or foo.el in a standard Emacs directory).
(load "foo")
When the argument to load is a relative file name, not starting with / or ~, load searches the directories in load-path (see Lisp Libraries).
- Load the compiled Lisp file foo.elc

