about summary refs log tree commit diff stats
path: root/.emacs.d
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d')
-rw-r--r--.emacs.d/lisp/init-project.el24
1 files changed, 24 insertions, 0 deletions
diff --git a/.emacs.d/lisp/init-project.el b/.emacs.d/lisp/init-project.el
index fcc0e09..be90d8e 100644
--- a/.emacs.d/lisp/init-project.el
+++ b/.emacs.d/lisp/init-project.el
@@ -64,6 +64,28 @@
   ;; Don't restart persp-mode when re-evaluating, as it clears the current persp list
   :init (or persp-mode (persp-mode))
   :config
+  ;; Based on jao-buffer-same-mode (https://jao.io/blog/2021-09-08-high-signal-to-noise-emacs-command.html)
+  (defun persp-switch-buffer-same-mode ()
+    "Switch to a buffer with the same major mode as the current buffer, respecting the current perspective."
+    (interactive)
+    (let* ((mode major-mode)
+           (pred (lambda (b)
+                   (let ((b (get-buffer (if (consp b) (car b) b))))
+                     (eq (buffer-local-value 'major-mode b) mode)))))
+      (pop-to-buffer (persp-read-buffer "Buffer: " nil t pred))))
+  (defun persp-previous-buffer-same-mode ()
+    "Switch to the previous buffer in the current perspective, with the same major mode as the current buffer (or do nothing)"
+    (interactive)
+    (let* ((persp-buffers (seq-filter 'persp-is-current-buffer (buffer-list)))
+           (mode major-mode)
+           (mode-pred (lambda (b)
+                        (let ((b (get-buffer (if (consp b) (car b) b))))
+                          (and (eq (buffer-local-value 'major-mode b) mode)
+                               (not (eq b (current-buffer)))
+                               (not (get-buffer-window b))))))
+           (persp-buffers-in-mode (seq-filter mode-pred persp-buffers)))
+      (when (not (seq-empty-p persp-buffers-in-mode))
+        (switch-to-buffer (car persp-buffers-in-mode)))))
   (defun switch-project (proj)
     "Switch to project or already open project perspective."
     (interactive (list (project-prompt-project-dir)))
@@ -77,6 +99,8 @@
           (project-switch-project proj)))))
   :bind
   ("C-x p p" . switch-project)
+  ("C-x C-b" . persp-previous-buffer-same-mode)
+  ("C-x C-S-b" . persp-switch-buffer-same-mode)
   ("C-x x x" . persp-switch-last)
   ("C-x x ." . persp-switch-quick))
 
7ce25cfe42c363259705a6b5741ad47484ab'>beea7ce2 ^
3e1349d2 ^
4690ce81 ^
a654e4ec ^

3e1349d2 ^
a654e4ec ^
3e1349d2 ^
70f4e9b6 ^
76755b28 ^

a654e4ec ^





76755b28 ^

a654e4ec ^
76755b28 ^



44c1aeef ^




0ca56ed8 ^


76755b28 ^
2f02189d ^
76755b28 ^
3e1349d2 ^
76755b28 ^

a654e4ec ^
76755b28 ^
44c1aeef ^
dcc060c7 ^
44c1aeef ^

76755b28 ^


44c1aeef ^
0ca56ed8 ^
76755b28 ^
4690ce81 ^
76755b28 ^


4690ce81 ^
76755b28 ^





67db19a0 ^
4690ce81 ^

76755b28 ^


4690ce81 ^
beea7ce2 ^






76755b28 ^




44c1aeef ^
67db19a0 ^
44c1aeef ^


beea7ce2 ^
76755b28 ^
beea7ce2 ^









76755b28 ^


44c1aeef ^
133a4614 ^
87196c34 ^
44c1aeef ^


87196c34 ^
44c1aeef ^






76755b28 ^




3e1349d2 ^
76755b28 ^


3e1349d2 ^
76755b28 ^
3e1349d2 ^
76755b28 ^
a654e4ec ^
87196c34 ^
133a4614 ^





87196c34 ^




76755b28 ^


a654e4ec ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160