about summary refs log tree commit diff
path: root/users/tazjin/emacs/config/bindings.el
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-08-23T20·03+0300
committertazjin <tazjin@tvl.su>2023-08-23T20·22+0000
commitdf4a09864af58468c5f54aa19cd90b27910910ce (patch)
tree146615299a644b55d99dc0a901e70111dd6bfa9f /users/tazjin/emacs/config/bindings.el
parent561a9fa45b4fe35809b0bec17147e17c027092ac (diff)
feat(tazjin/emacs): implement reliably-switch-buffer r/6520
Adds a completing-read function (defaulting to ivy for me, but it
doesn't matter) that offers a reliable alternative to standard
buffer-switching implementations.

In particular, this implementation retains a mapping of
buffer names to their buffer *objects*, so that the correct buffer is
selected even if some renaming took place during the selection.

I tried to account for a bunch of the common behaviours I could think
of:

* invisible buffers are ... invisible
* entering a buffer name manually creates that buffer, if there is no
  match
* ... unless that buffer is an invisible buffer, in which case it is
  selected and switched to
* the first element is always `(other-buffer (current-buffer))`,
  because of the ordering of #'buffer-list

Yet, the entire code of my implementation is less than the *setup*
code of ivy-switch-buffers, so it's possible I missed something. Well,
I'll find out ...

Change-Id: I08be0da0863d06c9a930e5efaf916719655db90e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9147
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/tazjin/emacs/config/bindings.el')
-rw-r--r--users/tazjin/emacs/config/bindings.el3
1 files changed, 3 insertions, 0 deletions
diff --git a/users/tazjin/emacs/config/bindings.el b/users/tazjin/emacs/config/bindings.el
index 8564365701..fc33cd1840 100644
--- a/users/tazjin/emacs/config/bindings.el
+++ b/users/tazjin/emacs/config/bindings.el
@@ -1,3 +1,6 @@
+;; Switch buffers reliably in the face of spurious renames.
+(global-set-key (kbd "C-x b") #'reliably-switch-buffer)
+
 ;; Font size
 (define-key global-map (kbd "C-=") 'increase-default-text-scale) ;; '=' because there lies '+'
 (define-key global-map (kbd "C--") 'decrease-default-text-scale)