summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-05-21 18:32:29 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-05-22 14:34:50 -0700
commit99a82ac8f0bbc149e6df738c8d41d4ebfe17775c (patch)
tree691aaa3dcf2f4829f3796326114973729d4390db
parent7c20cb4bd535707ffac3505a059230e7a45f4a24 (diff)
downloaddotfiles-99a82ac8f0bbc149e6df738c8d41d4ebfe17775c.tar.gz
restore commands for switching to a buffer with a given major mode
-rw-r--r--.emacs.d/init.el84
1 files changed, 39 insertions, 45 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 3123dc91..505e06d4 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -893,9 +893,11 @@ layout (which I use by default)."
;; `display-buffer-fallback-action' is a constant so cons once in advance.
(let ((ac `(,(car display-buffer-fallback-action) (inhibit-same-window . t))))
(defun spw/display-buffer (orig-fun &rest args)
- (if (memq this-command '(display-buffer
- project-display-buffer
- transient-cycles-cmd-display-buffer))
+ (if (memq this-command
+ '(display-buffer
+ project-display-buffer
+ transient-cycles-cmd-display-buffer
+ transient-cycles-cmd-spw/display-recent-major-mode-buffer))
(let ((display-buffer-overriding-action ac))
(apply orig-fun args))
(apply orig-fun args))))
@@ -1124,48 +1126,40 @@ don't consider windows satisfying the predicate EXCLUDE."
(if (> count 0) (tab-bar-history-forward) (tab-bar-history-back))))
:cycle-backwards-key [left] :cycle-forwards-key [right])
-;; For when the buffer's name isn't much help for switching to it, as is often
-;; the case with notmuch buffers. Commented out for now because the transient
-;; cycling appended to C-x b and C-x 4 C-o now includes buffers of the same
-;; major mode after cloned siblings, so I think I can do without these
-;; additional bindings.
-;; (defun spw/read-major-mode-buffer-ring ()
-;; (let ((buffer-lists (make-hash-table)))
-;; (dolist (buffer (buffer-list))
-;; (with-current-buffer buffer
-;; (puthash major-mode
-;; (cons buffer (gethash major-mode buffer-lists))
-;; buffer-lists)))
-;; (let* ((mode (intern (completing-read "Major mode: "
-;; (hash-table-keys buffer-lists)
-;; nil
-;; t)))
-;; (ring (make-ring (length (gethash mode buffer-lists)))))
-;; (dolist (buffer (gethash mode buffer-lists) ring)
-;; (ring-insert ring buffer)))))
-;; (defun spw/switch-to-major-mode-buffer ()
-;; (interactive)
-;; (let ((ring (spw/read-major-mode-buffer-ring)))
-;; (pop-to-buffer-same-window (ring-ref ring 0))
-;; ring))
-;; (defun spw/display-major-mode-buffer ()
-;; (interactive)
-;; (let ((ring (spw/read-major-mode-buffer-ring)))
-;; (cons
-;; (display-buffer (ring-ref ring 0))
-;; ring)))
-;; (spw/bind-command-with-ret-val-cycling
-;; ("\C-cb\C-o" . spw/display-major-mode-buffer)
-;; (spw/buffer-ring-cycle-lambda
-;; (cdr ret-val)
-;; (with-selected-window (car ret-val)
-;; (let ((display-buffer-overriding-action '((display-buffer-same-window)
-;; (inhibit-same-window . nil))))
-;; (display-buffer buffer)))))
-;; (spw/bind-command-with-ret-val-cycling
-;; ("\C-cbb" . spw/switch-to-major-mode-buffer)
-;; (spw/buffer-ring-cycle-lambda
-;; (and (ring-p ret-val) ret-val)))
+;;; For when the buffer's name isn't much help for switching to it, as is
+;;; often the case with `notmuch-show' buffers. We select the most recent
+;;; buffer but then transient cycling can take us to other buffers of the same
+;;; major mode.
+
+(defun spw/read-major-mode-recent-buffer ()
+ (let ((buffers (make-hash-table)))
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (unless (gethash major-mode buffers)
+ (puthash major-mode buffer buffers))))
+ (list
+ (gethash
+ (intern
+ (completing-read
+ "Most recent buffer of major mode: " (hash-table-keys buffers) nil t))
+ buffers))))
+
+(spw/transient-cycles-define-buffer-switch
+ ((("\C-zb" . spw/switch-to-recent-major-mode-buffer) (buffer)
+ (interactive (spw/read-major-mode-recent-buffer))
+ (switch-to-buffer buffer t))
+
+ (("\C-z4b" . spw/switch-to-recent-major-mode-buffer-other-window) (buffer)
+ (interactive (spw/read-major-mode-recent-buffer))
+ (switch-to-buffer-other-window buffer t))
+
+ (("\C-z5b" . spw/switch-to-recent-major-mode-buffer-other-frame) (buffer)
+ (interactive (spw/read-major-mode-recent-buffer))
+ (switch-to-buffer-other-frame buffer t))
+
+ (("\C-z4\C-o" . spw/display-recent-major-mode-buffer) (buffer)
+ (interactive (spw/read-major-mode-recent-buffer))
+ (display-buffer buffer))))
;; filling of comments -- we don't want to set
;; `comment-auto-fill-only-comments' always on because in Org-mode, for