Refactor bootstrap process

This commit is contained in:
Henrik Lissner 2016-03-26 01:19:31 -04:00
parent b3feea7a4f
commit 89eeba1d97
6 changed files with 83 additions and 60 deletions

View file

@ -1,82 +1,93 @@
;;; bootstrap.el ;;; bootstrap.el
(eval-when-compile (require 'cl))
;; Shut up byte-compiler!
(defvar narf-current-theme)
(defvar narf-current-font)
;; Global constants
(eval-and-compile (eval-and-compile
(defconst narf-emacs-dir user-emacs-directory) (defconst narf-default-theme 'wombat)
(defconst narf-core-dir (concat narf-emacs-dir "core/")) (defconst narf-default-font nil)
(defconst narf-modules-dir (concat narf-emacs-dir "modules/"))
(defconst narf-private-dir (concat narf-emacs-dir "private/")) (defconst narf-emacs-dir (expand-file-name "." user-emacs-directory))
(defconst narf-packages-dir (concat narf-emacs-dir ".cask/" emacs-version "/elpa/")) (defconst narf-core-dir (concat narf-emacs-dir "/core"))
(defconst narf-script-dir (concat narf-emacs-dir "scripts/")) (defconst narf-modules-dir (concat narf-emacs-dir "/modules"))
(defconst narf-snippet-dirs (list (concat narf-private-dir "snippets/") (defconst narf-private-dir (concat narf-emacs-dir "/private"))
(concat narf-private-dir "templates/"))) (defconst narf-packages-dir (concat narf-emacs-dir "/.cask/" emacs-version "/elpa"))
(defconst narf-script-dir (concat narf-emacs-dir "/scripts"))
(defconst narf-snippet-dirs (list (concat narf-private-dir "/snippets")
(concat narf-private-dir "/templates")))
;; Hostname and emacs version-based elisp temp directories ;; Hostname and emacs version-based elisp temp directories
(defconst narf-temp-dir (defconst narf-temp-dir (format "%s/cache/%s/%s.%s/"
(format "%scache/%s/%s.%s/"
narf-private-dir (system-name) narf-private-dir (system-name)
emacs-major-version emacs-minor-version)) emacs-major-version emacs-minor-version))
(defconst IS-MAC (eq system-type 'darwin)) (defconst IS-MAC (eq system-type 'darwin))
(defconst IS-LINUX (eq system-type 'gnu/linux)) (defconst IS-LINUX (eq system-type 'gnu/linux))
(defconst IS-WINDOWS (eq system-type 'windows-nt))) (defconst IS-WINDOWS (eq system-type 'windows-nt))
;; Global settings ;; Ensure that cask is in the right place
(scroll-bar-mode -1) ; no scrollbar ;; (let ((cask-dir (cond (IS-MAC "/usr/local/share/emacs/site-lisp/cask")
(tool-bar-mode -1) ; no toolbar ;; (t "~/.cask"))))
;; (unless (file-exists-p cask-dir)
(setq-default ;; (error "Cask folder not found"))
;; stop package.el from being annoying. NARF relies entirely on Cask. ;; (push cask-dir load-path))
package--init-file-ensured t
package-enable-at-startup nil
gc-cons-threshold 4388608
gc-cons-percentage 0.3)
(eval-and-compile
;; Make sure that cask is in the right place
(unless (eq 0 (call-process "which" nil nil nil "cask"))
(error "Cask could not be found"))
(let ((cask-dir (cond (IS-MAC "/usr/local/share/emacs/site-lisp/cask")
(t "~/.cask"))))
(unless (file-exists-p cask-dir)
(error "Cask folder not found"))
(push cask-dir load-path))
;; Helper for traversing subdirectories recursively ;; Helper for traversing subdirectories recursively
(defun --subdirs (path &optional include-self) (defun --subdirs (path &optional include-self)
(let ((result (if include-self (list path) (list))) (let ((result (if include-self (list path) (list))))
(paths (ignore-errors (directory-files path t "^[^.]" t)))) (dolist (file (ignore-errors (directory-files path t "^[^.]" t)))
(dolist (file paths)
(when (file-directory-p file) (when (file-directory-p file)
(push file result))) (push file result)))
result)) result)))
;;
;; Bootstrap
;;
(defun narf (packages)
"Bootstrap NARF emacs and initialize PACKAGES"
;; stop package.el from being annoying. NARF relies entirely on Cask.
(setq-default
package--init-file-ensured t
package-enable-at-startup nil
gc-cons-threshold 4388608)
;; prematurely optimize for faster startup
(let ((gc-cons-threshold 169715200)
(gc-cons-percentage 0.3)
file-name-handler-alist)
;; Scan various folders to populate the load-paths
(defvar narf--load-path load-path) (defvar narf--load-path load-path)
(defun narf/reload ()
(interactive)
(setq load-path (setq load-path
(progn (require 'cask)
(cask-initialize)
(append (list narf-private-dir) (append (list narf-private-dir)
(--subdirs narf-core-dir t) (--subdirs narf-core-dir t)
(--subdirs narf-modules-dir t) (--subdirs narf-modules-dir t)
(--subdirs narf-packages-dir) (--subdirs narf-packages-dir)
narf--load-path))))) (--subdirs (expand-file-name "../bootstrap" narf-packages-dir))
narf--load-path)
(defun narf (packages) custom-theme-load-path
"Bootstrap NARF emacs and initialize PACKAGES"
;; prematurely optimize for faster startup
(let (file-name-handler-alist
(gc-cons-threshold 169715200))
;; Scan various folders to populate the load-paths
(setq custom-theme-load-path
(append (list (expand-file-name "themes/" narf-private-dir)) (append (list (expand-file-name "themes/" narf-private-dir))
custom-theme-load-path) custom-theme-load-path))
load-path (eval-when-compile (narf/reload)))
(require 'f)
(require 'dash)
(require 's)
;; Load local settings, if available ;; Load local settings, if available
(when (file-exists-p "~/.emacs.local.el") (when (file-exists-p "~/.emacs.local.el")
(load "~/.emacs.local.el")) (load "~/.emacs.local.el"))
(load-theme narf-default-theme t)
;; Global settings
(setq narf-current-theme narf-default-theme (setq narf-current-theme narf-default-theme
narf-current-font narf-default-font) narf-current-font narf-default-font)
;; Load 'em up!
(load-theme narf-current-theme t)
(mapc 'require packages) (mapc 'require packages)
(defun display-startup-echo-area-message () (defun display-startup-echo-area-message ()

View file

@ -20,7 +20,7 @@
company-yasnippet company-yasnippet
company-dabbrev-code) company-dabbrev-code)
company-dabbrev) company-dabbrev)
company-statistics-file (concat narf-temp-dir "company-stats-cache.el") company-statistics-file (concat narf-temp-dir "/company-stats-cache.el")
company-quickhelp-delay nil) company-quickhelp-delay nil)
:config :config

View file

@ -227,6 +227,15 @@ to abort the minibuffer."
;; (delete-windows-on "*Completions*")) ;; (delete-windows-on "*Completions*"))
(abort-recursive-edit)))) (abort-recursive-edit))))
(defun narf-reload ()
"Reload `load-path', in case you updated cask while emacs was open!"
(interactive)
(setq load-path (append (list narf-private-dir narf-core-dir narf-modules-dir narf-packages-dir)
(f-directories narf-core-dir nil t)
(f-directories narf-modules-dir nil t)
(f-directories narf-packages-dir)
narf--load-path)))
(after! evil (after! evil
(evil-define-command narf:exit-mode-maybe () (evil-define-command narf:exit-mode-maybe ()
"Exits insert/replace mode using jk without the momentary pause caused by "Exits insert/replace mode using jk without the momentary pause caused by

View file

@ -42,6 +42,9 @@
(if (not window-system) (if (not window-system)
(menu-bar-mode -1) (menu-bar-mode -1)
(scroll-bar-mode -1) ; no scrollbar
(tool-bar-mode -1) ; no toolbar
;; Set fonts ;; Set fonts
(narf/load-font narf-default-font) (narf/load-font narf-default-font)
(set-face-attribute 'default t :font narf-default-font) (set-face-attribute 'default t :font narf-default-font)

View file

@ -84,7 +84,7 @@
(require 'dash) (require 'dash)
(unless (require 'autoloads nil t) (unless (require 'autoloads nil t)
(load (concat narf-emacs-dir "scripts/generate-autoloads.el")) (load (concat narf-emacs-dir "/scripts/generate-autoloads.el"))
(require 'autoloads)) (require 'autoloads))
(require 'core-vars) (require 'core-vars)
(require 'core-defuns) (require 'core-defuns)
@ -151,7 +151,7 @@
;; ;;
;; Allow errors to stop this from happening ;; We put this on `after-init-hook' Allow errors to stop this from happening
(add-hook! after-init (add-hook! after-init
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate) (defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
"Prevent annoying \"Active processes exist\" query when you quit Emacs." "Prevent annoying \"Active processes exist\" query when you quit Emacs."

View file

@ -1,9 +1,9 @@
;; NARF Dark ;; NARF Dark
;; By Henrik Lissner <http://github.com/hlissner/emacs.d> ;; By Henrik Lissner <http://github.com/hlissner/emacs.d>
(deftheme narf-dark "A dark theme for narfy emacs, inspired by Molokai") (require 'dash)
;; (custom-theme-set-variables 'narf-dark) (deftheme narf-dark "A dark theme for narfy emacs, inspired by Molokai")
;; Color helper functions ;; Color helper functions
;; Shamelessly *borrowed* from solarized ;; Shamelessly *borrowed* from solarized