Here are some examples of doing certain commonly desired things with Lisp expressions:
(setq c-tab-always-indent nil)Here we have a variable whose value is normally
tfor `true' and the alternative is
(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
setqaffects only the current buffer's local value, which is not what you probably want to do in an init file.
(setq user-mail-address "firstname.lastname@example.org")Various Emacs packages that need your own email address use the value of
(setq default-major-mode 'text-mode)Note that
text-modeis used because it is the command for entering Text mode. The single-quote before it makes the symbol a constant; otherwise,
text-modewould be treated as a variable name.
(add-hook 'text-mode-hook '(lambda () (auto-fill-mode 1)))This shows how to add a hook function to a normal hook variable (see section 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-fillwhose 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 "foo")When the argument to
loadis a relative file name, not starting with `/' or `~',
loadsearches the directories in
load-path(see section Libraries of Lisp Code for Emacs).
(load "~/foo.elc")Here an absolute file name is used, so no searching is done.
(global-set-key "\C-xl" 'make-symbolic-link)or
(define-key global-map "\C-xl" 'make-symbolic-link)Note once again the single-quote used to refer to the symbol
make-symbolic-linkinstead of its value as a variable.
(define-key lisp-mode-map "\C-xl" 'make-symbolic-link)
next-linein Fundamental mode so that they run
(substitute-key-definition 'next-line 'forward-line global-map)
(global-unset-key "\C-x\C-v")One reason to undefine a key is so that you can make it a prefix. Simply defining C-x C-v anything will make C-x C-v a prefix, but C-x C-v must first be freed of its usual non-prefix definition.
(modify-syntax-entry ?\$ "." text-mode-syntax-table)
(put 'narrow-to-region 'disabled nil)
Go to the first, previous, next, last section, table of contents.