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

@ -33,7 +33,7 @@
:config
(load "helm-autoloads" nil t)
(add-hook 'emacs-startup-hook #'helm-mode)
(add-hook 'doom-init-hook #'helm-mode)
(defvar helm-projectile-find-file-map (make-sparse-keymap))
(require 'helm-projectile)

View file

@ -40,7 +40,7 @@ session)."
(after! magit (setq magit-completing-read-function #'ivy-completing-read))
(after! yasnippet (push #'+ivy-yas-prompt yas-prompt-functions))
(add-hook 'emacs-startup-hook #'ivy-mode)
(add-hook 'doom-init-hook #'ivy-mode)
(map! :map ivy-mode-map
[remap apropos] #'counsel-apropos

View file

@ -44,7 +44,7 @@
shift-select-mode nil)
:config
(add-hook 'emacs-startup-hook #'evil-mode)
(add-hook 'doom-init-hook #'evil-mode)
(evil-select-search-module 'evil-search-module 'evil-search)
(set! :popup
@ -242,7 +242,7 @@ across windows."
evil-escape-excluded-major-modes '(neotree-mode)
evil-escape-key-sequence "jk"
evil-escape-delay 0.25)
(add-hook 'emacs-startup-hook #'evil-escape-mode)
(add-hook 'doom-post-init-hook #'evil-escape-mode)
:config
;; no `evil-escape' in minibuffer
(cl-pushnew #'minibufferp evil-escape-inhibit-functions)
@ -333,7 +333,7 @@ the new algorithm is confusing, like in python or ruby."
(?\] "[]})]")
(?\; "[;:]")))
:config
(add-hook 'emacs-startup-hook #'evil-snipe-override-mode))
(add-hook 'doom-post-init-hook #'evil-snipe-override-mode))
(def-package! evil-surround
@ -349,7 +349,7 @@ the new algorithm is confusing, like in python or ruby."
:init
(setq vimish-fold-dir (concat doom-cache-dir "vimish-fold/")
vimish-fold-indication-mode 'right-fringe)
(add-hook 'emacs-startup-hook #'evil-vimish-fold-mode t))
(add-hook 'doom-post-init-hook #'evil-vimish-fold-mode t))
;; Without `evil-visualstar', * and # grab the word at point and search, no

View file

@ -43,21 +43,24 @@ renamed.")
;; auto-save on kill
persp-auto-save-opt 1)
(defun +workspaces|init (&rest _)
(unless persp-mode
(persp-mode +1)
(add-hook 'doom-init-hook #'+workspaces|init t)
(add-hook 'after-make-frame-functions #'+workspaces|init)
(defun +workspaces|init (&optional frame)
(let ((frame (or frame (selected-frame))))
(unless persp-mode
(persp-mode +1))
;; The default perspective persp-mode makes (defined by `persp-nil-name')
;; is special and doesn't actually represent a real persp object, so
;; buffers can't really be assigned to it, among other quirks. We create a
;; *real* main workspace to fill this role.
(persp-add-new +workspaces-main)
(unless (persp-with-name-exists-p +workspaces-main)
(persp-add-new +workspaces-main))
;; Switch to it if we aren't auto-loading the last session
(when (or (= persp-auto-resume-time -1)
(equal (safe-persp-name (get-current-persp)) persp-nil-name))
(persp-frame-switch +workspaces-main))))
(add-hook 'emacs-startup-hook #'+workspaces|init)
(add-hook 'after-make-frame-functions #'+workspaces|init)
(when (or (equal (safe-persp-name (get-current-persp)) persp-nil-name)
(and (one-window-p)
(eq (window-buffer (selected-window)) (doom-fallback-buffer))))
(persp-frame-switch +workspaces-main frame))))
(define-key persp-mode-map [remap delete-window] #'+workspace/close-window-or-workspace)

View file

@ -58,7 +58,7 @@
"M-b" #'+eval/build
"M-a" #'mark-whole-buffer
"M-c" #'evil-yank
"M-q" #'save-buffers-kill-emacs
"M-q" (if (daemonp) #'delete-frame #'save-buffers-kill-emacs)
"M-s" #'save-buffer
"M-v" #'clipboard-yank
"M-f" #'swiper

View file

@ -8,7 +8,7 @@
(when theme
(mapc #'disable-theme custom-enabled-themes))
(load "doom-themes-common.el" nil t)
(load-theme theme t)
(+doom|init)
(+doom|refresh-bright-buffers)))
;;;###autoload

View file

@ -16,17 +16,33 @@
"Fallback font for unicode glyphs. Is ignored if :feature unicode is active.")
;;; Set fonts
(when (display-graphic-p)
;; Getting themes to remain consistent across GUI Emacs, terminal Emacs and
;; daemon Emacs is hairy.
;;
;; + Running `+doom|init' directly sorts out the initial GUI frame.
;; + Attaching it to `after-make-frame-functions' sorts out daemon Emacs.
;; + Terminal Emacs is a bit of a wildcard.
(defun +doom|init (&optional frame)
"Set the theme and load the font, in that order."
(load-theme +doom-theme t)
(with-demoted-errors "FONT ERROR: %s"
(set-frame-font +doom-font t t)
(set-frame-font +doom-font nil (if frame (list frame) t))
;; Fallback to `doom-unicode-font' for Unicode characters
(unless (featurep! :ui unicode)
(when +doom-unicode-font
(set-fontset-font t 'unicode +doom-unicode-font)))
(set-fontset-font t 'unicode +doom-unicode-font frame)))
;; ...and for variable-pitch mode
(when +doom-variable-pitch-font
(set-face-attribute 'variable-pitch nil :font +doom-variable-pitch-font))))
(set-face-attribute 'variable-pitch frame :font +doom-variable-pitch-font))))
(defun +doom|init-daemon (frame)
(when (or (daemonp) (not (display-graphic-p)))
(with-selected-frame frame
(run-with-timer 0 nil #'+doom|init))))
(add-hook 'after-make-frame-functions #'+doom|init)
(add-hook 'after-make-frame-functions #'+doom|init-daemon)
;; doom-one: gives Emacs a look inspired by Dark One in Atom.
@ -35,13 +51,11 @@
:load-path "~/work/plugins/emacs-doom-themes/"
:demand t
:config
(load-theme +doom-theme t)
(+doom|init)
;; blink mode-line on errors
(add-hook 'emacs-startup-hook #'doom-themes-visual-bell-config t)
(add-hook 'doom-post-init-hook #'doom-themes-visual-bell-config)
;; Add file icons to doom-neotree
(add-hook 'emacs-startup-hook #'doom-themes-neotree-config t)
(add-hook 'doom-post-init-hook #'doom-themes-neotree-config)
(setq doom-neotree-enable-variable-pitch t
doom-neotree-file-icons 'simple
doom-neotree-line-spacing 2)
@ -52,11 +66,6 @@
:foreground "#ffffff"
:background (doom-color 'current-line))
;; Dark frames by default
(when (display-graphic-p)
(push (cons 'background-color (doom-color 'bg)) initial-frame-alist)
(push (cons 'foreground-color (doom-color 'fg)) initial-frame-alist))
(after! neotree
(defun +doom|neotree-fix-popup ()
"Ensure the fringe settings are maintained on popup restore."

View file

@ -6,4 +6,4 @@
:init
(setq evil-goggles-duration 0.1
evil-goggles-enable-delete nil)
(add-hook 'emacs-startup-hook #'evil-goggles-mode t))
(add-hook 'doom-post-init-hook #'evil-goggles-mode t))