Organize Emacs Init File in 5 Minutes

By Xah Lee. Date: . Last updated: .

This page is a guide on organizing your emacs init file.

Many emacs users, have hundreds of lines in their emacs init file, accumulated over the years. Large emacs init file makes emacs start slow, and is a problem when you upgrade emacs.

When you find some elisp code on the web, you pile it in your emacs init and you can immediately go back to work on things you need done. That is the beauty of it. The best way i find in keeping emacs init organized, is just to break them into multiple files.

Split Your .emacs into Multiple Files

Go to your emacs init file. If the file has more than 2 hundred lines, then just go to the middle and split the file into 2 files. Name it .emacs.d/emacs_init_1.el and .emacs.d/emacs_init_2.el. The exact file name doesn't matter. Then, in your “.emacs”, change it to like this:

(load "~/.emacs.d/emacs_init_1")
(load "~/.emacs.d/emacs_init_2")

That's it.

When next time you have more code you want to add, just pick a file and add there. Each time, spend no more than 5 minutes doing it.

Rename Files When Needed

Within that 5 min, you can shuffle the file content a bit. Moving keybindings to init_keybinding.el, move loading packages to a separate file init_load_package.el, move misc settings (such as dired, highlighting, line numbering, cursor, font, etc) to another file misc_settings.el.

The init file categories i have are roughly this: {settings, keybinding, load_packages, elisp_functions, ms_windows, misc}. Usually, new things i add to “misc.el”. Once in a while, i clean up that file, move things to proper places.

This way, you have your customization under manageable condition, without much effort. You may edit your init files once a month. Gradually over the years, you may have multiple emacs init files, all manageable and reasonably organized.

Alternatives for Managing Emacs Init

Some people prefer a elaborate annotated init file, using org-mode, somethat like “literate programing”. 〔►see Emacs: Org Mode, Programing Language Code Markup

This way, the init file can be exported to HTML and read on the web.

For such example, see

Other people prefer some kinda system such that the same init file works for home, work, Mac, Microsoft Windows, and or synced to git.

I myself find these ways too cumbersome. I prefer simple, manual, int files for each machine.

Byte Compile Elisp Packages

Emacs: Byte Compile Elisp Files.

Using Emacs's Custom System

See: Emacs: M-x customize Tutorial.

Determine OS, Emacs Version, Machine Host Name

Emacs Lisp: Determine OS, Emacs Version, Machine Host Name

Emacs Lisp: Check If a {function, variable, feature} is Defined/Loaded

Emacs Lisp: Check If a {function, variable, feature} is Defined/Loaded

Emacs Customize Topic

  1. How to Set Emacs's User Interface
  2. Emacs: How to Install Packages Using ELPA, MELPA
  3. How to Install Emacs Package Manually
  4. Emacs: How to Define Keys
  5. Emacs: M-x customize Tutorial
  6. Emacs: Set File to Open in a Major Mode
  7. Organize Emacs Init File in 5 Minutes
  8. Emacs: Byte Compile Elisp Files
  9. Emacs: What's Hook?
  10. Emacs: Set Environment Variables within Emacs
Like it? Buy Xah Emacs Tutorial. Thanks.