From 184020a6f2dde1458791124689829c6f1355ad18 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 27 Aug 2023 01:45:11 +0300 Subject: feat(tazjin/emacs): annotate remote files in reliably-switch-buffer Change-Id: I0fa460f2d455114ca9387ad23d5a72bcb5a5d9ea Reviewed-on: https://cl.tvl.fyi/c/depot/+/9156 Reviewed-by: tazjin Tested-by: BuildkiteCI --- users/tazjin/emacs/config/functions.el | 18 +++++++++++++++--- 1 file 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 ... -- cgit 1.4.1