2015-12-24 06:39:38 +01:00
|
|
|
|
2013-06-02 13:56:07 +02:00
|
|
|
;;; mode-icons.el --- Show icons for modes -*- lexical-binding: t; -*-
|
2012-11-10 23:12:36 +01:00
|
|
|
|
2013-06-02 14:48:00 +02:00
|
|
|
;; Copyright (C) 2013 Tom Willemse
|
2012-11-10 23:12:36 +01:00
|
|
|
|
2013-06-02 14:45:06 +02:00
|
|
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
2012-11-10 23:12:36 +01:00
|
|
|
;; Keywords: multimedia
|
2012-11-10 23:21:46 +01:00
|
|
|
;; Version: 0.1.0
|
2013-06-02 14:45:06 +02:00
|
|
|
;; URL: http://ryuslash.org/projects/mode-icons.html
|
2012-11-10 23:12:36 +01:00
|
|
|
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2013-06-02 13:56:07 +02:00
|
|
|
(defconst mode-icons--directory
|
|
|
|
(if load-file-name
|
|
|
|
(file-name-directory load-file-name)
|
|
|
|
default-directory)
|
2012-11-10 23:17:42 +01:00
|
|
|
"Where mode-icons was loaded from.")
|
|
|
|
|
2013-06-02 13:56:07 +02:00
|
|
|
(defun mode-icons-get-icon-file (icon)
|
|
|
|
"Get the location of ICON.
|
|
|
|
|
|
|
|
ICON should be a file name with extension. The result is the
|
|
|
|
absolute path to ICON."
|
|
|
|
(concat mode-icons--directory "/icons/" icon))
|
2012-11-10 23:12:36 +01:00
|
|
|
|
|
|
|
(defvar mode-icons
|
2015-12-24 06:39:38 +01:00
|
|
|
`(
|
2015-12-21 11:19:20 +01:00
|
|
|
("CSS" "css" xpm)
|
2015-12-24 06:39:38 +01:00
|
|
|
("Coffee" "coffee" xpm)
|
2016-01-06 06:44:36 +01:00
|
|
|
("Compilation" "compile" xpm)
|
2015-12-24 06:39:38 +01:00
|
|
|
("Emacs-Lisp" "emacs" xpm)
|
2013-06-02 13:56:07 +02:00
|
|
|
("HTML" "html" xpm)
|
2015-12-24 06:39:38 +01:00
|
|
|
("Haml" "haml" xpm)
|
|
|
|
("Image[imagemagick]" "svg" xpm)
|
|
|
|
("JavaScript" "js" xpm)
|
|
|
|
("Lisp" "cl" xpm)
|
2016-01-14 09:21:22 +01:00
|
|
|
("nXML" "xml" xpm)
|
2015-12-23 07:12:18 +01:00
|
|
|
("Org" "org" xpm)
|
2015-12-24 06:39:38 +01:00
|
|
|
("PHP" "php" xpm)
|
|
|
|
("Python" "python" xpm)
|
2015-12-23 10:56:44 +01:00
|
|
|
("Ruby" "ruby" xpm)
|
2015-12-23 11:20:22 +01:00
|
|
|
("SCSS" "sass" xpm)
|
2015-12-24 06:39:38 +01:00
|
|
|
("Sass" "sass" xpm)
|
|
|
|
("Scheme" "scheme" xpm)
|
|
|
|
("Shell-script" "bash" xpm)
|
|
|
|
("Slim" "slim" xpm)
|
2016-01-14 09:21:22 +01:00
|
|
|
("Web" "html" xpm)
|
|
|
|
("XML" "xml" xpm)
|
2015-12-23 10:56:44 +01:00
|
|
|
("YAML" "yaml" xpm)
|
2015-12-24 06:39:38 +01:00
|
|
|
("YASnippet" "yas" xpm)
|
|
|
|
)
|
2013-06-02 13:56:07 +02:00
|
|
|
"Icons for major 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)
|
|
|
|
"Get the value for the display property of ICON having TYPE.
|
|
|
|
|
|
|
|
ICON should be a string naming the file of the icon, without its
|
|
|
|
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)))
|
|
|
|
|
|
|
|
(defun 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))))
|
|
|
|
|
|
|
|
(defun 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-name)))
|
2012-11-10 23:12:36 +01:00
|
|
|
|
|
|
|
(defun set-mode-icon (mode)
|
2013-06-02 13:56:07 +02:00
|
|
|
"Set the icon for MODE."
|
|
|
|
(setq mode-name (get-mode-icon mode)))
|
2012-11-10 23:12:36 +01:00
|
|
|
|
|
|
|
(defun set-current-mode-icon ()
|
2013-06-02 13:56:07 +02:00
|
|
|
"Set the icon for the current major mode."
|
2012-11-10 23:12:36 +01:00
|
|
|
(set-mode-icon mode-name))
|
|
|
|
|
2013-06-02 14:27:32 +02:00
|
|
|
;;;###autoload
|
2013-06-02 14:09:49 +02:00
|
|
|
(define-minor-mode mode-icons-mode
|
|
|
|
"Replace the name of the current major mode with an icon."
|
|
|
|
:global t
|
|
|
|
(if mode-icons-mode
|
2013-06-02 14:29:47 +02:00
|
|
|
(progn
|
|
|
|
(add-hook 'after-change-major-mode-hook 'set-current-mode-icon)
|
|
|
|
(set-current-mode-icon))
|
2013-06-02 14:09:49 +02:00
|
|
|
(remove-hook 'after-change-major-mode-hook 'set-current-mode-icon)))
|
|
|
|
|
2012-11-10 23:12:36 +01:00
|
|
|
(provide 'mode-icons)
|
|
|
|
;;; mode-icons.el ends here
|