Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions perspective.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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<))
Expand All @@ -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.
Expand Down
37 changes: 26 additions & 11 deletions test/test-perspective.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down