]> git.eshelyaron.com Git - emacs.git/commitdiff
project-switch-to-buffer: Don't disambiguate too much
authorDmitry Gutov <dmitry@gutov.dev>
Fri, 6 Jun 2025 02:38:55 +0000 (05:38 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 7 Jun 2025 20:01:30 +0000 (22:01 +0200)
* lisp/progmodes/project.el (project--read-project-buffer):
Use the new function from 'uniquify' to generate buffer names that
are just unique to the current project, not globally (bug#77312).

(cherry picked from commit 1c465fc0879b68b1cd7a05c033f6bb82fd5fa3aa)

lisp/progmodes/project.el

index b551e8b06fb27e4446bf06cf8e7dcc92d1adc63c..61694c3ec6a77043d17d47037d5acf6953845b47 100644 (file)
@@ -1488,13 +1488,28 @@ general form of conditions."
             (and (memq (cdr buffer) buffers)
                  (not
                   (project--buffer-check
-                   (cdr buffer) project-ignore-buffer-conditions)))))
-         (buffer (read-buffer
-                  "Switch to buffer: "
-                  (when (funcall predicate (cons other-name other-buffer))
-                    other-name)
-                  nil
-                  predicate)))
+                   buffer project-ignore-buffer-conditions)))))
+         (buffer
+          (if (and (fboundp 'uniquify-get-unique-names)
+                   uniquify-buffer-name-style)
+              ;; Forgo the use of `buffer-read-function' (often nil) in
+              ;; favor of uniquifying the buffers better.
+              (let* ((unique-names (uniquify-get-unique-names buffers))
+                     (other-name (when (funcall predicate (cons other-name other-buffer))
+                                   (car (rassoc other-buffer unique-names))))
+                     (result (completing-read
+                              "Switch to buffer: "
+                              unique-names
+                              predicate
+                              nil nil nil
+                              other-name)))
+                (assoc-default result unique-names #'equal result))
+            (read-buffer
+             "Switch to buffer: "
+             (when (funcall predicate (cons other-name other-buffer))
+               other-name)
+             nil
+             predicate))))
     ;; XXX: This check hardcodes the default buffer-belonging relation
     ;; which `project-buffers' is allowed to override.  Straighten
     ;; this up sometime later.  Or not.  Since we can add a method