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” 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” organized, is just to break them into multiple files.

Split Your .emacs into Multiple Files

Go to your “.emacs”. 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.

Byte Compile Elisp Packages

Emacs: Byte Compile Elisp Files.

Using Emacs's Custom System

See: Emacs: Customize System 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

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from my keyboard store.