Virtually all Emacs customization is done via Lisp code. You can modify variables which influence the way Emacs operates or you can add new functions to Emacs (or override existing functions--replacing them with your own).
While experimenting with Emacs customization, you'll probably want
to do it in a way that is temporary. If you do something horribly
wrong, you can just
C-x C-c to exit emacs and run it
again. Once you've figured out what changes you'd like to make
permanent, you can add them to your very own
.emacs file so
that they take effect every time you start Emacs. This is discussed in
the next section.
The easiest customizations are accomplished by changing the value of a variable in Emacs. The list code to do this looks like this:
(setq variable-name new-value)
variable-name is the name of the variable and
new-value is the value you'd like to give the variable. (In
Lisp-speak, you're binding a variable to a value.) The
function in lisp is analogous to the assignment operators (usually
=) in other programming languages.
NOTE: I'm glossing over many details here for the sake of
simplicity. You may also see me or others use the Lisp functions
set and even
setq-default. If you're really curious,
feel free to look them up in an Emacs Lisp reference.
Let's look at a line from my
(setq-default transient-mark-mode t)
transient-mark-mode controls whether or not a
region becomes highlighted when I mark it. In many GUI applications,
if you click and drag the mouse to select a range of text it becomes
hi-lighted in reverse video or some other color. Emacs will do the same
thing it the
transient-mark-mode variable is set (to a non-nil
A WHAT value?
Okay. Brief digression. Most programming languages have some notion of true/false values. In C/C++ a value is considered true if it is a non-zero value. In Perl, a non-null or non-zero value is true. In Lisp, the same idea applies but the names and symbols are different.
True is usually written as
t and false (or null) is
nil. Like in other languages, though, any non-nill
value is considered true.
To get the full description of what
does, you can use the on-line help. Type
C-h v or
describe-variable and then
you're lazy like me, you can take advantage of variable name
completion using the
Tab key. Just type part of the variable
name and hit the
Tab key. If you've typed enough of it that
Emacs can already uniquely identify it, you'll see the whole name
completed for you.
Another variable that folks often set is
tells Emacs how wide the screen should be for the purposes of
auto-fill-mode respects this value). To
set the value to something absurd, you could type:
(setq fill-column 20)
But that won't actually do anything. You need to tell Emacs to
evaluate the expression you typed. To do so, put the point
(cursor) at the end of the expression end then type
which calls the function
eval-last-sexp in case you
care. When you do that, notice that
20 (or whatever value you
used) is echoed back to you in the mini-buffer at the bottom of the
screen. That's just the return value from the expression you
Just to prove that it works, type a sentence or two. If you happen
auto-fill-mode enabled (you probably don't), you'll
notice the text wrapping at the 20 column mark. Otherwise, after
you've typed some stuff, type
M-q which calls the function
fill-paragraph. It will then perform the word wrapping.
You can configure Emacs to automatically do something when you open
a file of a particular type (just like some GUIs will automatically
launch a specific application if you click on the icon for a
particular file). For example, I may want Emacs to automatically
text-mode every time I open a file with a
.txt extension. Well, that already happens.
let's tell Emacs to always enter
text-mode when you open a
file named ``README''.
(setq auto-mode-alist (cons '("README" . text-mode) auto-mode-alist))
Without diving into lots of Lisp programming that you really don't
need to know (but it wouldn't hurt you to learn), let just say that
auto-mode-alist contains a list of pairs. Each
pair contains a regular expression and an Emacs mode name. If a file
you open matches the regular expression (in this case, the string
README) Emacs starts the mode you specified.
The funny syntax above is because we're actually adding another
pair to that mode list. You wouldn't want to just assign to
auto-mode-alist without making sure the values that it
already contains aren't lost.
And if I wanted Emacs to automatically switch to
html-helper-mode every time that I opened a file that ended
.htm, I would add this to my .emacs
(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.htm$" . html-helper-mode) auto-mode-alist))
The possibilities are truly endless.
After you've spent some time with Emacs and have a basic idea of
what customization can do for you, you'll probably want to customize a
few things permanently (or at least until you change your mind). If
you find yourself using Emacs on a daily basis, you'll also notice
.emacs file get bigger as time goes on. That's a
Good Thing because it means you've figured out how to make
Emacs work the way you want it do work. It's a shame that
more software products don't let you do that.
In case you haven't already guessed, every time you start Emacs, it
looks for a file named
.emacs in your home directory. Your
.emacs file is where you should put any Lisp code that you
want run automatically and that includes the sort of customization
we've been dealing with here.
Another example from my
(setq inhibit-startup-message t)
inhibit-startup-message variable controls whether or
not Emacs displays that welcome message when it starts. After a while,
I got sick of looking at it (because I knew how to find the help and
whatnot), so I went in search of a way to turn it off.
As an exercise, try creating a
.emacs file of your own and
add that line to it. Then exit and start Emacs again. You should not
see the welcome message.
Often times when your read about an Emacs mode (or a package), the
documentation will suggest some code to add to your
file in order to make the mode or package work in a particular way.
The GNU Emacs FAQ (
C-h F) contains some items related to
.emacs files that you might find useful.
As Emacs has grown in popularity and continued to evolved, someone
eventually said ``there has to be a better way to let novice users
customize their Emacs.'' And
customize was born.
Customize provides a more intuitive method of customizing parts of
Emacs. To try it out, either visit the
Customize sub-menu in
Help menu, or type
Customize groups customization into logical groups like ``Editing'', ``Programming'', ``Files'', and so on. Some groups contain sub-groups.
If you make changes using the customize interface, Emacs will save
the changes to your
.emacs file. That's rather handy, because
you can easily inspect (and change) the changes it made for you.
I don't use the Customize interface, so I can't say much more about it..
Like any well behaved X application, Emacs respects your X
resources. That means you can control the initial colors, geometry,
and other X specific things just as you could with an
nxterm, or whatever.
Here's the relevant bit of my
emacs*Background: DarkSlateGray emacs*Foreground: Wheat emacs*pointerColor: Orchid emacs*cursorColor: Orchid emacs*bitmapIcon: on emacs*font: fixed emacs.geometry: 80x25
X manual page for more details about X resources.
Chris Gray ( email@example.com) also notes:
In Debian, the
~/.Xdefaultsdoesn't seem to be used. However, Debian people can put what you have given in
/etc/X11/Xresources/emacsand they can have the pretty colors that they had when they were using RedHat.
Hosting by: Hurra Communications Ltd.
Generated: 2007-01-26 17:57:51