about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-08-26T22·45+0300
committertazjin <tazjin@tvl.su>2023-08-26T23·30+0000
commit184020a6f2dde1458791124689829c6f1355ad18 (patch)
tree74f85de8ca569479937665665f134f614eefe7d6
parente78b79c6cd30098b45a8ac24f9e8af9d2962b0ad (diff)
feat(tazjin/emacs): annotate remote files in reliably-switch-buffer r/6527
Change-Id: I0fa460f2d455114ca9387ad23d5a72bcb5a5d9ea
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9156
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
-rw-r--r--users/tazjin/emacs/config/functions.el18
1 files changed, 15 insertions, 3 deletions
diff --git a/users/tazjin/emacs/config/functions.el b/users/tazjin/emacs/config/functions.el
index 02ccab87d1c8..a5f109f4b5a6 100644
--- a/users/tazjin/emacs/config/functions.el
+++ b/users/tazjin/emacs/config/functions.el
@@ -306,14 +306,26 @@ by looking for a `Cargo.toml' file."
 situation where the buffer was renamed during selection and an
 empty new buffer is created.
 
-This is done by, in contrast to functions like
-`ivy-switch-buffer', retaining a list of the buffer objects and
-their associated names."
+This is done by, in contrast to most buffer-switching functions,
+retaining a list of the buffer *objects* and their associated
+names, instead of only their names (which might change)."
 
   (interactive)
   (let* ((buffers (seq-map (lambda (b) (cons (buffer-name b) b))
                            (seq-filter (lambda (b) (not (string-prefix-p " " (buffer-name b))))
                                        (buffer-list))))
+
+         ;; Annotate buffers that display remote files. I frequently
+         ;; want to see it, because I might have identically named
+         ;; files open locally and remotely at the same time, and it
+         ;; helps with differentiating them.
+         (completion-extra-properties
+          '(:annotation-function
+            (lambda (name)
+              (if-let* ((file (buffer-file-name (cdr (assoc name buffers))))
+                        (remote (file-remote-p file)))
+                  (format " [%s]" remote)))))
+
          (name (completing-read "Switch to buffer: " (seq-map #'car buffers)))
          (selected (or (cdr (assoc name buffers))
                        ;; Allow users to manually select invisible buffers ...