Refactor bootstrap process; goodbye bootstrap.el, hello doom macro
This commit is contained in:
parent
d4596e2647
commit
13edf0ad3d
4 changed files with 111 additions and 118 deletions
82
bootstrap.el
82
bootstrap.el
|
@ -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
|
|
@ -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'
|
||||
(unless (fboundp 'with-eval-after-load)
|
||||
(defmacro with-eval-after-load (file &rest body)
|
||||
`(eval-after-load ,file (lambda () ,@body))))
|
||||
|
||||
(defmacro λ! (&rest body)
|
||||
"A shortcut for: `(lambda () (interactive) ,@body)"
|
||||
"A shortcut for inline keybind lambdas."
|
||||
`(lambda () (interactive) ,@body))
|
||||
|
||||
(defmacro shut-up! (&rest body)
|
||||
|
@ -31,6 +63,9 @@ during compilation."
|
|||
`(let ((default-directory ,dir))
|
||||
,@forms))
|
||||
|
||||
(defmacro noop! (name &optional args)
|
||||
`(defun ,name ,args (interactive) (error "%s not implemented!" name)))
|
||||
|
||||
(defmacro add-hook! (hook &rest func-or-forms)
|
||||
"A convenience macro for `add-hook'.
|
||||
|
||||
|
@ -254,15 +289,15 @@ Examples:
|
|||
(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."
|
||||
(let ((dir (or dir (doom/project-root))))
|
||||
(with-current-buffer doom-buffer
|
||||
;; Reset scratch buffer if it wasn't visible
|
||||
(unless (or (eq (current-buffer) doom-buffer)
|
||||
(--any? (eq doom-buffer it) (doom/get-visible-windows)))
|
||||
(and (one-window-p t) (doom-mode-init))
|
||||
(setq-local indicate-empty-lines nil))
|
||||
(when (and (get-buffer-window-list doom-buffer nil t)
|
||||
(not doom-buffer-edited)
|
||||
(not inhibit-doom))
|
||||
(doom-mode-init t))
|
||||
(setq default-directory dir)
|
||||
(setq mode-line-format '(:eval (spaceline-ml-scratch))))))
|
||||
|
||||
|
@ -279,14 +314,16 @@ Examples:
|
|||
(f-directories doom-modules-dir nil t)
|
||||
(f-directories doom-packages-dir)
|
||||
(f-directories (f-expand "../bootstrap" doom-packages-dir))
|
||||
doom--load-path)))
|
||||
doom--load-path))
|
||||
(message "Reloaded!"))
|
||||
|
||||
(defun doom-reload-autoloads ()
|
||||
"Regenerate autoloads for DOOM emacs."
|
||||
(interactive)
|
||||
(let ((generated-autoload-file (concat doom-core-dir "/autoloads.el")))
|
||||
(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)
|
||||
(update-directory-autoloads (concat dir "/defuns"))
|
||||
(message "Scanned: %s" dir))
|
||||
|
|
66
core/core.el
66
core/core.el
|
@ -13,6 +13,21 @@
|
|||
;;
|
||||
;;; 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
|
||||
(set-charset-priority 'unicode)
|
||||
(setq locale-coding-system 'utf-8) ; pretty
|
||||
|
@ -22,17 +37,21 @@
|
|||
(prefer-coding-system 'utf-8) ; with sugar on top
|
||||
(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.
|
||||
(setq package--init-file-ensured t
|
||||
package-enable-at-startup nil
|
||||
package-archives
|
||||
'(("gnu" . "http://elpa.gnu.org/packages/")
|
||||
("melpa" . "http://melpa.org/packages/")
|
||||
("org" . "http://orgmode.org/elpa/")))
|
||||
("org" . "http://orgmode.org/elpa/"))
|
||||
|
||||
;; Core variables
|
||||
(setq ad-redefinition-action 'accept ; silence the advised function warnings
|
||||
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-ask-about-save nil ; save all buffers before 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-window-setup-function 'ediff-setup-windows-plain ; no extra frames
|
||||
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!
|
||||
save-interprogram-paste-before-kill nil
|
||||
sentence-end-double-space nil
|
||||
confirm-nonexistent-file-or-buffer t
|
||||
;; http://ergoemacs.org/emacs/emacs_stop_cursor_enter_prompt.html
|
||||
minibuffer-prompt-properties
|
||||
'(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/"))))
|
||||
|
||||
|
||||
;;
|
||||
;; 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
|
||||
;;
|
||||
|
||||
(defgroup doom nil
|
||||
"Emacs for the stubborn martian vimmer."
|
||||
:prefix "doom")
|
||||
|
||||
(eval-and-compile
|
||||
(require 'f)
|
||||
(require 'dash)
|
||||
(require 's)
|
||||
|
||||
(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 couldn't be loaded or generated!"))))
|
||||
|
||||
(autoload 'use-package "use-package" "" nil 'macro)
|
||||
(error "Autoloads weren't generated! Run `make autoloads`")))
|
||||
|
||||
(use-package anaphora
|
||||
:commands (awhen aif acond awhile))
|
||||
|
|
14
init.el
14
init.el
|
@ -28,14 +28,14 @@
|
|||
;;
|
||||
;;; 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
|
||||
:terminal-theme doom-dark
|
||||
(doom :default-theme 'doom-one
|
||||
:terminal-theme 'doom-dark
|
||||
:default-font ("Fira Mono" 12)
|
||||
|
||||
;;; The heart of DOOM
|
||||
core ; core/core.el
|
||||
core-os ; os-specific config
|
||||
core-scratch ; a perdier scratch buffer
|
||||
core-ui ; draw me like one of your French editors
|
||||
|
@ -59,13 +59,13 @@
|
|||
module-css ; #big-bang::before { content: ""; }
|
||||
module-data ; config/data formats
|
||||
module-db ; using emacs as a db browser/client
|
||||
module-elisp ; drowning in parentheses
|
||||
module-go ; the hipster dialect
|
||||
module-haskell ; a language that's lazier than I am
|
||||
module-java ; the poster child for carpal tunnel syndrome
|
||||
module-js ; all(hope(abandon(ye(who(enter(here))))))
|
||||
module-julia ; MATLAB, but fast
|
||||
module-latex ; for writing papers in Emacs
|
||||
module-elisp ; drowning in parentheses
|
||||
module-lua ; one-based indices? one-based indices.
|
||||
module-php ; making php less painful to work with
|
||||
module-processing ; pretty prototypes
|
||||
|
@ -79,8 +79,8 @@
|
|||
module-web ; The end is always near </html>
|
||||
|
||||
;;; Experimental
|
||||
; module-eshell ; for inferior OSes *cough*windows
|
||||
; module-org ; for organized fearless leader
|
||||
;; module-eshell ; for inferior OSes *cough*windows
|
||||
;; module-org ; for organized fearless leader
|
||||
|
||||
;;; Extra libraries
|
||||
extra-demo ; allow me to demonstrate...
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue