From 82cfba411c544c862a0854f682494a437642c957 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Sun, 20 Sep 2020 13:31:42 -0700 Subject: [PATCH] Don't try to enable `mode-icons-mode' until a frame exists In order to work better with the Emacs daemon, don't try to set up `mode-icons-mode' when no frame has been created yet. This should prevent `mode-icons-mode' trying to figure out what height the icons should be when we don't know what sort of font will be used yet. --- mode-icons.el | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index 4f61df1..44c3eeb 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -1790,20 +1790,38 @@ When ENABLE is non-nil, enable the changes to the mode line." (when place-eol (setcar place-eol mode-icons--backup-eol-construct))))) +(defun mode-icons--mode-enable () + "Set up for the command ‘mode-icons-mode’." + (add-hook 'after-change-major-mode-hook #'mode-icons-reset) + (mode-icons-fix t) + (mode-icons-set-minor-mode-icon) + (mode-icons-major-mode-icons)) + +(defun mode-icons--mode-enable-for-first-frame () + "Set up for the command ‘mode-icons-mode’ and then stop it from running again. +This function should be used in the +‘server-after-make-frame-hook’ hook. It will call +‘mode-icons--mode-enable’ and then remove itself from +‘server-after-make-frame-hook’." + (mode-icons--mode-enable) + (remove-hook 'server-after-make-frame-hook #'mode-icons--mode-enable-for-first-frame)) + +(defun mode-icons--mode-disable () + "Tear down for the command ‘mode-icons-mode’." + (remove-hook 'after-change-major-mode-hook #'mode-icons-reset) + (mode-icons-set-minor-mode-icon-undo) + (mode-icons-major-mode-icons-undo) + (mode-icons-fix)) + ;;;###autoload (define-minor-mode mode-icons-mode "Replace the name of the current major mode with an icon." :global t (if mode-icons-mode - (progn - (add-hook 'after-change-major-mode-hook #'mode-icons-reset) - (mode-icons-fix t) - (mode-icons-set-minor-mode-icon) - (mode-icons-major-mode-icons)) - (remove-hook 'after-change-major-mode-hook #'mode-icons-reset) - (mode-icons-set-minor-mode-icon-undo) - (mode-icons-major-mode-icons-undo) - (mode-icons-fix))) + (if (daemonp) + (add-hook 'server-after-make-frame-hook #'mode-icons--mode-enable-for-first-frame) + (mode-icons--mode-enable)) + (mode-icons--mode-disable))) (defun mode-icons-reset-hash () "Reset `mode-icons-get-icon-spec' and `mode-icons-get-icon-display'." @@ -1826,8 +1844,6 @@ When ENABLE is non-nil, enable the changes to the mode line." (with-current-buffer ,(current-buffer) (mode-icons-set-minor-mode-icon))))))) -(add-hook 'emacs-startup-hook #'mode-icons-reset) - (defadvice isearch-mode (after mode-icons--reset-isearch-icon activate) "Make `mode-icons' aware of icon." (mode-icons-set-minor-mode-icon))