M-x all-things-emacs

Quick Tip: Detaching the custom-file

December 6th, 2008 by Ryan McGeary · 186 Comments

I’ve never really liked the built-in customization UI in Emacs (M-x customize). I’m sure plenty of people use it and enjoy it, but, to me, it feels like an abominable tree of never ending and difficult to navigate options. Plus, it sticks your saved customizations as an unorganized mess of elisp smack at the bottom of your init file. I’m not quite sure how to solve my first gripe, but the second is manageable.

By setting the custom-file variable, you can keep those automated customizations in a separate file. Put this in your Emacs init:

(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)

Both lines are necessary. The first line tells Custom to save all customizations in the file, but does not load it. The 'noerror argument passed to load prevents errors if the file doesn’t exist. If you had existing customizations in your init file, be sure to copy them to the new custom file.

Now, go enjoy a cleaner init file. This tip is especially useful if you keep your init files under a version control system. You do keep your init files under version control, right?

Tags: elisp · quick · tips

186 responses so far ↓

  • 1 me // Dec 7, 2008 at 2:01 pm

    Amen, brudda! And yes, I’ve been keeping my dotfiles in revision control for years … inspired by http://joey.kitenet.net/svnhome/

  • 2 Bob Erb // Dec 8, 2008 at 7:12 pm

    Thank you. I hate that custom cruft, too.

  • 3 Karl Anderson // Dec 9, 2008 at 7:39 pm

    I just have a one-liner .emacs: “(load-library “~/emacs/my-emacs”)”, and let emacs do what it wants with .emacs. A simpler solution IMHO, because it does less – my-emacs.el loads a lot of my-foo.el libraries for various foo, anyway.

  • 4 Gimmmo // Mar 29, 2009 at 12:14 am

    Thanks, you save my day :)

  • 5 coder // Apr 11, 2009 at 11:50 am

    Hello, I am writing a new Java source browser for Emacs, using Pymacs and Python. It’s called PyJDE.


    Take a look.