   (add-to-list 'kill-buffer-query-functions #'doom|protect-visible-buffer nil 'eq)
   (add-hook 'after-change-major-mode-hook #'doom|highlight-non-default-indentation)
 
+  ;; Reload theme if the display device has changed
   (add-hook 'after-make-frame-functions #'doom|reload-theme-in-frame-maybe)
   (add-hook 'after-delete-frame-functions #'doom|reload-theme-maybe)
 

       (signal 'doom-error e)))))

(defun doom|init-theme ()
  "Set the theme and load the font, in that order."
  (when (and doom-theme (not (memq doom-theme custom-enabled-themes)))
    (let ((doom--prefer-theme-elc t))
      (load-theme doom-theme t))))

;; Getting themes to remain consistent across GUI Emacs, terminal Emacs and
;; daemon Emacs is hairy. `doom|init-theme' sorts out the initial GUI frame.
;; Attaching `doom|init-theme-in-frame' to `after-make-frame-functions' sorts
;; out daemon and emacsclient frames.
;;
;; There will still be issues with simultaneous gui and terminal (emacsclient)
;; frames, however. There's always `doom/reload-theme' if you need it!
(defun doom|reload-theme-in-frame-maybe (frame)
  "Reloads the theme in new daemon or tty frames."
  (when (and doom-theme
             (framep frame)
             (not (eq doom-last-window-system (framep-on-display frame))))

  (add-hook 'focus-in-hook #'doom|run-switch-frame-hooks)
  (advice-add! '(switch-to-buffer display-buffer) :around #'doom*run-switch-buffer-hooks))

;; Apply `doom-theme'
(unless (daemonp)
  (add-hook 'doom-init-ui-hook #'doom|init-theme))
;; Apply `doom-font' et co
(add-hook 'doom-after-init-modules-hook #'doom|init-fonts)
;; Setup `doom-load-theme-hook'
(advice-add #'load-theme :after #'doom*run-load-theme-hooks)

(add-hook 'window-setup-hook #'doom|init-ui)


