Refactor bootstrap process; goodbye bootstrap.el, hello doom macro

This commit is contained in:
Henrik Lissner 2016-05-23 06:26:28 -04:00
parent d4596e2647
commit 13edf0ad3d
4 changed files with 111 additions and 118 deletions

View file

@ -1,82 +0,0 @@
;;; bootstrap.el
(defalias '! 'eval-when-compile)
;; For benchmarking
(defconst emacs-start-time (current-time))
;; Global constants
(defconst doom-default-theme 'wombat)
(defconst doom-terminal-theme 'wombat)
(defconst doom-default-font nil)
(defconst doom-emacs-dir (! (expand-file-name "." user-emacs-directory)))
(defconst doom-core-dir (! (concat doom-emacs-dir "/core")))
(defconst doom-modules-dir (! (concat doom-emacs-dir "/modules")))
(defconst doom-private-dir (! (concat doom-emacs-dir "/private")))
(defconst doom-packages-dir (! (concat doom-emacs-dir "/.cask/" emacs-version "/elpa")))
(defconst doom-script-dir (! (concat doom-emacs-dir "/scripts")))
(defconst doom-ext-dir (! (concat doom-emacs-dir "/ext")))
(defconst doom-snippet-dirs (! (list (concat doom-private-dir "/snippets")
(concat doom-private-dir "/templates"))))
;; Hostname and emacs version-based elisp temp directories
(defconst doom-temp-dir (! (format "%s/cache/%s/%s.%s"
doom-private-dir (system-name)
emacs-major-version emacs-minor-version)))
(defconst IS-MAC (! (eq system-type 'darwin)))
(defconst IS-LINUX (! (eq system-type 'gnu/linux)))
(defconst IS-WINDOWS (! (eq system-type 'windows-nt)))
(defvar doom--load-path load-path)
;; Helper for traversing subdirectories recursively
(defun --subdirs (path &optional include-self)
(let ((result (if include-self (list path) (list))))
(dolist (file (ignore-errors (directory-files path t "^[^.]" t)))
(when (file-directory-p file)
(push file result)))
result))
;;
;; Bootstrap
;;
;; Shut up byte-compiler!
(defvar doom-current-theme)
(defvar doom-current-font)
(defmacro doom (_ default-theme _ term-theme _ font &rest packages)
"Bootstrap DOOM emacs and initialize PACKAGES"
`(progn
(setq doom-default-theme ',default-theme
doom-terminal-theme ',term-theme
doom-default-font (font-spec :family ,(nth 0 font) :size ,(nth 1 font) :antialias ,(not (nth 2 font))))
(setq-default gc-cons-threshold 4388608
gc-cons-percentage 0.4)
;; prematurely optimize for faster startup
(let ((gc-cons-threshold 339430400)
(gc-cons-percentage 0.6)
file-name-handler-alist)
;; Scan various folders to populate the load-paths
(setq load-path
',(append (list doom-private-dir)
(--subdirs doom-core-dir t)
(--subdirs doom-modules-dir t)
(--subdirs doom-packages-dir)
(--subdirs (expand-file-name "../bootstrap" doom-packages-dir))
doom--load-path)
custom-theme-load-path
',(append (list (expand-file-name "themes/" doom-private-dir))
custom-theme-load-path))
(load "~/.emacs.local.el" t t)
(setq doom-current-theme (if (display-graphic-p) doom-default-theme doom-terminal-theme)
doom-current-font doom-default-font)
,@(mapcar (lambda (pkg) `(require ',pkg)) packages)
(when (display-graphic-p)
(require 'server)
(unless (server-running-p)
(server-start)))
;; Prevent any auto-displayed text + benchmarking
(advice-add 'display-startup-echo-area-message :override 'ignore)
(message ""))))
;;; bootstrap.el ends here

View file

@ -1,10 +1,42 @@
;;; core-defuns.el
;; Bootstrap macro
(defmacro doom (_ default-theme __ term-theme ___ font &rest packages)
"Bootstrap DOOM emacs and initialize PACKAGES"
`(let ((gc-cons-threshold 339430400)
(gc-cons-percentage 0.6)
file-name-handler-alist)
;; Local settings
(load "~/.emacs.local.el" t t)
;; Global constants
(defvar doom-default-theme ,default-theme)
(defvar doom-terminal-theme ,term-theme)
(defvar doom-default-font
(font-spec :family ,(nth 0 font)
:size ,(nth 1 font)
:antialias ,(not (nth 2 font))))
(defvar doom-current-theme (if (display-graphic-p) doom-default-theme doom-terminal-theme))
(defvar doom-current-font doom-default-font)
(unless noninteractive
,@(mapcar (lambda (pkg) `(require ',pkg))
packages)
(when (display-graphic-p)
(require 'server)
(unless (server-running-p)
(server-start)))
;; Prevent any auto-displayed text + benchmarking
(advice-add 'display-startup-echo-area-message :override 'ignore)
(message ""))))
;; Backwards compatible `with-eval-after-load' ;; Backwards compatible `with-eval-after-load'
(unless (fboundp 'with-eval-after-load) (unless (fboundp 'with-eval-after-load)
(defmacro with-eval-after-load (file &rest body) (defmacro with-eval-after-load (file &rest body)
`(eval-after-load ,file (lambda () ,@body)))) `(eval-after-load ,file (lambda () ,@body))))
(defmacro λ! (&rest body) (defmacro λ! (&rest body)
"A shortcut for: `(lambda () (interactive) ,@body)" "A shortcut for inline keybind lambdas."
`(lambda () (interactive) ,@body)) `(lambda () (interactive) ,@body))
(defmacro shut-up! (&rest body) (defmacro shut-up! (&rest body)
@ -31,6 +63,9 @@ during compilation."
`(let ((default-directory ,dir)) `(let ((default-directory ,dir))
,@forms)) ,@forms))
(defmacro noop! (name &optional args)
`(defun ,name ,args (interactive) (error "%s not implemented!" name)))
(defmacro add-hook! (hook &rest func-or-forms) (defmacro add-hook! (hook &rest func-or-forms)
"A convenience macro for `add-hook'. "A convenience macro for `add-hook'.
@ -254,15 +289,15 @@ Examples:
(define-key evil-motion-state-map (kbd "S-SPC") ',prev-func))) (define-key evil-motion-state-map (kbd "S-SPC") ',prev-func)))
;; ;;
(defun doom|update-scratch-buffer-cwd (&optional dir) (defun doom|update-scratch-buffer (&optional dir inhibit-doom)
"Make sure scratch buffer is always 'in a project', and looks good." "Make sure scratch buffer is always 'in a project', and looks good."
(let ((dir (or dir (doom/project-root)))) (let ((dir (or dir (doom/project-root))))
(with-current-buffer doom-buffer (with-current-buffer doom-buffer
;; Reset scratch buffer if it wasn't visible ;; Reset scratch buffer if it wasn't visible
(unless (or (eq (current-buffer) doom-buffer) (when (and (get-buffer-window-list doom-buffer nil t)
(--any? (eq doom-buffer it) (doom/get-visible-windows))) (not doom-buffer-edited)
(and (one-window-p t) (doom-mode-init)) (not inhibit-doom))
(setq-local indicate-empty-lines nil)) (doom-mode-init t))
(setq default-directory dir) (setq default-directory dir)
(setq mode-line-format '(:eval (spaceline-ml-scratch)))))) (setq mode-line-format '(:eval (spaceline-ml-scratch))))))
@ -279,14 +314,16 @@ Examples:
(f-directories doom-modules-dir nil t) (f-directories doom-modules-dir nil t)
(f-directories doom-packages-dir) (f-directories doom-packages-dir)
(f-directories (f-expand "../bootstrap" doom-packages-dir)) (f-directories (f-expand "../bootstrap" doom-packages-dir))
doom--load-path))) doom--load-path))
(message "Reloaded!"))
(defun doom-reload-autoloads () (defun doom-reload-autoloads ()
"Regenerate autoloads for DOOM emacs." "Regenerate autoloads for DOOM emacs."
(interactive) (interactive)
(let ((generated-autoload-file (concat doom-core-dir "/autoloads.el"))) (let ((generated-autoload-file (concat doom-core-dir "/autoloads.el")))
(when (file-exists-p generated-autoload-file) (when (file-exists-p generated-autoload-file)
(delete-file generated-autoload-file)) (delete-file generated-autoload-file)
(message "Deleted old autoloads.el"))
(mapc (lambda (dir) (mapc (lambda (dir)
(update-directory-autoloads (concat dir "/defuns")) (update-directory-autoloads (concat dir "/defuns"))
(message "Scanned: %s" dir)) (message "Scanned: %s" dir))

View file

@ -13,6 +13,21 @@
;; ;;
;;; Autoloaded functions are in {core,modules}/defuns/defuns-*.el ;;; Autoloaded functions are in {core,modules}/defuns/defuns-*.el
;; Paths
(defalias '! 'eval-when-compile)
(defconst doom-emacs-dir (! (expand-file-name user-emacs-directory)))
(defconst doom-core-dir (! (expand-file-name "core" doom-emacs-dir)))
(defconst doom-modules-dir (! (expand-file-name "modules" doom-emacs-dir)))
(defconst doom-private-dir (! (expand-file-name "private" doom-emacs-dir)))
(defconst doom-packages-dir (! (expand-file-name (concat ".cask/" emacs-version "/elpa") doom-emacs-dir)))
(defconst doom-ext-dir (! (expand-file-name "ext" doom-emacs-dir)))
(defconst doom-temp-dir
(! (format "%s/cache/%s/%s.%s"
doom-private-dir (system-name)
emacs-major-version emacs-minor-version))
"Hostname and emacs-version-based elisp temp directories")
;; UTF-8 please ;; UTF-8 please
(set-charset-priority 'unicode) (set-charset-priority 'unicode)
(setq locale-coding-system 'utf-8) ; pretty (setq locale-coding-system 'utf-8) ; pretty
@ -22,17 +37,21 @@
(prefer-coding-system 'utf-8) ; with sugar on top (prefer-coding-system 'utf-8) ; with sugar on top
(setq default-process-coding-system '(utf-8-unix . utf-8-unix)) (setq default-process-coding-system '(utf-8-unix . utf-8-unix))
(setq-default major-mode 'text-mode) ;; Premature optimization for faster startup
(setq-default gc-cons-threshold 4388608
gc-cons-percentage 0.4
major-mode 'text-mode)
;; stop package.el from being annoying. I rely solely on Cask. ;; stop package.el from being annoying. I rely solely on Cask.
(setq package--init-file-ensured t (setq package--init-file-ensured t
package-enable-at-startup nil package-enable-at-startup nil
package-archives package-archives
'(("gnu" . "http://elpa.gnu.org/packages/") '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.org/packages/") ("melpa" . "http://melpa.org/packages/")
("org" . "http://orgmode.org/elpa/"))) ("org" . "http://orgmode.org/elpa/"))
;; Core variables ad-redefinition-action 'accept ; silence the advised function warnings
(setq ad-redefinition-action 'accept ; silence the advised function warnings confirm-nonexistent-file-or-buffer t
compilation-always-kill t ; kill compl. process before spawning another compilation-always-kill t ; kill compl. process before spawning another
compilation-ask-about-save nil ; save all buffers before compiling compilation-ask-about-save nil ; save all buffers before compiling
compilation-scroll-output t ; scroll with output while compiling compilation-scroll-output t ; scroll with output while compiling
@ -42,11 +61,10 @@
ediff-split-window-function 'split-window-horizontally ; side-by-side diffs ediff-split-window-function 'split-window-horizontally ; side-by-side diffs
ediff-window-setup-function 'ediff-setup-windows-plain ; no extra frames ediff-window-setup-function 'ediff-setup-windows-plain ; no extra frames
enable-recursive-minibuffers nil ; no minibufferception enable-recursive-minibuffers nil ; no minibufferception
idle-update-delay 2 ; update a little less often idle-update-delay 5 ; update a little less often
ring-bell-function 'ignore ; silence of the bells! ring-bell-function 'ignore ; silence of the bells!
save-interprogram-paste-before-kill nil save-interprogram-paste-before-kill nil
sentence-end-double-space nil sentence-end-double-space nil
confirm-nonexistent-file-or-buffer t
;; http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html ;; http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html
minibuffer-prompt-properties minibuffer-prompt-properties
'(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt) '(read-only t point-entered minibuffer-avoid-prompt face minibuffer-prompt)
@ -66,27 +84,47 @@
undo-tree-history-directory-alist `(("." . ,(concat doom-temp-dir "/undo/")))) undo-tree-history-directory-alist `(("." . ,(concat doom-temp-dir "/undo/"))))
;;
;; Load path
;;
(defvar doom--load-path load-path
"Initial `load-path'; so we don't clobber it on consecutive reloads.")
;; Populate the load-path manually; cask shouldn't be an internal dependency
(setq load-path
(! (defun --subdirs (path &optional include-self)
(let ((result (if include-self (list path) (list))))
(dolist (file (ignore-errors (directory-files path t "^[^.]" t)))
(when (file-directory-p file)
(push file result)))
result))
(append (list doom-private-dir)
(--subdirs doom-core-dir t)
(--subdirs doom-modules-dir t)
(--subdirs doom-packages-dir)
(--subdirs (expand-file-name "../bootstrap" doom-packages-dir))
doom--load-path))
custom-theme-load-path
(! (append (list (expand-file-name "themes/" doom-private-dir))
custom-theme-load-path)))
;; ;;
;; Libraries ;; Libraries
;; ;;
(defgroup doom nil (require 'f)
"Emacs for the stubborn martian vimmer." (require 'dash)
:prefix "doom") (require 's)
(eval-and-compile
(require 'f)
(require 'dash)
(require 's)
(require 'core-vars)
(require 'core-defuns)
(unless (require 'autoloads nil t)
(doom-reload-autoloads)
(unless (require 'autoloads nil t)
(error "Autoloads couldn't be loaded or generated!"))))
(autoload 'use-package "use-package" "" nil 'macro) (autoload 'use-package "use-package" "" nil 'macro)
(require 'core-vars)
(require 'core-defuns)
(unless (require 'autoloads nil t)
(doom-reload-autoloads)
(unless (require 'autoloads nil t)
(error "Autoloads weren't generated! Run `make autoloads`")))
(use-package anaphora (use-package anaphora
:commands (awhen aif acond awhile)) :commands (awhen aif acond awhile))

14
init.el
View file

@ -28,14 +28,14 @@
;; ;;
;;; License: MIT ;;; License: MIT
(load (concat user-emacs-directory "bootstrap.el")) (defconst emacs-start-time (current-time))
(load (concat user-emacs-directory "core/core.el"))
(doom :default-theme doom-one (doom :default-theme 'doom-one
:terminal-theme doom-dark :terminal-theme 'doom-dark
:default-font ("Fira Mono" 12) :default-font ("Fira Mono" 12)
;;; The heart of DOOM ;;; The heart of DOOM
core ; core/core.el
core-os ; os-specific config core-os ; os-specific config
core-scratch ; a perdier scratch buffer core-scratch ; a perdier scratch buffer
core-ui ; draw me like one of your French editors core-ui ; draw me like one of your French editors
@ -59,13 +59,13 @@
module-css ; #big-bang::before { content: ""; } module-css ; #big-bang::before { content: ""; }
module-data ; config/data formats module-data ; config/data formats
module-db ; using emacs as a db browser/client module-db ; using emacs as a db browser/client
module-elisp ; drowning in parentheses
module-go ; the hipster dialect module-go ; the hipster dialect
module-haskell ; a language that's lazier than I am module-haskell ; a language that's lazier than I am
module-java ; the poster child for carpal tunnel syndrome module-java ; the poster child for carpal tunnel syndrome
module-js ; all(hope(abandon(ye(who(enter(here)))))) module-js ; all(hope(abandon(ye(who(enter(here))))))
module-julia ; MATLAB, but fast module-julia ; MATLAB, but fast
module-latex ; for writing papers in Emacs module-latex ; for writing papers in Emacs
module-elisp ; drowning in parentheses
module-lua ; one-based indices? one-based indices. module-lua ; one-based indices? one-based indices.
module-php ; making php less painful to work with module-php ; making php less painful to work with
module-processing ; pretty prototypes module-processing ; pretty prototypes
@ -79,8 +79,8 @@
module-web ; The end is always near </html> module-web ; The end is always near </html>
;;; Experimental ;;; Experimental
; module-eshell ; for inferior OSes *cough*windows ;; module-eshell ; for inferior OSes *cough*windows
; module-org ; for organized fearless leader ;; module-org ; for organized fearless leader
;;; Extra libraries ;;; Extra libraries
extra-demo ; allow me to demonstrate... extra-demo ; allow me to demonstrate...