-
Notifications
You must be signed in to change notification settings - Fork 177
Neotree
This patch is no longer needed, all-the-icons
is now supported by NeoTree
on its own. Just install both packages and then set your NeoTree
theme to 'icons
This page contains a couple of patches that you can use to get File Icons alongside your Neotree file tree. The same idea can be applied to other file tree viewers, I just happen to use Neotree.
N.B I plan on supplying a patch in the future to the author of
Neotree to include all-the-icons
with file icons as a 'theme'
In order to get Neotree to show file icons, you will have to override the functions which insert the fold symbols. These functions change based on the 'theme' you choose when customising Neotree.
This means that applying this patch will ignore whatever theme you previously selected, however, that's the point so that shouldn't be a surprised!
(defun neo-buffer--insert-fold-symbol (name &optional file-name)
"Custom overriding function for the fold symbol.
`NAME' decides what fold icon to use, while `FILE-NAME' decides
what file icon to use."
(or (and (equal name 'open) (insert (all-the-icons-icon-for-dir file-name "down")))
(and (equal name 'close) (insert (all-the-icons-icon-for-dir file-name "right")))
(and (equal name 'leaf) (insert (format "\t\t\t%s\t" (all-the-icons-icon-for-file file-name))))))
This is the function which actually inserts the icon, the reason you
have to patch the original function is because you need the
file-name
to be passed into all-the-icons-icon-for-file
, which
isn't done by default. Otherwise, you could achieve the same result
using
advice.
(defun neo-buffer--insert-dir-entry (node depth expanded)
(let ((node-short-name (neo-path--file-short-name node)))
(insert-char ?\s (* (- depth 1) 2)) ; indent
(when (memq 'char neo-vc-integration)
(insert-char ?\s 2))
(neo-buffer--insert-fold-symbol
(if expanded 'open 'close) node)
(insert-button (concat node-short-name "/")
'follow-link t
'face neo-dir-link-face
'neo-full-path node
'keymap neotree-dir-button-keymap)
(neo-buffer--node-list-set nil node)
(neo-buffer--newline-and-begin)))
(defun neo-buffer--insert-file-entry (node depth)
(let ((node-short-name (neo-path--file-short-name node))
(vc (when neo-vc-integration (neo-vc-for-node node))))
(insert-char ?\s (* (- depth 1) 2)) ; indent
(when (memq 'char neo-vc-integration)
(insert-char (car vc))
(insert-char ?\s))
(neo-buffer--insert-fold-symbol 'leaf node-short-name)
(insert-button node-short-name
'follow-link t
'face (if (memq 'face neo-vc-integration)
(cdr vc)
neo-file-link-face)
'neo-full-path node
'keymap neotree-file-button-keymap)
(neo-buffer--node-list-set nil node)
(neo-buffer--newline-and-begin)))
These two functions are the ones that call
neo-buffer--insert-fold-symbol
, and the patch is just to pass
through the file name (or node
) in both cases.
You want to do one of the following
- Make sure that these patches are applied after Neotree has loaded,
- Edit your local copy of Neotree source file (but that interferes with updates and stuff...).
I use use-package
which
allows you to manage your package dependencies much better! It allows
you define an :after
block to be run once a package is loaded,
i.e.
(use-package neotree
:after
;; Load the above patches
)
Alternatively, you can use with-eval-after-load
to apply the patches
after Neotree. This can be found as a patch file here
By default, all-the-icons
will show the file icons in colour. If you
want to disable this, you can set all-the-icons-color-icons
to nil
(setq all-the-icons-color-icons nil)