Sets up clean organization inside user-emacs-directory
with a separate custom.el
file, a backup directory and a settings.org
file for a more literate emacs configuration that can be built upon.
Note that you may need to ”touch
” some of the initial files so no error appears on startup.
;; do not use `init.el` for `custom-*` code - use `custom-file.el`.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file))
;; backup in one place. flat, no tree structure. for files with names like
;; ~foo.el~ autogenerated by emacs.
(setq backup-directory-alist `(("" . ,(concat user-emacs-directory "backup/"))))
;; Require and initialize `package`.
(require 'package)
;; set package.el repositories.
(setq package-archives
'(("org" . "https://orgmode.org/elpa/")
("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
;; Put downloaded packages inside "~/clean-emacs/elpa-27".
(let ((path (format (concat user-emacs-directory "elpa-%s") emacs-major-version)))
(if (file-accessible-directory-p path)
(setq package-user-dir path)))
;; initialize built-in package management.
(package-initialize)
;; update packages list if we are on a new install.
(unless package-archive-contents
(package-refresh-contents))
;; a list of pkgs to programmatically install.
(setq my-package-list '(use-package evil))
;; programmatically install/ensure installed
;; pkgs in your personal list
(dolist (package my-package-list)
(unless (package-installed-p package)
(package-install package)))
;; can now "(use-package pkgname)" for package configuring.
;;
;; for packages not installed via elpa, need to add them to load path.
(let ((path (expand-file-name (concat user-emacs-directory "lisp/"))))
(if (file-accessible-directory-p path)
(add-to-list 'load-path path t)))
;; configure rest of packages in "settings.org" org file.
(org-babel-load-file
(expand-file-name "settings.org"
user-emacs-directory))
;; NOTE, settings.org must exit and be non-empty so that there is no error upon
;; startup. Must contain at least one "#+begin_src emacs-lisp" block.
;;
;; MISC NOISE PUT HERE SO "settings.org" is not polluted.
;;
Sample settings.org
#+begin_src emacs-lisp
;; change typing "yes" or "no" in minibuffer prompts to typing "y" or "n".
(fset 'yes-or-no 'y-or-n-p)
#+end_src