Commit 7a441bca authored by James Nguyen's avatar James Nguyen

Add ability to sort neotree paths with hidden paths last

parent ab9a1559
......@@ -371,6 +371,13 @@ This variable is used in `neo-vc-for-node' when
:type 'boolean
:group 'neotree)
(defcustom neo-filepath-sort-function 'string<
"Function to be called when sorting neotree nodes."
:type '(symbol (const :tag "Normal" string<)
(const :tag "Sort Hidden at Bottom" neo-sort-hidden-last)
(function :tag "Other"))
:group 'neotree)
;; Faces
......@@ -1127,6 +1134,24 @@ Return nil if DIR is not an existing directory."
"Returns true regardless of message value in the argument."
(defun neo-sort-hidden-last (x y)
"Sort normally but with hidden files last."
(let ((x-hidden (neo-filepath-hidden-p x))
(y-hidden (neo-filepath-hidden-p y)))
((and x-hidden (not y-hidden))
((and (not x-hidden) y-hidden)
(string< x y)))))
(defun neo-filepath-hidden-p (node)
"Return whether or not node is a hidden path."
(let ((shortname (neo-path--file-short-name node)))
(lambda (x) (not (null (string-match-p x shortname))))
;; Buffer methods
......@@ -1355,8 +1380,7 @@ PATH is value."
(defun neo-buffer--get-nodes (path)
(let* ((nodes (neo-util--walk-dir path))
(comp #'(lambda (x y)
(string< x y)))
(comp neo-filepath-sort-function)
(nodes (neo-util--filter 'neo-util--hidden-path-filter nodes)))
(cons (sort (neo-util--filter 'file-directory-p nodes) comp)
(sort (neo-util--filter #'(lambda (f) (not (file-directory-p f))) nodes) comp))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment