Skip to content

Commit f06420a

Browse files
committed
add sort by path length & custom method
1 parent 71a01f4 commit f06420a

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

projectile.el

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,16 @@ is set to 'alien'."
251251
(const :tag "Recently opened files" recentf)
252252
(const :tag "Recently active buffers, then recently opened files" recently-active)
253253
(const :tag "Access time (atime)" access-time)
254-
(const :tag "Modification time (mtime)" modification-time)))
254+
(const :tag "Modification time (mtime)" modification-time)
255+
(const :tag "Path length" path-length)
256+
(const :tag "Custom method" custom-method)))
257+
258+
(defcustom projectile-sort-custom-method nil
259+
"The sort method to use for custom sorting
260+
261+
This should be the name of a predicate method usable by `cl-sort'"
262+
:group 'projectile
263+
:type 'symbol)
255264

256265
(defcustom projectile-verbose t
257266
"Echo messages that are not errors."
@@ -2172,7 +2181,9 @@ With a prefix arg INVALIDATE-CACHE invalidates the cache first."
21722181
(recentf (projectile-sort-by-recentf-first files))
21732182
(recently-active (projectile-sort-by-recently-active-first files))
21742183
(modification-time (projectile-sort-by-modification-time files))
2175-
(access-time (projectile-sort-by-access-time files))))
2184+
(access-time (projectile-sort-by-access-time files))
2185+
(path-length (projectile-sort-by-path-length files))
2186+
(custom-method (projectile-sort-by-custom-method files))))
21762187

21772188
(defun projectile-sort-by-recentf-first (files)
21782189
"Sort FILES by a recent first scheme."
@@ -2206,6 +2217,23 @@ With a prefix arg INVALIDATE-CACHE invalidates the cache first."
22062217
(file2-atime (nth 4 (file-attributes file2))))
22072218
(not (time-less-p file1-atime file2-atime)))))))
22082219

2220+
(defun projectile-sort-by-path-length (files)
2221+
"Sort FILES by path length."
2222+
(let ((default-directory (projectile-project-root)))
2223+
(cl-sort
2224+
(copy-sequence files)
2225+
(lambda (file1 file2)
2226+
(let ((path-len1 (length file1))
2227+
(path-len2 (length file2)))
2228+
(< path-len1 path-len2))))))
2229+
2230+
(defun projectile-sort-by-custom-method (files)
2231+
"Sort FILES by custom method."
2232+
(let ((default-directory (projectile-project-root)))
2233+
(cl-sort
2234+
(copy-sequence files)
2235+
projectile-sort-custom-method)))
2236+
22092237

22102238
;;;; Find directory in project functionality
22112239
(defun projectile--find-dir (invalidate-cache &optional dired-variant)

0 commit comments

Comments
 (0)