1 ;;; major-mode-icons.el --- display icon for major-mode on mode-line.
3 ;; Authors: stardiviner <numbchild@gmail.com>
4 ;; Package-Requires: ((emacs "25.1"))
6 ;; Keywords: frames multimedia
7 ;; homepage: http://github.com/stardiviner/major-mode-icons
9 ;; You should have received a copy of the GNU General Public License
10 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
14 ;; If you want to use `major-mode-icons--major-mode-extra' extra info, you
15 ;; should install corresponding packages.
17 ;; - clojure-mode <-> cider
18 ;; - ruby-mode <-> rbenv
19 ;; - python-mode <-> pyvenv
23 ;;; ----------------------------------------------------------------------------
27 (defgroup major-mode-icons nil
28 "Show icon for current buffer's major-mode."
31 (defconst major-mode-icons--icons-default-path
33 (file-name-directory (or load-file-name
36 "Default icons path of major-mode-icons.")
38 (defcustom major-mode-icons-icons-path major-mode-icons--icons-default-path
40 :group
'major-mode-icons
43 (defcustom major-mode-icons-mode-name-font
"Segoe Print"
44 "The font family used for major mode name."
45 :group
'major-mode-icons
48 ;; major mode with icon
49 (defvar major-mode-icons--major-mode-list
51 inferior-emacs-lisp-mode
55 slime-repl-mode sly-mrepl-mode
) .
"Common-Lisp")
56 ((scheme-mode) .
"Scheme")
58 cider-repl-mode
) .
"Clojure")
59 ((clojurescript-mode) .
"ClojureScript")
60 ((python-mode) .
"Python")
61 ((enh-ruby-mode ruby-mode
) .
"Ruby")
62 ((inf-ruby-mode) .
"inf-ruby")
65 ((csharp-mode) .
"C#")
67 ((swift-mode) .
"Swift")
68 ((rust-mode) .
"Rust")
69 ((java-mode) .
"Java")
71 ((web-mode html-mode
) .
"HTML")
74 js-mode js2-mode js3-mode inferior-js-mode
) .
"JavaScript")
75 ((coffee-mode) .
"CoffeeScript")
76 ((org-mode org-agenda-mode
) .
"Org-mode")
77 ((tex-mode latex-mode TeX-mode LaTeX-mode
) .
"TeX")
78 ((bibtex-mode) .
"BibTeX")
79 ((markdown-mode) .
"Markdown")
80 ((yaml-mode) .
"YAML")
81 ((rst-mode) .
"reStructuredText")
82 ((eshell-mode) .
"Command-Line")
83 ((sh-mode shell-mode
) .
"Shell")
84 ((term-mode) .
"term")
85 ((powershell-mode) .
"powershell")
86 ((ess-mode R-mode
) .
"R")
87 ((julia-mode ess-julia-mode
) .
"Julia")
88 ((gnuplot-mode) .
"gnuplot")
89 ((octave-mode) .
"Octave")
90 ((matlab-mode) .
"Matlab")
91 ((haskell-mode) .
"Haskell")
92 ((scala-mode) .
"Scala")
93 ((erlang-mode) .
"Erlang")
94 ((prolog-mode) .
"Prolog")
95 ((ocaml-mode) .
"OCaml")
97 ((xml-mode nxml-mode
) .
"XML")
98 ((json-mode) .
"JSON")
99 ((diff-mode ediff-mode magit-diff-mode
) .
"diff")
100 ((asm-mode nasm-mode
) .
"Assembly")
101 ((android-mode) .
"Android")
103 ((arduino-mode) .
"Arduino")
104 ((systemd-mode) .
"Systemd")
105 ((docker-mode) .
"Docker")
106 ((projectile-rails-mode) .
"Rails")
107 ((slim-mode) .
"Slim")
108 ((sass-mode) .
"Sass")
109 ((spice-mode) .
"Electric")
111 "Pairs: ([mode-list] . [icon-name])."
114 (defun major-mode-icons--major-mode-list-match ()
115 "Return the matched item in `major-mode-list'."
117 (cl-some ; or use (remove nil '(nil nil (clojure-mode) nil nil ...))
119 (when (not (null elem
))
123 (member major-mode element
))
124 (mapcar 'car major-mode-icons--major-mode-list
)))
125 major-mode-icons--major-mode-list
))
127 (defun major-mode-icons--major-mode-icon (&optional extra
)
128 "Display icon for current buffer's `major-mode' and `EXTRA' info."
129 (let* ((match (major-mode-icons--major-mode-list-match))
131 (icon-path (concat major-mode-icons-icons-path icon
".xpm")))
133 (if (and (file-exists-p icon-path
) (image-type-available-p 'xpm
))
136 'display
(if (and (file-exists-p icon-path
) (image-type-available-p 'xpm
))
137 (create-image icon-path
'xpm nil
:ascent
'center
)))
138 (propertize (format "%s" mode-name
))
142 (propertize (format " %s" (or extra
"")))
146 ;;; auto show extra info
147 (defun major-mode-icons--major-mode-extra ()
148 "Extend function `major-mode-icon' with extra info."
152 (if (and (featurep 'cider
)
153 (not (equal (cider--modeline-info) "not connected")))
154 (cider--project-name nrepl-project-dir
)))
156 (if (and (featurep 'rbenv
) global-rbenv-mode
)
157 (rbenv--active-ruby-version) ; `rbenv--modestring'
160 (if (and (featurep 'pyvenv
) pyvenv-mode
)
161 ;; `pyvenv-mode-line-indicator' -> `pyvenv-virtual-env-name'
162 pyvenv-virtual-env-name
163 ;; conda: `conda-env-current-name'
168 (defun major-mode-icons-show ()
169 "Show icon on mode-line."
170 (major-mode-icons--major-mode-icon (major-mode-icons--major-mode-extra)))
172 (defvar major-mode-icons-lighter
173 (let* ((match (major-mode-icons--major-mode-list-match))
175 (propertize (format " %s " mode-name
) ; display `mode-name' text.
178 (concat major-mode-icons-icons-path icon
".xpm")))
179 (if (and (image-type-available-p 'xpm
)
180 (file-exists-p icon-path
))
181 (create-image icon-path
'xpm nil
:ascent
'center
)
183 "Lighter for minor mode `major-mode-icons'.")
185 (put 'major-mode-icons-lighter
'risky-local-variable t
)
188 (define-minor-mode major-mode-icons-mode
189 "A minor mode of showing icon for major-mode of current buffer."
191 :lighter major-mode-icons-lighter
194 ;;; ----------------------------------------------------------------------------
196 (provide 'major-mode-icons
)
198 ;;; major-mode-icons.el ends here