Next: Terminal Init, Previous: Init Syntax, Up: Init File [Contents][Index]
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 t
for ‘true’
and the alternative is nil
for ‘false’.
(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 probably not what you want to do in an init file.
(setq default-major-mode 'text-mode)
Note that text-mode
is used because it is the command for entering
the mode we want. A single-quote is written before it to make a symbol
constant; otherwise, text-mode
would be treated as a variable name.
(setq text-mode-hook '(lambda () (auto-fill-mode 1)))
Here we have a variable whose value should be a Lisp function. The
function we supply is a list starting with lambda
, and a single
quote is written in front of it to make it (for the purpose of this
setq
) a list constant rather than an expression. Lisp functions
are not explained here; for mode hooks it is enough to know that
(auto-fill-mode 1)
is an expression that will be executed when
Text mode is entered. You could replace it with any other expression
that you like, or with several expressions in a row.
(setq text-mode-hook 'turn-on-auto-fill)
This is another way to accomplish the same result.
turn-on-auto-fill
is a symbol whose function definition is
(lambda () (auto-fill-mode 1))
.
(load "foo")
When the argument to load
is a relative pathname, not starting
with ‘/’ or ‘~’, load
searches the directories in
load-path
(see Loading).
(load "~/foo.elc")
Here an absolute file name is used, so no searching is done.
make-symbolic-link
.
(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-link
instead of its value as a variable.
(define-key c-mode-map "\C-xl" 'make-symbolic-link)
(define-key c-mode-map 'f1 'make-symbolic-link)
(define-key c-mode-map '(shift f1) 'make-symbolic-link)
next-line
in Fundamental mode
to run forward-line
instead.
(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 would make C-x C-v a prefix, but C-x C-v must be freed of any non-prefix definition first.
(modify-syntax-entry ?\$ "." text-mode-syntax-table)
eval-expression
without confirmation.
(put 'eval-expression 'disabled nil)
Next: Terminal Init, Previous: Init Syntax, Up: Init File [Contents][Index]