├── LICENSE ├── README.org ├── helm-icons.el └── images ├── nerd-icons-gui.png ├── nerd-icons-nw.png └── treemacs-icons.gif /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ivan Yonchovski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * helm icons 2 | 3 | [[file:images/treemacs-icons.gif]] 4 | 5 | ** Configuration 6 | *** Melpa (TBD) 7 | *** Manual 8 | By default, the provider uses =treemacs=, so make sure that you have that 9 | in your load path. If you wish to use =all-the-icons= icons instead, set =helm-icons-provider= 10 | to ='all-the-icons=. Or if you wish to use =nerd-icons= icons (which is usable in terminal, 11 | more information [[https://github.com/rainstormstudio/nerd-icons.el][here]]), set =helm-icons-provider= to ='nerd-icons=. 12 | 13 | Make sure that you have =helm= and your icon provider installed, clone the repo 14 | and put it on your path. Make sure that the enable call is performed before 15 | loading =helm=. 16 | 17 | #+BEGIN_SRC emacs-lisp 18 | (helm-icons-enable) 19 | #+END_SRC 20 | 21 | If you use =all-the-icons= and you haven't installed the fonts before, you will be prompted to do so. 22 | 23 | The following are images showing how it looks like when using with =nerd-icons=. Notice that 24 | the second is in konsole. 25 | 26 | [[file:images/nerd-icons-gui.png]] 27 | 28 | [[file:images/nerd-icons-nw.png]] 29 | 30 | ** Supported commands: 31 | - =helm-recentf= 32 | - =helm-mini= 33 | - =helm-find-file= 34 | - =helm-buffers-list= 35 | - =helm-locate= 36 | - =helm-fasd= 37 | - =helm-projectile-*= 38 | -------------------------------------------------------------------------------- /helm-icons.el: -------------------------------------------------------------------------------- 1 | ;;; helm-icons.el --- Helm icons -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2020 Ivan Yonchovski 4 | 5 | ;; Author: Ivan Yonchovski 6 | ;; Contributor: Ellis Kenyő 7 | ;; Keywords: convenience 8 | 9 | ;; Version: 0.1 10 | ;; URL: https://github.com/yyoncho/helm-icons 11 | ;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (f "0.20.0") (treemacs "2.7")) 12 | 13 | ;; This program is free software; you can redistribute it and/or modify 14 | ;; it under the terms of the GNU General Public License as published by 15 | ;; the Free Software Foundation, either version 3 of the License, or 16 | ;; (at your option) any later version. 17 | 18 | ;; This program is distributed in the hope that it will be useful, 19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | ;; GNU General Public License for more details. 22 | 23 | ;; You should have received candidate copy of the GNU General Public License 24 | ;; along with this program. If not, see . 25 | 26 | ;;; Commentary: 27 | 28 | ;; This package plugs icons into `helm' standard functions. 29 | 30 | ;;; Code: 31 | 32 | (require 'dash) 33 | (require 'seq) 34 | (require 'f) 35 | (require 'treemacs-faces nil t) 36 | (require 'treemacs-icons nil t) 37 | (require 'treemacs-themes nil t) 38 | (require 'all-the-icons nil t) 39 | (require 'nerd-icons nil t) 40 | 41 | (defgroup helm-icons nil 42 | "Helm treemacs icons." 43 | :group 'helm) 44 | 45 | (defcustom helm-icons-mode->icon 46 | '((dired-mode . dir-closed) 47 | (emacs-lisp-mode . "el") 48 | (spacemacs-buffer-mode . "el")) 49 | "Lookup Emacs mode -> `treemacs' icon key." 50 | :type '(alist :key-type symbol :value-type sexp)) 51 | 52 | (defcustom helm-icons-provider 53 | 'treemacs 54 | "Provider to load symbols from." 55 | :type '(choice (const all-the-icons) 56 | (const nerd-icons) 57 | (const treemacs)) 58 | :group 'helm) 59 | 60 | (with-eval-after-load 'treemacs-icons 61 | (defun helm-icons--treemacs-icon (file) 62 | "docstring" 63 | (let ((icon (cond 64 | ((symbolp file) file) 65 | ((f-dir? file) 'dir-closed) 66 | ((f-file? file) (f-ext file))))) 67 | (let* ((theme (treemacs--find-theme 68 | (treemacs-theme->name 69 | (treemacs-current-theme)))) 70 | (icons (treemacs-theme->gui-icons theme))) 71 | (ht-get icons icon))))) 72 | 73 | (defun helm-icons--get-icon (file) 74 | "Get icon for FILE." 75 | (cond ((eq helm-icons-provider 'all-the-icons) 76 | (require 'all-the-icons) 77 | (concat 78 | (or (cond ((not (stringp file)) (all-the-icons-octicon "gear")) 79 | ((or 80 | (member (f-base file) '("." "..")) 81 | (f-dir? file)) 82 | (all-the-icons-octicon "file-directory"))) 83 | (all-the-icons-icon-for-file file)) 84 | " ")) 85 | ((eq helm-icons-provider 'nerd-icons) 86 | (require 'nerd-icons) 87 | (concat 88 | (or (cond ((not (stringp file)) (nerd-icons-octicon "nf-oct-gear")) 89 | ((or 90 | (member (f-base file) '("." "..")) 91 | (f-dir? file)) 92 | (nerd-icons-octicon "nf-oct-file_directory"))) 93 | (nerd-icons-icon-for-file file)) 94 | " ")) 95 | ((eq helm-icons-provider 'treemacs) 96 | (helm-icons--treemacs-icon file)))) 97 | 98 | (defun helm-icons--get-icon-for-mode (mode) 99 | "Get icon for mode. First it will use the customized 100 | helm-icons-mode->icon to resolve the icon, otherwise it tries to 101 | use the provider." 102 | (or (-some->> (assoc major-mode helm-icons-mode->icon) 103 | (cl-rest) 104 | helm-icons--get-icon) 105 | (cond ((eq helm-icons-provider 'all-the-icons) 106 | (-let ((icon (all-the-icons-icon-for-mode mode))) 107 | (when (stringp icon) (concat icon " ")))) 108 | ((eq helm-icons-provider 'nerd-icons) 109 | (-let ((icon (nerd-icons-icon-for-mode mode))) 110 | (when (stringp icon) (concat icon " ")))) 111 | (t nil)))) 112 | 113 | (defun helm-icons-buffers-add-icon (candidates _source) 114 | "Add icon to buffers source. 115 | CANDIDATES is the list of candidates." 116 | (-map (-lambda ((display . buffer)) 117 | (cons (concat 118 | (with-current-buffer buffer 119 | (or (helm-icons--get-icon-for-mode major-mode) 120 | (-some->> (buffer-file-name) 121 | helm-icons--get-icon) 122 | (helm-icons--get-icon 'fallback))) 123 | display) 124 | buffer)) 125 | candidates)) 126 | 127 | (defun helm-icons-files-add-icons (candidates _source) 128 | "Add icon to files source. 129 | CANDIDATES is the list of candidates." 130 | (-map (-lambda (candidate) 131 | (-let [(display . file-name) (if (listp candidate) 132 | candidate 133 | (cons candidate candidate))] 134 | (cons (concat (cond 135 | ((helm-icons--get-icon file-name)) 136 | ((helm-icons--get-icon 'fallback))) 137 | display) 138 | file-name))) 139 | candidates)) 140 | 141 | (defun helm-icons-add-transformer (fn source) 142 | "Add FN to `filtered-candidate-transformer' slot of SOURCE." 143 | (setf (alist-get 'filtered-candidate-transformer source) 144 | (-uniq (append 145 | (-let [value (alist-get 'filtered-candidate-transformer source)] 146 | (if (seqp value) value (list value))) 147 | (list fn))))) 148 | 149 | (defun helm-icons--make (orig name class &rest args) 150 | "The advice over `helm-make-source'. 151 | ORIG is the original function. 152 | NAME, CLASS and ARGS are the original params." 153 | (let ((result (apply orig name class args))) 154 | (cl-case class 155 | ((helm-recentf-source helm-source-ffiles helm-locate-source helm-fasd-source helm-ls-git-source) 156 | (helm-icons-add-transformer 157 | #'helm-icons-files-add-icons 158 | result)) 159 | ((helm-source-buffers helm-source-projectile-buffer) 160 | (helm-icons-add-transformer 161 | #'helm-icons-buffers-add-icon 162 | result))) 163 | (cond 164 | ((or (-any? (lambda (source-name) (s-match source-name name)) 165 | '("Projectile files" 166 | "Projectile projects" 167 | "Projectile directories" 168 | "Projectile recent files" 169 | "Projectile files in current Dired buffer" 170 | "dired-do-rename.*" 171 | "Elisp libraries (Scan)"))) 172 | (helm-icons-add-transformer 173 | #'helm-icons-files-add-icons 174 | result))) 175 | result)) 176 | 177 | (defun helm-icons--setup () 178 | "Setup icons based on which provider is set." 179 | (cond ((eq helm-icons-provider 'all-the-icons) 180 | (require 'all-the-icons)) 181 | ((eq helm-icons-provider 'nerd-icons) 182 | (require 'nerd-icons)) 183 | ((eq helm-icons-provider 'treemacs) 184 | (require 'treemacs-themes) 185 | (require 'treemacs-icons)))) 186 | 187 | ;;;###autoload 188 | (defun helm-icons-enable () 189 | "Enable `helm-icons'." 190 | (interactive) 191 | (advice-add 'helm-make-source :around #'helm-icons--make) 192 | (helm-icons--setup)) 193 | 194 | (provide 'helm-icons) 195 | ;;; helm-icons.el ends here 196 | -------------------------------------------------------------------------------- /images/nerd-icons-gui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yyoncho/helm-icons/0d113719ee72cb7b6bb7db29f7200d667bd86607/images/nerd-icons-gui.png -------------------------------------------------------------------------------- /images/nerd-icons-nw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yyoncho/helm-icons/0d113719ee72cb7b6bb7db29f7200d667bd86607/images/nerd-icons-nw.png -------------------------------------------------------------------------------- /images/treemacs-icons.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yyoncho/helm-icons/0d113719ee72cb7b6bb7db29f7200d667bd86607/images/treemacs-icons.gif --------------------------------------------------------------------------------