aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgcv <gepardcv@gmail.com>2026-02-03 05:41:43 -0800
committerGitHub <noreply@github.com>2026-02-03 05:41:43 -0800
commit1dbbb4149a407e435bbb99abf19369c5b14cc23d (patch)
tree442818614dfb75c144552f3e312de9b111ca40a1
parent3148471470e21435939adac19116dfee225a9871 (diff)
parent5d631eccd79c782af689ad771c7c5e9f9ee0861c (diff)
Merge pull request #224 from ispringle/master
feat: add the 'oldest sort method to sort by creation day, ascending
-rw-r--r--README.md10
-rw-r--r--perspective.el24
-rw-r--r--test/test-perspective.el37
3 files changed, 48 insertions, 23 deletions
diff --git a/README.md b/README.md
index 6cbfb76..f1ed6a1 100644
--- a/README.md
+++ b/README.md
@@ -82,7 +82,7 @@ When you finish looking at Z, you close perspective `feature-Z`, and return to
Y, you close perspective `bugfix-Y` and return to `feature-X`.
(Hint: this workflow works best with the `persp-sort` variable set to `'created`
-— see documentation below.)
+or `'oldest` — see documentation below.)
### Perspective Merging
@@ -245,7 +245,7 @@ The actual command keys (the ones pressed after the prefix) are defined in
- `s` — `persp-switch`: Query a perspective to switch to, or create
- `` ` `` — `persp-switch-by-number`: Switch to perspective by number, or switch
quickly using numbers `1, 2, 3.. 0` as prefix args; note this will probably be
- most useful with `persp-sort` set to `'created`
+ most useful with `persp-sort` set to `'created` or `'oldest`
- `k` — `persp-remove-buffer`: Query a buffer to remove from current perspective
- `c` — `persp-kill` : Query a perspective to kill
- `r` — `persp-rename`: Rename current perspective
@@ -425,9 +425,11 @@ customize`). The following are likely to be of most interest:
- `persp-sort`: Select the order in which to sort perspectives when calling
`persp-switch`. Defaults to `'name` (alphabetical), but `'access` (by most
- recently accessed) and `'created` (by order created) are available. Note that
+ recently accessed), `'created` (by order created, descending) and `'oldest`
+ (by order created, ascending) are available. Note that
`persp-switch-by-number` is likely to be confusing when this is set to
- `'access`, as the numbers associated with a perspective will change all the time.
+ `'access`, as the numbers associated with a perspective will change all the
+ time.
- `persp-interactive-completion-function`: Used for prompting for a perspective
name. `completing-read` is the default, with `ido-completing-read` enabled
with `ido-mode`. `ivy-completing-read` is broadly compatible, but
diff --git a/perspective.el b/perspective.el
index a0f0427..811b38c 100644
--- a/perspective.el
+++ b/perspective.el
@@ -99,11 +99,13 @@ instead of the full perspective list."
"What order to sort perspectives.
If 'name, then sort alphabetically.
If 'access, then sort by last time accessed (latest first).
-If 'created, then sort by time created (latest first)."
+If 'created, then sort by time created (latest first).
+If 'oldest, then sort by time created (oldest first)"
:group 'perspective-mode
:type '(choice (const :tag "By Name" name)
(const :tag "By Time Accessed" access)
- (const :tag "By Time Created" created)))
+ (const :tag "By Time Created (descending)" created)
+ (const :tag "By Time Created (ascending)" oldest)))
(defcustom persp-frame-global-perspective-name "GLOBAL"
"The name for a frames global perspective."
@@ -584,11 +586,12 @@ perspective-local variables to `persp-curr'"
"Return a list of the names of all perspectives on the `selected-frame'.
If `persp-sort' is 'name (the default), then return them sorted
-alphabetically. If `persp-sort' is 'access, then return them
-sorted by the last time the perspective was switched to, the
-current perspective being the first. If `persp-sort' is 'created,
-then return them in the order they were created, with the newest
-first."
+alphabetically. If `persp-sort' is 'access, then return them sorted by
+the last time the perspective was switched to, the current perspective
+being the first. If `persp-sort' is 'created, then return them in the
+order they were created, with the newest first. If `persp-sort' is
+'oldest, then return them in the order they were created, with the
+oldest first."
(let ((persps (hash-table-values (perspectives-hash))))
(cond ((eq persp-sort 'name)
(sort (mapcar 'persp-name persps) 'string<))
@@ -601,7 +604,12 @@ first."
(mapcar 'persp-name
(sort persps (lambda (a b)
(time-less-p (persp-created-time b)
- (persp-created-time a)))))))))
+ (persp-created-time a))))))
+ ((eq persp-sort 'oldest)
+ (mapcar 'persp-name
+ (sort persps (lambda (a b)
+ (time-less-p (persp-created-time a)
+ (persp-created-time b)))))))))
(defun persp-all-names (&optional not-frame)
"Return a list of the perspective names for all frames.
diff --git a/test/test-perspective.el b/test/test-perspective.el
index 5f521de..20fd38c 100644
--- a/test/test-perspective.el
+++ b/test/test-perspective.el
@@ -2229,17 +2229,32 @@ persp-test-make-sample-environment."
(ert-deftest issue-90-persp-last--vs--persp-find-some ()
(persp-test-with-persp
- (let ((persp-sort 'created)) ; this should be respected when killing
- (should-persp-equal '("main") "main" nil "main")
- (with-named-persp "A"
- (should-persp-equal '("A" "main") "A" "main" "main")
- (with-named-persp "B"
- (should-persp-equal '("B" "A" "main") "B" "A" "A")
- (with-named-persp "C"
- (should-persp-equal '("C" "B" "A" "main") "C" "B" "B")) ; pop C
- (should-persp-equal '("B" "A" "main") "B" nil "B")) ; pop B
- (should-persp-equal '("A" "main") "A" nil "A")) ; pop A
- (should-persp-equal '("main") "main" nil "main"))))
+ (let ((persp-sort 'created)) ; this should be respected when killing
+ (should-persp-equal '("main") "main" nil "main")
+ (with-named-persp "A"
+ (should-persp-equal '("A" "main") "A" "main" "main")
+ (with-named-persp "B"
+ (should-persp-equal '("B" "A" "main") "B" "A" "A")
+ (with-named-persp "C"
+ (should-persp-equal '("C" "B" "A" "main") "C" "B" "B")) ; pop C
+ (should-persp-equal '("B" "A" "main") "B" nil "B")) ; pop B
+ (should-persp-equal '("A" "main") "A" nil "A")) ; pop A
+ (should-persp-equal '("main") "main" nil "main"))))
+
+(ert-deftest sort-by-oldest ()
+ (persp-test-with-persp
+ (let ((persp-sort 'oldest))
+ ;; persp-order curr last find-some
+ (should-persp-equal '("main") "main" nil "main")
+ (with-named-persp "A"
+ (should-persp-equal '("main" "A") "A" "main" "main")
+ (with-named-persp "B"
+ (should-persp-equal '("main" "A" "B") "B" "A" "A")
+ (with-named-persp "C"
+ (should-persp-equal '("main" "A" "B" "C") "C" "B" "B"))
+ (should-persp-equal '("main" "A" "B") "B" nil "main"))
+ (should-persp-equal '("main" "A") "main" nil "main"))
+ (should-persp-equal '("main") "main" nil "main"))))
(ert-deftest state-save-and-load ()
(unwind-protect