What's Emacs Custom System and Should You Use It?

Perm url with updates: http://xahlee.org/emacs/emacs_custom_system.html

What's Emacs Custom System and Should You Use It?

Xah Lee, 2010-04-06

This page is a tutorial on emacs's Custom system for setting user preferences.

What's Emacs's Custom GUI?

Emacs has a textual GUI system for setting user preferences . It lets you customize emacs without needing to know much emacs lisp. You can call it by “Alt+x customize”. Try it. You'll see that things are simple to understand. You can just use the mouse and click buttons to change emacs's many complex setting.

You can also call “customize-group” to customize a particular mode directly. For example, type “Alt+x customize-group”, then give “dired”. That page will let you change dired's settings. Another way is to customize a variable directly if you know a variable's name. For example, type “Alt+x customize-variable”, then “auto-save-default”.

emacs custom system

Emacs textual GUI based Custom system for setting user preferences.

When you are done, press the “Save for future sessions”. After you are finished, emacs will insert elisp code like this into your init file:

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(abbrev-mode t)
 '(auto-save-default nil)
 '(comment-column 2)
 '(current-language-environment "UTF-8")
 '(default-input-method "latin-1-prefix")
 '(ffap-newfile-prompt t)
 '(font-lock-maximum-decoration 2)
 '(indicate-empty-lines nil)
 '(initial-major-mode (quote text-mode))
 '(initial-scratch-message "")
 ;; ...
)

The emacs's Custom system is very convenient. It provides a easy way for people not familiar with lisp, and it works in terminal on remote machines too because it is a textual based GUI. For emacs beginner, this is a great way to explore. However, it has its flaws.

Some advanced emacs user have a habit of using this Custom system whenever possible. So, they avoid a bunch of manually created “(setq ‹variable name› ‹value›)” in their emacs init file. This can keep the variable settings neat.

However, other advanced emacs users totally avoid this Custom system, because the Custom system put all variable settings into one alphabetical list. These emacs users prefer to group similar customizations together so that they have better control.

How to Move Things Out of custom-set-variables

It is easy to move variables in or out of this “custom-set-variables” system. For example, if you have:

(custom-set-variables
 '(abbrev-mode t)
 '(auto-save-default nil)
 ;; ...
)

The equivalent would be:

(setq abbrev-mode t)
(setq auto-save-default nil)

Should You Use Custom?

If you move things manually out of the code generated by Custom, note that the Custom system may get confused. For example, if you call “customize-group”, then “abbrev”, the values displayed there for Abbrev Mode may not reflect the actual value, because you've set abbrev-mode variable outside the custom system. If you went ahead and use the Custom anyway and save for future session, emacs will generate the code, so in effect you have 2 places in your init file both trying to set the same variable. It'll still work, because the generated code is at the bottom of your init file (presuming you just have one simple init file), but can be a potential problem.

For me, i don't take the effort to move things out of the auto generated code.

The Custom system isn't ideal neither. Because sometimes when you read online, often you can just grab some code such as “(setq abbrev-mode t)” and put in your init file. Very convenient. You don't need to know if that variable is part of the Custom system. (The Custom system does NOT include all possible variable settings)

For emacs blog writers, it is also much easier to just say “put this code snippet in your .emacs”. It is more difficult to give direction on how to do the same thing thru Custom system. And for many customizations that's more than just setting of variables, it cannot be done thru the Custom system.

So, there's no ideal choice here about whether you should be using the custom system. My advices is just don't fret about it either way. Though, you should avoid setting a variable in more than one place. You'll see why later.

Also, even though the Custom is a GUI, but it is not quite intuitive. When i first tried the Custom, i already have 5 years of daily emacs experience, but i was still quite confused on what each customization item is supposed to do.

See also: Organize Your .emacs in 5 Minutes.

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs