Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### New features

* Add `related-files-fn` option to use custom function to find test/impl/other files.
* Add `path-length` and `custom-method` files sorting options
* Add `related-files-fn` option to use custom function to find test/impl/other files
* [#1019](https://github.com/bbatsov/projectile/issues/1019): Jump to a test named the same way but in a different directory.
* [#982](https://github.com/bbatsov/projectile/issues/982): Add heuristic for projectile-find-matching-test.
* Support a list of functions for `related-files-fn` options and helper functions.
Expand Down
16 changes: 16 additions & 0 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ To sort files by <a href="https://en.wikipedia.org/wiki/MAC_times#Access_time_(a
(setq projectile-sort-order 'access-time)
```

To sort files by the length of the file path:

```el
(setq projectile-sort-order path-length)
```

To sort files by a user-defined method:

```el
;; passed to PREDICATE of cl-sort
(defun my-custom-sort-method (file1 file2)
(< (length file1) (length file2)))

(setq projectile-sort-custom-method 'my-custom-sort-method)
(setq projectile-sort-order custom-method)
```

## Caching

Expand Down
32 changes: 30 additions & 2 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,16 @@ is set to 'alien'."
(const :tag "Recently opened files" recentf)
(const :tag "Recently active buffers, then recently opened files" recently-active)
(const :tag "Access time (atime)" access-time)
(const :tag "Modification time (mtime)" modification-time)))
(const :tag "Modification time (mtime)" modification-time)
(const :tag "Path length" path-length)
(const :tag "Custom method" custom-method)))

(defcustom projectile-sort-custom-method nil
"The sort method to use for custom sorting.

This should be the name of a predicate method usable by `cl-sort'"
:group 'projectile
:type 'symbol)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add a package-version property here saying 2.1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did 2.1.0, since the others were all 3 digit


(defcustom projectile-verbose t
"Echo messages that are not errors."
Expand Down Expand Up @@ -2173,7 +2182,9 @@ With a prefix arg INVALIDATE-CACHE invalidates the cache first."
(recentf (projectile-sort-by-recentf-first files))
(recently-active (projectile-sort-by-recently-active-first files))
(modification-time (projectile-sort-by-modification-time files))
(access-time (projectile-sort-by-access-time files))))
(access-time (projectile-sort-by-access-time files))
(path-length (projectile-sort-by-path-length files))
(custom-method (projectile-sort-by-custom-method files))))

(defun projectile-sort-by-recentf-first (files)
"Sort FILES by a recent first scheme."
Expand Down Expand Up @@ -2207,6 +2218,23 @@ With a prefix arg INVALIDATE-CACHE invalidates the cache first."
(file2-atime (nth 4 (file-attributes file2))))
(not (time-less-p file1-atime file2-atime)))))))

(defun projectile-sort-by-path-length (files)
"Sort FILES by path length."
(let ((default-directory (projectile-project-root)))
(cl-sort
(copy-sequence files)
(lambda (file1 file2)
(let ((path-len1 (length file1))
(path-len2 (length file2)))
(< path-len1 path-len2))))))

(defun projectile-sort-by-custom-method (files)
"Sort FILES by custom method."
(let ((default-directory (projectile-project-root)))
(cl-sort
(copy-sequence files)
projectile-sort-custom-method)))


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