splitting Emacs config

Published on 10 Feb 2019

I think I am getting better at using Emacs. I have been using Emacs Org mode for managing my to-do lists since November 2018. Actually, I tried using Emacs with Spacemacs in fall 2017, but for some reasons I stopped using Spacemacs after 3 months.

The process of configuring Emacs involves editing the ~/.emacs file. I found myself adding lines after lines in ~/.emacs to point it looked like a mess. Then I thought if it was possible to make my configuration modular by splitting parts of the configurations into separate files.

I did that, and it worked. I feel like this is an ideal solution for me.

The ~/.emacs is still retained because Emacs spits something into it whenever I install some packages from MELPA repository. At the bottom of ~/.emacs, I placed this line:

; load my custom configs
(load "~/.emacs.d/init.el")

In ~/.emacs.d/init.el (referred to as init.el from now on), I placed some basic Emacs configurations such as the enabling the Evil, disabling splash screen, etc.

; -------------------
; Base Configurations
; -------------------

; disable splash screen
(setq inhibit-splash-screen t)

; enable transient mark mode
(transient-mark-mode 1)

; Melpa repository
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

; activate Evil mode
(require 'evil)
(evil-mode 1)

; activate spacemacs-dark theme 
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'spacemacs-dark t)

; suppress the creation of backup file
(setq make-backup-files nil)

So, where is this modular part? There is another section in init.el where I defined extra sets of configuration by pointing to separate .el files, usually package-specific.

; ---------------------------------
; Activate Package's Configurations
; ---------------------------------

; load shortcut keys
(load "~/.emacs.d/shortcuts.el")

; load org-mode config
(load "~/.emacs.d/org-mode.el")

For example, I have a file ~/.emacs.d/org-mode.el to define the behavior for Org mode.

(use-package org
    :mode (("\\.org$" . org-mode))
    :ensure t
        ; use unicode bullets
        (require 'org-bullets)
        (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
        ; set custom color for TODO keywords
        (setq org-todo-keyword-faces
        ("TODO" . "orange")
        ("NEXT" . "red")
        ("AXED" . "blue")
        ("BACK" . "pink")

I also have a configuration file for managing custom keyboard shortcuts, the ~/emacs.md/shortcuts.el.

; define keys with general.el
  :states '(normal emacs)
  :prefix "SPC"
  ; base
  "sv" 'visual-line-mode
  "sd" 'kill-this-buffer
  "sw" 'save-buffer
  "sq" 'save-buffers-kill-terminal
  ; org-mode
  "aq" 'org-archive-subtree-default
  ; helm
  "hp" 'helm-find
  "ff" 'helm-find-files
  "bb" 'helm-mini

This setup works for me. I am not entirely sure if there is a performance penalty, but I guess I will figure that out sooner or later.