]> git.eshelyaron.com Git - emacs.git/commitdiff
uniquify-get-unique-names: Return a list with propertized strings
authorDmitry Gutov <dmitry@gutov.dev>
Wed, 2 Jul 2025 02:26:51 +0000 (05:26 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 23 Jul 2025 20:12:35 +0000 (22:12 +0200)
* lisp/uniquify.el (uniquify-get-unique-names): Return a list of
strings, and add text property 'uniquify-orig-buffer' to each,
pointing at the corresponding buffers (bug#77312).

* lisp/progmodes/project.el (project--read-project-buffer):
Look up that property's values here and build the alist.

(cherry picked from commit 76877a6b08492c555744cfebda3224df91dec82a)

lisp/progmodes/project.el
lisp/uniquify.el

index 2d57579513db662dc683c424b1b6a621130dc286..738c12a94250e4ae267856e06d512e9f61b23632 100644 (file)
@@ -1512,7 +1512,13 @@ Return non-nil if PROJECT is not a remote project."
                    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))
+              (let* ((unique-names
+                      (mapcar
+                       (lambda (name)
+                         (cons name
+                               (get-text-property 0 'uniquify-orig-buffer
+                                                  (or name ""))))
+                       (uniquify-get-unique-names buffers)))
                      (other-name (when (funcall predicate (cons other-name other-buffer))
                                    (car (rassoc other-buffer unique-names))))
                      (result (completing-read
index 6e25323bf5ad5820ec19c63b88cec77ee6c0987d..4284d6a4feb3cb13735cc3863eb8ba2477a83d25 100644 (file)
@@ -517,10 +517,11 @@ in `uniquify-list-buffers-directory-modes', otherwise returns nil."
   "The current unique name of this buffer in `uniquify-get-unique-names'.")
 
 (defun uniquify-get-unique-names (buffers)
-  "Return an alist with a unique name for each buffer in BUFFERS.
+  "Return a list with unique names for buffers in BUFFERS.
 
 The names are unique only among BUFFERS, and may conflict with other
-buffers not in that list.
+buffers not in that list.  Each string has a text property
+`uniquify-orig-buffer' that stores the corresponding buffer.
 
 This does not rename the buffers or change any state; the unique name is
 only present in the returned alist."
@@ -547,8 +548,15 @@ only present in the returned alist."
          (gethash name buffer-names)))))
   (mapcar (lambda (buf)
             (with-current-buffer buf
-              (prog1 (cons uniquify--stateless-curname buf)
-                (kill-local-variable 'uniquify--stateless-curname))))
+              (let ((name
+                     (if (eq uniquify--stateless-curname
+                             (buffer-name buf))
+                         (copy-sequence uniquify--stateless-curname)
+                       uniquify--stateless-curname)))
+                (when name
+                  (put-text-property 0 1 'uniquify-orig-buffer buf name))
+                (kill-local-variable 'uniquify--stateless-curname)
+                name)))
           buffers))
 
 ;;; Hooks from the rest of Emacs