From 10e0bd7a17dada1fdc416d8d601f365f9736580e Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Thu, 4 Apr 2024 11:24:07 +0200 Subject: [PATCH] Make 'completion-buffer-name-table/affixation' more robust --- lisp/minibuffer.el | 71 +++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 005a5d272ca..1e308136d84 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -4238,39 +4238,42 @@ See `read-file-name' for the meaning of the arguments." (mapcar #'symbol-name (mapcar (apply-partially #'buffer-local-value 'major-mode) - (mapcar #'get-buffer names)))))))) + (delete nil (mapcar #'get-buffer names))))))))) (mapcar (lambda (name) - (let* ((buf (get-buffer name)) - (mode (capitalize - (string-replace - "-mode" "" - (symbol-name (buffer-local-value 'major-mode buf)))))) - (list name - (concat (if (and (buffer-modified-p buf) - (buffer-file-name buf)) - (propertize "*" 'face 'completions-annotations) " ") - " ") - (propertize - (concat (make-string (- (+ max-name 2) - (string-width name)) - ?\s) - mode - (if-let ((file-name (buffer-file-name buf))) - (concat - (make-string (- (+ max-mode 2) - (string-width mode)) - ?\s) - file-name) - (when-let ((proc (get-buffer-process buf))) - (concat - (make-string (- (+ max-mode 2) - (string-width mode)) - ?\s) - (format "%s (%s)" - (process-name proc) - (process-status proc)))))) - 'face 'completions-annotations)))) + (if-let* ((buf (get-buffer name)) + (mode (capitalize + (string-replace + "-mode" "" + (symbol-name (buffer-local-value 'major-mode buf)))))) + (list name + (concat (if (and (buffer-modified-p buf) + (buffer-file-name buf)) + (propertize "*" 'face 'completions-annotations) " ") + " ") + (propertize + (concat (make-string (- (+ max-name 2) + (string-width name)) + ?\s) + mode + (if-let ((file-name (buffer-file-name buf))) + (concat + (make-string (- (+ max-mode 2) + (string-width mode)) + ?\s) + file-name) + (when-let ((proc (get-buffer-process buf))) + (concat + (make-string (- (+ max-mode 2) + (string-width mode)) + ?\s) + (format "%s (%s)" + (process-name proc) + (process-status proc)))))) + 'face 'completions-annotations)) + (list name (concat (propertize "X" 'face 'completions-annotations) + " ") + ""))) names))) (defun completion-buffer-name-normal-predicate (buffer-name) @@ -4288,8 +4291,10 @@ When the value of variable `read-buffer-to-switch-current-buffer' is a buffer, the completion table excludles that buffer from the list of possible completions." (completion-table-with-metadata - (mapcar #'buffer-name - (remove read-buffer-to-switch-current-buffer (buffer-list))) + (completion-table-dynamic + (lambda (&rest _) + (mapcar #'buffer-name + (remove read-buffer-to-switch-current-buffer (buffer-list))))) `((category . buffer) (sort-function . identity) (narrow-completions-function . minibuffer-narrow-buffer-completions) -- 2.39.5