Subject: Re: bug#41879: 28.0.50; [Patch]: Add project-switch-to-buffer in project.el

From: Theodor Thornhill <[email-masked]>
Date: Thu, 18 Jun 2020 10:26:05 +0000

On the other hand, what do you think about this one?

Now you will get buffers such as '*xref*' and I assume your inferior buffers as well. Could you try this? I added your 'other-buffer' thing also for good measure :)

Theo

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index e24d81c1b4..e935cae280 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -714,11 +714,20 @@ project-vc-dir
 
 ;;;###autoload
 (defun project-shell ()
-  "Open Shell in the current project."
+  "Open Shell in the current project.
+With \\[universal-argument] prefix, create subsequent shell buffers
+with uniquified names."
   (interactive)
-  (let ((default-directory (project-root (project-current t))))
-    ;; Use ‘create-file-buffer’ to uniquify shell buffer names.
-    (shell (create-file-buffer "*shell*"))))
+  (let* ((default-directory (project-root (project-current t)))
+         (default-project-shell-name
+           (concat "*" (file-name-nondirectory
+                        (directory-file-name
+                         (file-name-directory default-directory)))
+                   "-shell*"))
+         (shell-buffer (get-buffer default-project-shell-name)))
+    (if (and shell-buffer (not current-prefix-arg))
+        (pop-to-buffer shell-buffer)
+      (shell (generate-new-buffer-name default-project-shell-name)))))
 
 ;;;###autoload
 (defun project-eshell ()
@@ -779,10 +788,12 @@ project-switch-to-buffer
   (let ((root (project-root (project-current t))))
     (switch-to-buffer
      (read-buffer
-      "Switch to buffer: " nil t
+      "Switch to buffer: "
+      (buffer-name (other-buffer (current-buffer)))
+      t
       (lambda (buffer)
         ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
-        (when-let ((file (buffer-file-name (cdr buffer))))
+        (when-let ((file (buffer-local-value 'default-directory (cdr buffer))))
           (file-in-directory-p file root)))))))
 
 (defcustom project-kill-buffers-skip-conditions