Skip to content

Commit

Permalink
projectile-current-project-on-switch 'keep moves current project to f…
Browse files Browse the repository at this point in the history
…ront
  • Loading branch information
jtamagnan committed Feb 17, 2024
1 parent 0163b33 commit eb33085
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [#1875](https://github.com/bbatsov/projectile/pull/1875): Add support for Sapling VCS.
* [#1876](https://github.com/bbatsov/projectile/pull/1876): Add support for Jujutsu VCS.
* [#1877](https://github.com/bbatsov/projectile/pull/1877): Add custom variable `projectile-cmd-hist-ignoredups`.
* [#1879](https://github.com/bbatsov/projectile/pull/1879): Modify the keep projectile-current-project-on-switch to move the current project to the front.
* Add support for Eask projects.

### Bugs fixed
Expand Down
17 changes: 14 additions & 3 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ position."
:type '(radio
(const :tag "Remove" remove)
(const :tag "Move to end" move-to-end)
(const :tag "Keep" keep)))
(const :tag "Keep" keep)
(const :tag "Move to front" front)))

(defcustom projectile-max-file-buffer-count nil
"Maximum number of file buffers per project that are kept open.
Expand Down Expand Up @@ -5468,20 +5469,30 @@ An open project is a project with any open buffers."
(list (abbreviate-file-name project)))
projects))

(defun projectile--move-current-project-to-front (projects)
"Move current project (if any) to the start of list in the list of PROJECTS."
(if-let ((project (projectile-project-root)))
(append
(list (abbreviate-file-name project))
(projectile--remove-current-project projects))
projects))

(defun projectile-relevant-known-projects ()
"Return a list of known projects."
(pcase projectile-current-project-on-switch
('remove (projectile--remove-current-project projectile-known-projects))
('move-to-end (projectile--move-current-project-to-end projectile-known-projects))
('keep projectile-known-projects)))
('keep projectile-known-projects)
('front (projectile--move-current-project-to-front projectile-known-projects))))

(defun projectile-relevant-open-projects ()
"Return a list of open projects."
(let ((open-projects (projectile-open-projects)))
(pcase projectile-current-project-on-switch
('remove (projectile--remove-current-project open-projects))
('move-to-end (projectile--move-current-project-to-end open-projects))
('keep open-projects))))
('keep open-projects)
('front (projectile--move-current-project-to-front open-projects)))))

;;;###autoload
(defun projectile-switch-project (&optional arg)
Expand Down
16 changes: 15 additions & 1 deletion test/projectile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,21 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
(spy-on 'projectile-project-root :and-return-value "~/foo/")
(let ((projectile-current-project-on-switch 'keep)
(projectile-known-projects known-projects))
(expect (projectile-relevant-known-projects) :to-equal '("~/foo/" "~/bar/" "~/baz/"))))))
(expect (projectile-relevant-known-projects) :to-equal '("~/foo/" "~/bar/" "~/baz/")))))

(describe "when projectile-current-project-on-switch is 'front; find-file hook not run"
(it "returns projectile-known-projects"
(spy-on 'projectile-project-root :and-return-value "~/qux/")
(let ((projectile-current-project-on-switch 'front)
(projectile-known-projects known-projects))
(expect (projectile-relevant-known-projects) :to-equal '("~/qux/" "~/foo/" "~/bar/" "~/baz/")))))

(describe "when projectile-current-project-on-switch is 'front"
(it "returns projectile-known-projects"
(spy-on 'projectile-project-root :and-return-value "~/bar/")
(let ((projectile-current-project-on-switch 'front)
(projectile-known-projects known-projects))
(expect (projectile-relevant-known-projects) :to-equal '("~/bar/" "~/foo/" "~/baz/"))))))

(describe "projectile-relevant-open-projects"
(describe "when projectile-current-project-on-switch is 'remove"
Expand Down

0 comments on commit eb33085

Please sign in to comment.