Refactor DOOM init & add new init hooks

+ Add doom-init-hook and doom-post-init-hook to simplify Emacs init
  hooks into less ambiguous ones.
+ Attach former after-init-hook and emacs-startup-hook hooks to new doom
  init hooks.
+ Vastly improves daemon and tty support: preventing incorrect colors
  from bleeding across face class barriers, and into GUI Emacs and vice
  versa, when spawned with emacsclient.
+ Fix persp-mode breaking Emacs daemon, and ensuring that initialization
  is done properly in terminal Emacs (and emacsclient frames).
This commit is contained in:
Henrik Lissner 2017-06-12 00:20:30 +02:00
parent d3054f4679
commit 4984a548d1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
17 changed files with 121 additions and 80 deletions

View file

@ -107,7 +107,7 @@ fundamental-mode) for performance sake."
savehist-autosave-interval nil ; save on kill only
savehist-additional-variables '(kill-ring search-ring regexp-search-ring)
save-place-file (concat doom-cache-dir "saveplace"))
(add-hook! 'emacs-startup-hook #'(savehist-mode save-place-mode))
(add-hook! 'doom-init-hook #'(savehist-mode save-place-mode))
;; Keep track of recently opened files
(def-package! recentf
@ -151,7 +151,7 @@ fundamental-mode) for performance sake."
(t (error "%s is an invalid action for :editorconfig" action)))))
:config
(add-hook 'emacs-startup-hook #'editorconfig-mode)
(add-hook 'doom-init-hook #'editorconfig-mode)
(defun doom|editorconfig-whitespace-mode-maybe (&rest _)
"Show whitespace-mode when file uses TABS (ew)."
@ -169,7 +169,7 @@ fundamental-mode) for performance sake."
sp-max-pair-length 3)
:config
(add-hook 'emacs-startup-hook #'smartparens-global-mode)
(add-hook 'doom-init-hook #'smartparens-global-mode)
(require 'smartparens-config)
;; Smartparens interferes with Replace mode
(add-hook 'evil-replace-state-entry-hook #'turn-off-smartparens-mode)

View file

@ -33,7 +33,7 @@
;; embolden local bindings
(set-face-attribute 'which-key-local-map-description-face nil :weight 'bold)
(which-key-setup-side-window-bottom)
(add-hook 'window-setup-hook #'which-key-mode))
(add-hook 'doom-init-hook #'which-key-mode))
;;

View file

@ -40,8 +40,13 @@
;; See core/autoload/packages.el for more functions.
(defvar doom-init-p nil
"Non-nil if doom's package system has been initialized (by `doom-initialize').
This will be nil if you have byte-compiled your configuration (as intended).")
"Non-nil if doom is done initializing (once `doom-post-init-hook' is done). If
this is nil after Emacs has started something is wrong.")
(defvar doom-package-init-p nil
"If non-nil, doom's package system has been initialized (by
`doom-initialize'). This will be nill if you byte-compile your configuration (as
intended).")
(defvar doom-init-time nil
"The time it took, in seconds, for DOOM Emacs to initialize.")
@ -62,6 +67,9 @@ missing) and shouldn't be deleted.")
(defvar doom-disabled-packages ()
"A list of packages that should be ignored by `def-package!'.")
(defvar doom-reload-hook nil
"A list of hooks to run when `doom/reload' is called.")
(defvar doom--site-load-path load-path
"The load path of built in Emacs libraries.")
@ -123,7 +131,7 @@ base by `doom!' and for calculating how many packages exist.")
are installed. If you byte-compile core/core.el, this function will be avoided
to speed up startup."
;; Called early during initialization; only use native functions!
(when (or (not doom-init-p) force-p)
(when (or (not doom-package-init-p) force-p)
(unless noninteractive
(message "Doom initialized"))
@ -162,7 +170,7 @@ to speed up startup."
(load "quelpa" nil t)
(load "use-package" nil t)
(setq doom-init-p t)))
(setq doom-package-init-p t)))
(defun doom-initialize-autoloads ()
"Ensures that `doom-autoload-file' exists and is loaded. Otherwise run
@ -297,7 +305,7 @@ byte-compilation."
(unless (server-running-p)
(server-start)))
(add-hook 'emacs-startup-hook #'doom--display-benchmark t))))
(add-hook 'doom-post-init-hook #'doom--display-benchmark))))
(defmacro def-package! (name &rest plist)
"A thin wrapper around `use-package'."

View file

@ -90,8 +90,7 @@ is enabled/disabled.'")
("^ \\*" :regexp t :size 12 :noselect t :autokill t :autoclose t)))
:config
(add-transient-hook! 'after-make-frame-functions (shackle-mode +1))
(add-hook 'window-setup-hook #'shackle-mode)
(add-hook 'doom-init-hook #'shackle-mode)
(defun doom*shackle-always-align (plist)
"Ensure popups are always aligned and selected by default. Eliminates the need
@ -540,7 +539,7 @@ you came from."
;; Ensure these settings are attached to org-load-hook as late as possible,
;; giving other modules a chance to add their own hooks.
(add-hook! 'emacs-startup-hook
(defun doom|init-org-popups ()
(add-hook! 'org-load-hook
(set! :popup
'("*Calendar*" :size 0.4 :noselect t)
@ -601,6 +600,7 @@ you came from."
(let ((map org-agenda-mode-map))
(define-key map "q" 'org-agenda-Quit)
(define-key map "Q" 'org-agenda-Quit)))))
(add-hook 'doom-init-hook #'doom|init-org-popups)
(provide 'core-popups)
;;; core-popups.el ends here

View file

@ -21,7 +21,7 @@ state are passed in.")
"build.gradle"))
:config
(add-hook 'after-init-hook #'projectile-mode)
(add-hook 'doom-init-hook #'projectile-mode)
(setq projectile-other-file-alist
(append '(("less" "css")

View file

@ -95,14 +95,14 @@ local value, whether or not it's permanent-local. Therefore, we cycle
;; undo/redo changes to Emacs' window layout
(defvar winner-dont-bind-my-keys t) ; I'll bind keys myself
(require 'winner)
(add-hook 'window-setup-hook #'winner-mode)
(autoload 'winner-mode "winner" nil t)
(add-hook 'doom-init-hook #'winner-mode)
;; highlight matching delimiters
(setq show-paren-delay 0.1
show-paren-highlight-openparen t
show-paren-when-point-inside-paren t)
(add-hook 'window-setup-hook #'show-paren-mode)
(add-hook 'doom-init-hook #'show-paren-mode)
;;; More reliable inter-window border
;; The native border "consumes" a pixel of the fringe on righter-most splits,
@ -110,7 +110,7 @@ local value, whether or not it's permanent-local. Therefore, we cycle
(setq-default window-divider-default-places t
window-divider-default-bottom-width 1
window-divider-default-right-width 1)
(add-hook 'window-setup-hook #'window-divider-mode)
(add-hook 'doom-init-hook #'window-divider-mode)
;; like diminish, but for major-modes. [pedantry intensifies]
(defvar doom-ui-mode-names
@ -132,24 +132,27 @@ mode is detected.")
(global-set-key [remap delete-frame] #'doom/delete-frame)
;; auto-enabled in Emacs 25+; I'd rather enable it manually
(global-eldoc-mode -1)
(global-eldoc-mode -1) ; auto-enabled in Emacs 25+; I'll do it myself
(blink-cursor-mode +1) ; a good indicator that Emacs isn't frozen
;; draw me like one of your French editors
(tooltip-mode -1) ; relegate tooltips to echo area only
(menu-bar-mode -1)
(when (fboundp 'tool-bar-mode)
(tool-bar-mode -1))
(when (display-graphic-p)
(scroll-bar-mode -1)
;; buffer name in frame title
(setq-default frame-title-format '("DOOM Emacs"))
;; standardize fringe width
(push (cons 'left-fringe doom-ui-fringe-size) default-frame-alist)
(push (cons 'right-fringe doom-ui-fringe-size) default-frame-alist)
;; no fringe in the minibuffer
(add-hook! '(emacs-startup-hook minibuffer-setup-hook)
(set-window-fringes (minibuffer-window) 0 0 nil)))
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
;; buffer name in frame title
(setq-default frame-title-format '("DOOM Emacs"))
;; standardize fringe width
(push (cons 'left-fringe doom-ui-fringe-size) default-frame-alist)
(push (cons 'right-fringe doom-ui-fringe-size) default-frame-alist)
;; no fringe in the minibuffer
(defun doom|no-fringes-in-minibuffer ()
(set-window-fringes (minibuffer-window) 0 0 nil))
(add-hook! '(doom-init-hook minibuffer-setup-hook)
#'doom|no-fringes-in-minibuffer)
;;
@ -320,9 +323,8 @@ file."
;; indicators for empty lines past EOF
(def-package! vi-tilde-fringe
:when (display-graphic-p)
:commands global-vi-tilde-fringe-mode
:init (add-hook 'window-setup-hook #'global-vi-tilde-fringe-mode))
:init (add-hook 'doom-init-hook #'global-vi-tilde-fringe-mode))
;; For a distractions-free-like UI, that dynamically resizes margets and can
;; center a buffer.

View file

@ -124,8 +124,15 @@ melodramatic ex-vimmer disappointed with the text-editor status quo."
initial-major-mode 'fundamental-mode
initial-scratch-message nil)
;; Custom init hooks; clearer than `after-init-hook', `emacs-startup-hook', and
;; `window-setup-hook'.
(defvar doom-init-hook nil
"A list of hooks run when DOOM is initialized, before `doom-post-init-hook'.")
(defvar doom-post-init-hook nil
"A list of hooks run after DOOM initialization is complete, and after
`doom-init-hook'.")
;;;
;; Automatic minor modes
(defvar doom-auto-minor-mode-alist '()
"Alist mapping filename patterns to corresponding minor mode functions, like
@ -153,7 +160,7 @@ enable multiple minor modes for the same regexp.")
;;;
;; Bootstrap
;; Initialize
(eval-and-compile
(defvar doom--file-name-handler-alist file-name-handler-alist)
(setq gc-cons-threshold 402653184
@ -170,7 +177,25 @@ enable multiple minor modes for the same regexp.")
(setq load-path (eval-when-compile load-path)
doom--package-load-path (eval-when-compile doom--package-load-path))
;;; Let 'er rip
(defun doom|finalize ()
(unless doom-init-p
(run-hooks 'doom-init-hook)
(run-hooks 'doom-post-init-hook)
;; Don't keep gc-cons-threshold too high. It helps to stave off the GC while
;; Emacs starts up, but afterwards it causes stuttering and random freezes.
;; So reset it to a reasonable default.
(setq gc-cons-threshold 16777216
gc-cons-percentage 0.1
file-name-handler-alist doom--file-name-handler-alist
doom-init-p t)))
(add-hook! '(emacs-startup-hook doom-reload-hook)
#'doom|finalize)
;;;
;; Bootstrap
(load! core-os) ; consistent behavior across Oses
(with-demoted-errors "AUTOLOAD ERROR: %s"
(require 'autoloads doom-autoload-file t))
@ -182,16 +207,5 @@ enable multiple minor modes for the same regexp.")
(load! core-projects) ; making Emacs project-aware
(load! core-keybinds)) ; centralized keybind system + which-key
(defun doom|init ()
;; Don't keep gc-cons-threshold too high. It helps to stave off the GC while
;; Emacs starts up, but afterwards it causes stuttering and random freezes. So
;; reset it to a reasonable default.
(setq gc-cons-threshold 16777216
gc-cons-percentage 0.1
file-name-handler-alist doom--file-name-handler-alist))
(add-hook! '(emacs-startup-hook doom-reload-hook)
#'doom|init)
(provide 'core)
;;; core.el ends here