Mode icons now updates based on an idle timer

- This should allow modes to turn on in a hook and still being
  recognized by mode-icons.

- This may also address issue #19
This commit is contained in:
Matthew Fidler 2016-03-30 13:52:40 -05:00
parent d493f67631
commit 323b48e416

View file

@ -575,23 +575,26 @@ ICON-SPEC should be a specification from `mode-icons'."
(defvar mode-icons-set-minor-mode-icon-alist nil) (defvar mode-icons-set-minor-mode-icon-alist nil)
(defun mode-icons-set-minor-mode-icon-undo () (defun mode-icons-set-minor-mode-icon-undo (&optional dont-update)
"Undo minor modes." "Undo minor modes.
When DONT-UPDATE is non-nil, don't call `force-mode-line-update'."
(let (minor) (let (minor)
(dolist (mode mode-icons-set-minor-mode-icon-alist) (dolist (mode mode-icons-set-minor-mode-icon-alist)
(setq minor (assq (car mode) minor-mode-alist)) (setq minor (assq (car mode) minor-mode-alist))
(when minor (when minor
(setcdr minor (cdr mode))))) (setcdr minor (cdr mode)))))
(setq mode-icons-set-minor-mode-icon-alist nil) (setq mode-icons-set-minor-mode-icon-alist nil)
(force-mode-line-update)) (unless dont-update
(force-mode-line-update)))
(defcustom mode-icons-separate-images-with-spaces t (defcustom mode-icons-separate-images-with-spaces t
"Separate minor-mode icons with spaces." "Separate minor-mode icons with spaces."
:type 'boolean :type 'boolean
:group 'mode-icons) :group 'mode-icons)
(defun mode-icons-set-minor-mode-icon () (defun mode-icons-set-minor-mode-icon (&optional dont-update)
"Set the icon for the minor modes." "Set the icon for the minor modes.
When DONT-UPDATE is non-nil, don't call `force-mode-line-update'"
(let (icon-spec mode-name minor) (let (icon-spec mode-name minor)
(dolist (mode minor-mode-alist) (dolist (mode minor-mode-alist)
(unless (assq (car mode) mode-icons-set-minor-mode-icon-alist) (unless (assq (car mode) mode-icons-set-minor-mode-icon-alist)
@ -608,7 +611,8 @@ ICON-SPEC should be a specification from `mode-icons'."
(setcdr minor (list "")) (setcdr minor (list ""))
(setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "")
mode-name))))))))) mode-name)))))))))
(force-mode-line-update)) (unless dont-update
(force-mode-line-update)))
(defun mode-icons--generate-major-mode-item () (defun mode-icons--generate-major-mode-item ()
"Give rich strings needed for `major-mode' viewing." "Give rich strings needed for `major-mode' viewing."
@ -863,17 +867,33 @@ STRING is the string to modify, or if absent, the value from `mode-line-eol-desc
:global t :global t
(if mode-icons-mode (if mode-icons-mode
(progn (progn
(add-hook 'after-change-major-mode-hook 'mode-icons-set-current-mode-icon) ;; (add-hook 'after-change-major-mode-hook 'mode-icons-set-current-mode-icon)
(add-hook 'after-change-major-mode-hook 'mode-icons-set-minor-mode-icon) (add-hook 'after-change-major-mode-hook #'mode-icons-reset)
(mode-icons-fix t) (mode-icons-fix t)
(mode-icons-set-minor-mode-icon) (mode-icons-set-minor-mode-icon)
(mode-icons-major-mode-icons)) (mode-icons-major-mode-icons))
(remove-hook 'after-change-major-mode-hook 'mode-icons-set-minor-mode-icon) (remove-hook 'after-change-major-mode-hook #'mode-icons-reset)
(remove-hook 'after-change-major-mode-hook 'mode-icons-set-current-mode-icon)
(mode-icons-set-minor-mode-icon-undo) (mode-icons-set-minor-mode-icon-undo)
(mode-icons-major-mode-icons-undo) (mode-icons-major-mode-icons-undo)
(mode-icons-fix))) (mode-icons-fix)))
(defun mode-icons-reset-now ()
"Reset mode-icons icons."
(interactive)
(when (and mode-icons-mode (not (minibufferp)))
(mode-icons-set-current-mode-icon)
;; FIXME -- undo to allow `ergoemacs-mode' and color changing
;; XPMs. Seems a bit heavy handed.
(mode-icons-set-minor-mode-icon-undo t)
(mode-icons-set-minor-mode-icon)))
(defun mode-icons-reset ()
"Reset mode-icons icons."
(interactive)
(run-with-idle-timer 0.1 nil #'mode-icons-reset-now))
(add-hook 'emacs-startup-hook #'mode-icons-reset)
(provide 'mode-icons) (provide 'mode-icons)
;;; mode-icons.el ends here ;;; mode-icons.el ends here
;; Local Variables: ;; Local Variables: