]> git.eshelyaron.com Git - emacs.git/commitdiff
Make 'completion-buffer-name-table/affixation' more robust
authorEshel Yaron <me@eshelyaron.com>
Thu, 4 Apr 2024 09:24:07 +0000 (11:24 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 4 Apr 2024 09:24:07 +0000 (11:24 +0200)
lisp/minibuffer.el

index 005a5d272ca9a55892321ccf55a0a9674aa862ad..1e308136d8422f69be4e2a53228ddc588559b468 100644 (file)
@@ -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)