Skip to content

Commit fad3c20

Browse files
gagboalphapapa
andcommitted
Allow multiple workspaces per buffer
- Rename `bufler-workspace-name` to `bufler-workspace-names` to show it can hold multiple values - Add prefix to workspace names in the groups - Make `bufler-workspace-buffer-name-workspace` add to list of buffer-local workspace value instead of replacing it - Use another version of `seq-group-by` in `bufler-group-tree` that adds an element in multiple groups if the grouping function returns a list. For the last point, it would be better to use `cl-defmethod` to override the `seq-group-by` function only when grouping workspaces but currently no version tried work. Last try : ```lisp (cl-defmethod seq-group-by ((function (eql 'bufler-group-auto-workspace)) sequence) "Specialization of `seq-group-by' that puts elements of SEQUENCES in each of the workspaces returned by FUNCTION." (seq-reduce (lambda (acc elt) (let ((keys (funcall function elt)) (add-to-groups (lambda (key) (let ((cell (assoc key acc))) (if cell (setcdr cell (push elt (cdr cell))) (push (list key elt) acc)))))) (mapc add-to-groups keys) acc)) (seq-reverse sequence) nil)) ``` Co-authored-by: Adam Porter <[email protected]>
1 parent 097f434 commit fad3c20

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

bufler-group-tree.el

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,32 @@
4242

4343
;;;; Functions
4444

45+
(defun bufler-group-tree-seq-group-by (function sequence)
46+
"Specialization of `seq-group-by' that puts elements of SEQUENCES in each of
47+
the workspaces returned by FUNCTION."
48+
(seq-reduce
49+
(lambda (acc elt)
50+
(let ((keys (funcall function elt))
51+
(add-to-group (lambda (key)
52+
(let ((cell (assoc key acc)))
53+
(if cell
54+
(setcdr cell (push elt (cdr cell)))
55+
(push (list key elt) acc))))))
56+
(if (listp keys)
57+
(mapc add-to-group keys)
58+
(funcall add-to-group keys))
59+
acc))
60+
(seq-reverse sequence)
61+
nil))
62+
4563
(defun bufler-group-tree (fns sequence)
4664
"Return SEQUENCE grouped according to FNS."
4765
(declare (indent defun))
4866
;; Modeled on grouping from `sbuffer'.
4967
(cl-typecase fns
5068
(function
5169
;; "Regular" subgroups (naming things is hard).
52-
(seq-group-by fns sequence))
70+
(bufler-group-tree-seq-group-by fns sequence))
5371
(list (cl-typecase (car fns)
5472
(function
5573
;; "Regular" subgroups (naming things is hard).
@@ -59,7 +77,7 @@
5977
(cons (car it)
6078
(bufler-group-tree (cdr fns) (cdr it))))
6179
groups))
62-
(seq-group-by (car fns) sequence)))
80+
(bufler-group-tree-seq-group-by (car fns) sequence)))
6381
(list
6482
;; "Recursive sub-subgroups" (naming things is hard).
6583
;; First, separate all the buffers that match the

bufler-workspace.el

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,29 @@ act as if SET-WORKSPACE-P is non-nil."
159159
(bufler-buffer-workspace-path selected-buffer)))
160160
(switch-to-buffer selected-buffer)))
161161

162+
;;;###autoload
163+
(defun bufler-workspace-list-named-workspaces ()
164+
"Return the list of current named workspaces."
165+
(seq-uniq
166+
(cl-loop for buffer in (buffer-list)
167+
when (buffer-local-value 'bufler-workspace-names buffer)
168+
append it)))
169+
162170
;;;###autoload
163171
(defun bufler-workspace-buffer-name-workspace (&optional name)
164172
"Set current buffer's workspace to NAME.
165173
If NAME is nil (interactively, with prefix), unset the buffer's
166-
workspace name. This sets the buffer-local variable
167-
`bufler-workspace-name'. Note that, in order for a buffer to
174+
workspace name. This prepends to the buffer-local variable
175+
`bufler-workspace-names'. Note that, in order for a buffer to
168176
appear in a named workspace, the buffer must be matched by an
169177
`auto-workspace' group before any other group."
170178
(interactive (list (unless current-prefix-arg
171179
(completing-read "Named workspace: "
172-
(seq-uniq
173-
(cl-loop for buffer in (buffer-list)
174-
when (buffer-local-value 'bufler-workspace-name buffer)
175-
collect it))))))
180+
(bufler-workspace-list-named-workspaces)))))
176181
(setf bufler-cache nil)
177-
(setq-local bufler-workspace-name name))
182+
(if (and name (not (string= "" name)))
183+
(add-to-list (make-local-variable 'bufler-workspace-names) name)
184+
(setq-local bufler-workspace-names nil)))
178185

179186
;;;###autoload
180187
(define-minor-mode bufler-workspace-mode

bufler.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ Usually this will be something like \"/usr/share/emacs/VERSION\".")
9797
(defvar bufler-cache nil
9898
"Cache of computed buffer groups.")
9999

100-
(defvar bufler-workspace-name nil
101-
"The buffer's named workspace, if any.")
100+
(defvar bufler-workspace-names nil
101+
"A list of named workspaces owning the buffer, if any.")
102102

103103
(defvar bufler-cache-related-dirs (make-hash-table :test #'equal)
104104
"Cache of relations between directories.
@@ -457,7 +457,7 @@ NAME, okay, `checkdoc'?"
457457

458458
(declare-function bufler-workspace-buffer-name-workspace "bufler-workspace")
459459
(bufler-define-buffer-command name-workspace
460-
"Set buffer's workspace name.
460+
"Adds to buffer's workspace names.
461461
With prefix, unset it."
462462
(lambda (buffer)
463463
(with-current-buffer buffer
@@ -466,7 +466,7 @@ With prefix, unset it."
466466
(completing-read "Named workspace: "
467467
(seq-uniq
468468
(cl-loop for buffer in (buffer-list)
469-
when (buffer-local-value 'bufler-workspace-name buffer)
469+
when (buffer-local-value 'bufler-workspace-names buffer)
470470
collect it)))))))
471471

472472
;;;;; Group commands
@@ -1070,8 +1070,9 @@ NAME, okay, `checkdoc'?"
10701070
(concat "Tramp: " host)))
10711071

10721072
(bufler-defauto-group workspace
1073-
(when-let* ((name (buffer-local-value 'bufler-workspace-name buffer)))
1074-
name))
1073+
(when-let* ((names (buffer-local-value 'bufler-workspace-names buffer)))
1074+
(mapcar (lambda (name) (concat "Workspace: " name)) names)))
1075+
10751076

10761077
;;;;;; Group-defining macro
10771078

0 commit comments

Comments
 (0)