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
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 "email@example.com")
Various Emacs packages that need your own email address use the value of
Make Text mode the default mode for new buffers.
(setq default-major-mode 'text-mode)
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.
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).
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' from your home directory.
Here an absolute file name is used, so no searching is done.
Rebind the key C-x l to run the function
(global-set-key "\C-xl" 'make-symbolic-link)
(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.
Do the same thing for C mode only.
(define-key c-mode-map "\C-xl" 'make-symbolic-link)
Redefine all keys which now run
next-line in Fundamental mode so that they run
(substitute-key-definition 'next-line 'forward-line global-map)
Make C-x C-v undefined.
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.
Make `$' have the syntax of punctuation in Text mode. Note the use of a character constant for `$'.
(modify-syntax-entry ?\$ "." text-mode-syntax-table)
Enable the use of the command
eval-expression without confirmation.
(put 'eval-expression 'disabled nil)
439.   What is a moldograph? What is moldography?
400.   How can I change which port sshd listens on in Mac OS X 10.3 Panther? (hint: not in sshd_config)   [leif/2004-01-24]
343.   How can I patch my in kernel PCMCIA orinoco drivers so that I may change my MAC address/enter MonMode? (and use kismet, airsnort and the like...)   [jake/2002-12-19]
330.   what is a terrible feeling to have when you are hung over?   [jake/2002-10-11]
313.   What is the best way to end your console session with a Ultra Enterprise 2 when connected with cu?   [jake/2002-05-06]
302.   How can I raise my website's placement on google?   [macki/2002-01-20]
292.   what do you do when your favorite web site becomes no more?   [kurt/2001-11-29]
276.   What is the recipe for Soylent Green yak drink?   [blink/2001-10-02] ( macki/2001-11-05 )
267.   Where can I find lava-lamp generated pseudo random numbers?   [rupe/2001-08-16]
266.   Why won't sites with 24.x.x.x IPs respond to HTTP requests?   [rupe/2001-08-13]
174.   why doesnt an image change in a java applet when it changes on the server?   [jesse/2001-02-10]
163.   What is the easiest way to pause execution of a program in java, without threads?   [jesse/2001-01-13]
108.   How can i get custom ring tones onto my cell phone?   [jesse/2000-07-09]
107.   Where can I find out how to install and use the distributed rendering package PVMPOV?   [rupe/2000-07-04]
50.   If the mass number of an isotope is much greater than twice the atomic number, what type of radioactive decay might you expect?   [kurt/2000-02-06]
41.   Which OS Sucks? Which OS Rules?   [strick/2000-02-02]
33.   What is 'netpbm' ?   [strick/2000-01-26]
31.   Was Ross at Kevin Mitnick's release?   [strick/2000-01-23]
13.   What internet security sites should I read?   [strick/2000-01-17]