From 34416c46437d972fb83141b34c5742e372d751d1 Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Thu, 21 Jan 2016 22:50:31 -0600 Subject: Add mode-icons prefix to functions --- mode-icons.el | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index 10d40ec..6a3f7df 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -70,14 +70,15 @@ absolute path to ICON." ("XML" "xml" xpm) ("YAML" "yaml" xpm) ("YASnippet" "yas" xpm) + (" yas" "yas" xpm) ) - "Icons for major modes. + "Icons for major and minor modes. Each specification is a list with the first element being the name of the major mode. The second the name of the icon file, without the extension. And the third being the type of icon.") -(defun get-icon-display (icon type) +(defun mode-icons-get-icon-display (icon type) "Get the value for the display property of ICON having TYPE. ICON should be a string naming the file of the icon, without its @@ -87,29 +88,29 @@ the icon." (concat icon "." (symbol-name type))))) `(image :type ,type :file ,icon-path :ascent center))) -(defun propertize-mode (mode icon-spec) +(defun mode-icons-propertize-mode (mode icon-spec) "Propertize MODE with ICON-SPEC. MODE should be a string, the name of the mode to propertize. ICON-SPEC should be a specification from `mode-icons'." (propertize - mode 'display (get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))) + mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))) -(defun get-mode-icon (mode) +(defun mode-icons-get-mode-icon (mode) "Get the icon for MODE, if there is one." (let* ((mode-name (format-mode-line mode)) (icon-spec (assoc mode-name mode-icons))) (if icon-spec - (propertize-mode mode-name icon-spec) + (mode-icons-propertize-mode mode-name icon-spec) mode-name))) -(defun set-mode-icon (mode) +(defun mode-icons-set-mode-icon (mode) "Set the icon for MODE." - (setq mode-name (get-mode-icon mode))) + (setq mode-name (mode-icons-get-mode-icon mode))) -(defun set-current-mode-icon () +(defun mode-icons-set-current-mode-icon () "Set the icon for the current major mode." - (set-mode-icon mode-name)) + (mode-icons-set-mode-icon mode-name)) ;;;###autoload (define-minor-mode mode-icons-mode @@ -117,9 +118,9 @@ ICON-SPEC should be a specification from `mode-icons'." :global t (if mode-icons-mode (progn - (add-hook 'after-change-major-mode-hook 'set-current-mode-icon) - (set-current-mode-icon)) - (remove-hook 'after-change-major-mode-hook 'set-current-mode-icon))) + (add-hook 'after-change-major-mode-hook 'mode-icons-set-current-mode-icon) + (mode-icons-set-current-mode-icon)) + (remove-hook 'after-change-major-mode-hook 'mode-icons-set-current-mode-icon))) (provide 'mode-icons) ;;; mode-icons.el ends here -- cgit v1.2.3-54-g00ecf From 74702c8bc7b8422e4ec25a3c79dec69e518698dc Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 00:23:45 -0600 Subject: Add icons for minor modes --- mode-icons.el | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/mode-icons.el b/mode-icons.el index 6a3f7df..fa10e06 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -112,6 +112,31 @@ ICON-SPEC should be a specification from `mode-icons'." "Set the icon for the current major mode." (mode-icons-set-mode-icon mode-name)) +(defvar mode-icons-set-minor-mode-icon-alist nil) + +(defun mode-icons-set-minor-mode-icon-undo () + (let (minor) + (dolist (mode mode-icons-set-minor-mode-icon-alist) + (setq minor (assq (car mode) minor-mode-alist)) + (when minor + (setcdr minor (cdr mode))))) + (setq mode-icons-set-minor-mode-icon-alist nil)) + +(defun mode-icons-set-minor-mode-icon () + "Set the icon for the minor modes." + (let (icon-spec mode-name minor) + (dolist (mode minor-mode-alist) + (unless (assq (car mode) mode-icons-set-minor-mode-icon-alist) + (setq mode-name (format-mode-line mode) + icon-spec (assoc mode-name mode-icons)) + (when icon-spec + (setq minor (assq (car mode) minor-mode-alist)) + (when minor + (or (assq (car mode) mode-icons-set-minor-mode-icon-alist) + (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) + (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) + (setcdr minor (list (concat " " (mode-icons-propertize-mode mode-name icon-spec)))))))))) + ;;;###autoload (define-minor-mode mode-icons-mode "Replace the name of the current major mode with an icon." @@ -119,8 +144,12 @@ ICON-SPEC should be a specification from `mode-icons'." (if mode-icons-mode (progn (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) + (mode-icons-set-minor-mode-icon) (mode-icons-set-current-mode-icon)) - (remove-hook 'after-change-major-mode-hook 'mode-icons-set-current-mode-icon))) + (remove-hook 'after-change-major-mode-hook 'mode-icons-set-minor-mode-icon) + (remove-hook 'after-change-major-mode-hook 'mode-icons-set-current-mode-icon) + (mode-icons-set-minor-mode-icon-undo))) (provide 'mode-icons) ;;; mode-icons.el ends here -- cgit v1.2.3-54-g00ecf From 423d5a5868933897aec1624faa512054330dd2c8 Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 09:31:03 -0600 Subject: Add customize group and separation options --- mode-icons.el | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index fa10e06..4d4b929 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -26,6 +26,10 @@ ;; ;;; Code: +(defgroup mode-icons nil + "Provide icons for major modes." + :group 'editing-basics + :group 'convenience) (defconst mode-icons--directory (if load-file-name @@ -40,9 +44,8 @@ ICON should be a file name with extension. The result is the absolute path to ICON." (concat mode-icons--directory "/icons/" icon)) -(defvar mode-icons - `( - ("CSS" "css" xpm) +(defcustom mode-icons + '(("CSS" "css" xpm) ("Coffee" "coffee" xpm) ("Compilation" "compile" xpm) ("Emacs-Lisp" "emacs" xpm) @@ -71,12 +74,24 @@ absolute path to ICON." ("YAML" "yaml" xpm) ("YASnippet" "yas" xpm) (" yas" "yas" xpm) - ) + (" hs" "hs" xpm)) "Icons for major and minor modes. -Each specification is a list with the first element being the +Each specificatioun is a list with the first element being the name of the major mode. The second the name of the icon file, -without the extension. And the third being the type of icon.") +without the extension. And the third being the type of icon." + :type '(repeat + (list (string :tag "Regular Expression") + (choice + (string :tag "Icon Name") + (const :tag "Suppress" nil)) + (choice + (const :tag "png" png) + (const :tag "gif" gif) + (const :tag "jpeg" jepg) + (const :tag "xbm" xbm) + (const :tag "xpm" xpm)))) + :group 'mode-icons) (defun mode-icons-get-icon-display (icon type) "Get the value for the display property of ICON having TYPE. @@ -93,8 +108,10 @@ the icon." MODE should be a string, the name of the mode to propertize. ICON-SPEC should be a specification from `mode-icons'." - (propertize - mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))) + (cond + ((not (nth 1 icon-spec)) "") + (t (propertize + mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))))) (defun mode-icons-get-mode-icon (mode) "Get the icon for MODE, if there is one." @@ -122,6 +139,11 @@ ICON-SPEC should be a specification from `mode-icons'." (setcdr minor (cdr mode))))) (setq mode-icons-set-minor-mode-icon-alist nil)) +(defcustom mode-icons-separate-images-with-spaces t + "Separate minor-mode icons with spaces." + :type 'boolean + :group 'mode-icons) + (defun mode-icons-set-minor-mode-icon () "Set the icon for the minor modes." (let (icon-spec mode-name minor) @@ -135,7 +157,8 @@ ICON-SPEC should be a specification from `mode-icons'." (or (assq (car mode) mode-icons-set-minor-mode-icon-alist) (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) - (setcdr minor (list (concat " " (mode-icons-propertize-mode mode-name icon-spec)))))))))) + (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") + (mode-icons-propertize-mode mode-name icon-spec)))))))))) ;;;###autoload (define-minor-mode mode-icons-mode -- cgit v1.2.3-54-g00ecf From 150f27878ede51136f0ef9d4c14472b83fffeebe Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 09:44:27 -0600 Subject: Allow regular expression matching. --- mode-icons.el | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index 4d4b929..ce9a587 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -113,10 +113,18 @@ ICON-SPEC should be a specification from `mode-icons'." (t (propertize mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))))) +(defun mode-icons-get-icon-spec (mode) + "Get icon spec based on regular expression." + (catch 'found-mode + (dolist (item mode-icons) + (when (string-match-p (car item) mode) + (throw 'found-mode item))) + nil)) + (defun mode-icons-get-mode-icon (mode) "Get the icon for MODE, if there is one." (let* ((mode-name (format-mode-line mode)) - (icon-spec (assoc mode-name mode-icons))) + (icon-spec (mode-icons-get-icon-spec mode-name))) (if icon-spec (mode-icons-propertize-mode mode-name icon-spec) mode-name))) @@ -150,7 +158,7 @@ ICON-SPEC should be a specification from `mode-icons'." (dolist (mode minor-mode-alist) (unless (assq (car mode) mode-icons-set-minor-mode-icon-alist) (setq mode-name (format-mode-line mode) - icon-spec (assoc mode-name mode-icons)) + icon-spec (mode-icons-get-icon-spec mode-name)) (when icon-spec (setq minor (assq (car mode) minor-mode-alist)) (when minor -- cgit v1.2.3-54-g00ecf From 220b53964f8b4632e058dba0b7bd644b18deaca4 Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 10:47:32 -0600 Subject: Reverse mode-line-icons mode --- mode-icons.el | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index ce9a587..6615598 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -129,9 +129,29 @@ ICON-SPEC should be a specification from `mode-icons'." (mode-icons-propertize-mode mode-name icon-spec) mode-name))) +(defvar mode-icons-cached-mode-name nil + "Cached mode name to restore when disabling mode-icons.") + (defun mode-icons-set-mode-icon (mode) "Set the icon for MODE." - (setq mode-name (mode-icons-get-mode-icon mode))) + (unless mode-icons-cached-mode-name + (set (make-local-variable 'mode-icons-cached-mode-name) + mode-name) + (setq mode-name (mode-icons-get-mode-icon mode)))) + +(defun mode-icons-major-mode-icons-undo () + "Undo the mode-name changes" + (dolist (b (buffer-list)) + (with-current-buffer b + (when mode-icons-cached-mode-name + (setq mode-name mode-icons-cached-mode-name + mode-icons-cached-mode-name nil))))) + +(defun mode-icons-major-mode-icons () + "Apply mode name changes on all buffers." + (dolist (b (buffer-list)) + (with-current-buffer b + (mode-icons-set-current-mode-icon)))) (defun mode-icons-set-current-mode-icon () "Set the icon for the current major mode." @@ -177,10 +197,11 @@ ICON-SPEC should be a specification from `mode-icons'." (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) (mode-icons-set-minor-mode-icon) - (mode-icons-set-current-mode-icon)) + (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-set-current-mode-icon) - (mode-icons-set-minor-mode-icon-undo))) + (mode-icons-set-minor-mode-icon-undo) + (mode-icons-major-mode-icons-undo))) (provide 'mode-icons) ;;; mode-icons.el ends here -- cgit v1.2.3-54-g00ecf From 9e4d51fea0dd2b3cda1cc5ffe80eef7f9956c4f0 Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 11:32:49 -0600 Subject: Use force-mode-line-update --- mode-icons.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mode-icons.el b/mode-icons.el index 6615598..f727bec 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -186,7 +186,8 @@ ICON-SPEC should be a specification from `mode-icons'." (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") - (mode-icons-propertize-mode mode-name icon-spec)))))))))) + (mode-icons-propertize-mode mode-name icon-spec))))))))) + (force-mode-line-update t)) ;;;###autoload (define-minor-mode mode-icons-mode -- cgit v1.2.3-54-g00ecf From f1dea72cf65db8dccfcf7449c31ae6f3961c4f6b Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 11:33:24 -0600 Subject: Fix jpeg typo --- mode-icons.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mode-icons.el b/mode-icons.el index f727bec..f684ccd 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -88,7 +88,7 @@ without the extension. And the third being the type of icon." (choice (const :tag "png" png) (const :tag "gif" gif) - (const :tag "jpeg" jepg) + (const :tag "jpeg" jpeg) (const :tag "xbm" xbm) (const :tag "xpm" xpm)))) :group 'mode-icons) -- cgit v1.2.3-54-g00ecf From 9131e57b2441c9bf91b48726c0073cba79a6c63d Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 12:05:08 -0600 Subject: Add force-mode-line-update --- mode-icons.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mode-icons.el b/mode-icons.el index f684ccd..cce6440 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -187,7 +187,7 @@ ICON-SPEC should be a specification from `mode-icons'." (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") (mode-icons-propertize-mode mode-name icon-spec))))))))) - (force-mode-line-update t)) + (force-mode-line-update)) ;;;###autoload (define-minor-mode mode-icons-mode -- cgit v1.2.3-54-g00ecf From c4080009b2c55fe2b7dc42de621475a465344a35 Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 12:09:51 -0600 Subject: Take out tabs; Add local variable that forbids tabs --- mode-icons.el | 59 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index cce6440..fb5873a 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -81,16 +81,16 @@ Each specificatioun is a list with the first element being the name of the major mode. The second the name of the icon file, without the extension. And the third being the type of icon." :type '(repeat - (list (string :tag "Regular Expression") - (choice - (string :tag "Icon Name") - (const :tag "Suppress" nil)) - (choice - (const :tag "png" png) - (const :tag "gif" gif) - (const :tag "jpeg" jpeg) - (const :tag "xbm" xbm) - (const :tag "xpm" xpm)))) + (list (string :tag "Regular Expression") + (choice + (string :tag "Icon Name") + (const :tag "Suppress" nil)) + (choice + (const :tag "png" png) + (const :tag "gif" gif) + (const :tag "jpeg" jpeg) + (const :tag "xbm" xbm) + (const :tag "xpm" xpm)))) :group 'mode-icons) (defun mode-icons-get-icon-display (icon type) @@ -118,7 +118,7 @@ ICON-SPEC should be a specification from `mode-icons'." (catch 'found-mode (dolist (item mode-icons) (when (string-match-p (car item) mode) - (throw 'found-mode item))) + (throw 'found-mode item))) nil)) (defun mode-icons-get-mode-icon (mode) @@ -136,7 +136,7 @@ ICON-SPEC should be a specification from `mode-icons'." "Set the icon for MODE." (unless mode-icons-cached-mode-name (set (make-local-variable 'mode-icons-cached-mode-name) - mode-name) + mode-name) (setq mode-name (mode-icons-get-mode-icon mode)))) (defun mode-icons-major-mode-icons-undo () @@ -144,8 +144,8 @@ ICON-SPEC should be a specification from `mode-icons'." (dolist (b (buffer-list)) (with-current-buffer b (when mode-icons-cached-mode-name - (setq mode-name mode-icons-cached-mode-name - mode-icons-cached-mode-name nil))))) + (setq mode-name mode-icons-cached-mode-name + mode-icons-cached-mode-name nil))))) (defun mode-icons-major-mode-icons () "Apply mode name changes on all buffers." @@ -164,7 +164,7 @@ ICON-SPEC should be a specification from `mode-icons'." (dolist (mode mode-icons-set-minor-mode-icon-alist) (setq minor (assq (car mode) minor-mode-alist)) (when minor - (setcdr minor (cdr mode))))) + (setcdr minor (cdr mode))))) (setq mode-icons-set-minor-mode-icon-alist nil)) (defcustom mode-icons-separate-images-with-spaces t @@ -177,16 +177,16 @@ ICON-SPEC should be a specification from `mode-icons'." (let (icon-spec mode-name minor) (dolist (mode minor-mode-alist) (unless (assq (car mode) mode-icons-set-minor-mode-icon-alist) - (setq mode-name (format-mode-line mode) - icon-spec (mode-icons-get-icon-spec mode-name)) - (when icon-spec - (setq minor (assq (car mode) minor-mode-alist)) - (when minor - (or (assq (car mode) mode-icons-set-minor-mode-icon-alist) - (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) - (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) - (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") - (mode-icons-propertize-mode mode-name icon-spec))))))))) + (setq mode-name (format-mode-line mode) + icon-spec (mode-icons-get-icon-spec mode-name)) + (when icon-spec + (setq minor (assq (car mode) minor-mode-alist)) + (when minor + (or (assq (car mode) mode-icons-set-minor-mode-icon-alist) + (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) + (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) + (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") + (mode-icons-propertize-mode mode-name icon-spec))))))))) (force-mode-line-update)) ;;;###autoload @@ -196,9 +196,9 @@ ICON-SPEC should be a specification from `mode-icons'." (if mode-icons-mode (progn (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) - (mode-icons-set-minor-mode-icon) - (mode-icons-major-mode-icons)) + (add-hook 'after-change-major-mode-hook 'mode-icons-set-minor-mode-icon) + (mode-icons-set-minor-mode-icon) + (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-set-current-mode-icon) (mode-icons-set-minor-mode-icon-undo) @@ -206,3 +206,6 @@ ICON-SPEC should be a specification from `mode-icons'." (provide 'mode-icons) ;;; mode-icons.el ends here +;; Local Variables: +;; indent-tabs-mode: nil +;; End: -- cgit v1.2.3-54-g00ecf From 837c63da1207333524e38777d79c0058f1be5a9a Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 15:54:31 -0600 Subject: Fix mode-icons for standard mode-line --- mode-icons.el | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index fb5873a..dd078db 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -101,17 +101,34 @@ extension. Type should be a symbol designating the file type for the icon." (let ((icon-path (mode-icons-get-icon-file (concat icon "." (symbol-name type))))) - `(image :type ,type :file ,icon-path :ascent center))) + `(image :type ,type :file ,icon-path :ascent center))) -(defun mode-icons-propertize-mode (mode icon-spec) +(defcustom mode-icons-minor-mode-base-text-properties + '('help-echo 'rm--help-echo + 'mouse-face 'mode-line-highlight + 'local-map mode-line-minor-mode-keymap) + "List of text propeties to apply to every minor mode." + :type '(repeat sexp) + :group 'mode-icons) + +(defvar mode-icons-powerline-p nil) +(defun mode-icons-need-update-p () + "Determine if the mode-icons need an update" + (not (or (and (boundp 'rich-minority-mode) rich-minority-mode) + (member 'sml/pos-id-separator mode-line-format) + (string-match-p "powerline" (prin1-to-string mode-line-format))))) + +(defun mode-icons-propertize-mode (mode icon-spec &optional extra-props) "Propertize MODE with ICON-SPEC. MODE should be a string, the name of the mode to propertize. -ICON-SPEC should be a specification from `mode-icons'." +ICON-SPEC should be a specification from `mode-icons'. +EXTRA-PROPS should be a list of extra properties to apply to the text." (cond ((not (nth 1 icon-spec)) "") - (t (propertize - mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))))) + ((and extra-props (mode-icons-need-update-p)) + (eval `(propertize ,mode 'display ',(mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)) ,@extra-props))) + (t (propertize mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))))) (defun mode-icons-get-icon-spec (mode) "Get icon spec based on regular expression." @@ -165,7 +182,8 @@ ICON-SPEC should be a specification from `mode-icons'." (setq minor (assq (car mode) minor-mode-alist)) (when minor (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)) (defcustom mode-icons-separate-images-with-spaces t "Separate minor-mode icons with spaces." @@ -186,9 +204,35 @@ ICON-SPEC should be a specification from `mode-icons'." (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") - (mode-icons-propertize-mode mode-name icon-spec))))))))) + (mode-icons-propertize-mode mode-name icon-spec mode-icons-minor-mode-base-text-properties))))))))) (force-mode-line-update)) +(defun mode-icons--generate-minor-mode-list () + "Extracts all rich strings necessary for the minor mode list." + (split-string (format-mode-line minor-mode-alist))) + +;; Based on rich-minority by Artur Malabarba +(defvar mode-icons--backup-construct nil) +(defvar mode-icons--mode-line-construct + '(:eval (mode-icons--generate-minor-mode-list)) + "Construct used to replace `minor-mode-alist'.") + +(defun mode-icons-fix (&optional enable) + "Fix mode-icons." + (if enable + (let ((place (or (member 'minor-mode-alist mode-line-modes) + (cl-member-if + (lambda (x) (and (listp x) + (equal (car x) :propertize) + (equal (cadr x) '("" minor-mode-alist)))) + mode-line-modes)))) + (when place + (setq mode-icons--backup-construct (car place)) + (setcar place mode-icons--mode-line-construct))) + (let ((place (member mode-icons--mode-line-construct mode-line-modes))) + (when place + (setcar place mode-icons--backup-construct))))) + ;;;###autoload (define-minor-mode mode-icons-mode "Replace the name of the current major mode with an icon." @@ -197,12 +241,14 @@ ICON-SPEC should be a specification from `mode-icons'." (progn (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) + (mode-icons-fix t) (mode-icons-set-minor-mode-icon) (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-set-current-mode-icon) (mode-icons-set-minor-mode-icon-undo) - (mode-icons-major-mode-icons-undo))) + (mode-icons-major-mode-icons-undo) + (mode-icons-fix))) (provide 'mode-icons) ;;; mode-icons.el ends here -- cgit v1.2.3-54-g00ecf From 7f3f53b51074b57253548b6bf90c7e40770ad6dd Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 17:31:53 -0600 Subject: Fix mode-icons to work better with vanilla emacs --- mode-icons.el | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index dd078db..96cbe46 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -1,4 +1,3 @@ - ;;; mode-icons.el --- Show icons for modes -*- lexical-binding: t; -*- ;; Copyright (C) 2013 Tom Willemse @@ -74,7 +73,8 @@ absolute path to ICON." ("YAML" "yaml" xpm) ("YASnippet" "yas" xpm) (" yas" "yas" xpm) - (" hs" "hs" xpm)) + (" hs" "hs" xpm) + ("\\(ElDoc\\|Anzu\\|SP\\|Guide\\|PgLn\\|Golden\\|Undo-Tree\\|Ergo.*\\|,\\)" nil nil)) "Icons for major and minor modes. Each specificatioun is a list with the first element being the @@ -86,6 +86,7 @@ without the extension. And the third being the type of icon." (string :tag "Icon Name") (const :tag "Suppress" nil)) (choice + (const :tag "text" nil) (const :tag "png" png) (const :tag "gif" gif) (const :tag "jpeg" jpeg) @@ -118,16 +119,13 @@ the icon." (member 'sml/pos-id-separator mode-line-format) (string-match-p "powerline" (prin1-to-string mode-line-format))))) -(defun mode-icons-propertize-mode (mode icon-spec &optional extra-props) +(defun mode-icons-propertize-mode (mode icon-spec) "Propertize MODE with ICON-SPEC. MODE should be a string, the name of the mode to propertize. -ICON-SPEC should be a specification from `mode-icons'. -EXTRA-PROPS should be a list of extra properties to apply to the text." +ICON-SPEC should be a specification from `mode-icons'." (cond ((not (nth 1 icon-spec)) "") - ((and extra-props (mode-icons-need-update-p)) - (eval `(propertize ,mode 'display ',(mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)) ,@extra-props))) (t (propertize mode 'display (mode-icons-get-icon-display (nth 1 icon-spec) (nth 2 icon-spec)))))) (defun mode-icons-get-icon-spec (mode) @@ -204,12 +202,17 @@ EXTRA-PROPS should be a list of extra properties to apply to the text." (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") - (mode-icons-propertize-mode mode-name icon-spec mode-icons-minor-mode-base-text-properties))))))))) + (mode-icons-propertize-mode mode-name icon-spec))))))))) (force-mode-line-update)) (defun mode-icons--generate-minor-mode-list () "Extracts all rich strings necessary for the minor mode list." - (split-string (format-mode-line minor-mode-alist))) + (delete "" (mapcar (lambda(mode) + (let ((pm (eval `(propertize ,mode ,@mode-icons-minor-mode-base-text-properties)))) + (unless (string= pm "") + (setq pm (concat " " pm))) + pm)) + (split-string (format-mode-line minor-mode-alist))))) ;; Based on rich-minority by Artur Malabarba (defvar mode-icons--backup-construct nil) -- cgit v1.2.3-54-g00ecf From f0f3103a49dff06dfe825ff161ba4cec4fb7ffb2 Mon Sep 17 00:00:00 2001 From: Matthew L. Fidler Date: Fri, 22 Jan 2016 22:49:44 -0600 Subject: Fix the diminished modes so they display nothing --- mode-icons.el | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mode-icons.el b/mode-icons.el index 96cbe46..fac2833 100644 --- a/mode-icons.el +++ b/mode-icons.el @@ -200,19 +200,19 @@ ICON-SPEC should be a specification from `mode-icons'." (when minor (or (assq (car mode) mode-icons-set-minor-mode-icon-alist) (push (copy-sequence minor) mode-icons-set-minor-mode-icon-alist)) - (setq mode-name (replace-regexp-in-string "^ " "" mode-name)) - (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") - (mode-icons-propertize-mode mode-name icon-spec))))))))) + (setq mode-name (replace-regexp-in-string "^ " "" mode-name) + mode-name (mode-icons-propertize-mode mode-name icon-spec)) + (if (string= "" mode-name) + (setcdr minor (list "")) + (setcdr minor (list (concat (or (and mode-icons-separate-images-with-spaces " ") "") + mode-name))))))))) (force-mode-line-update)) (defun mode-icons--generate-minor-mode-list () "Extracts all rich strings necessary for the minor mode list." - (delete "" (mapcar (lambda(mode) - (let ((pm (eval `(propertize ,mode ,@mode-icons-minor-mode-base-text-properties)))) - (unless (string= pm "") - (setq pm (concat " " pm))) - pm)) - (split-string (format-mode-line minor-mode-alist))))) + (delete " " (delete "" (mapcar (lambda(mode) + (concat " " (eval `(propertize ,mode ,@mode-icons-minor-mode-base-text-properties)))) + (split-string (format-mode-line minor-mode-alist)))))) ;; Based on rich-minority by Artur Malabarba (defvar mode-icons--backup-construct nil) -- cgit v1.2.3-54-g00ecf