Subject: [PATCH] project.el: Use project-name to calculate prefixed buffer name
From: Spencer Baugh <[email-masked]>
To: [email-masked]
Date: Thu, 30 Mar 2023 14:35:53 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

project.el: Use project-name to calculate prefixed buffer name.  This
makes the name more easily customizable and works better for projects
which don't have a meaningful last directory component.

In GNU Emacs 29.0.60 (build 3, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2023-03-13 built on
 igm-qws-u22796a
Repository revision: e759905d2e0828eac4c8164b09113b40f6899656
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: CentOS Linux 7 (Core)

Configured using:
 'configure --with-x-toolkit=lucid --with-modules
 --with-gif=ifavailable'

From 2141d988d376cfd6a572a86c77346815c45cc686 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <[email-masked]>
Date: Thu, 30 Mar 2023 14:34:29 -0400
Subject: [PATCH] Use project-name to calculate prefixed buffer name

* lisp/progmodes/project.el (project-prefixed-buffer-name):
(project-shell):
(project-eshell):
Use project-name to calculate prefixed buffer name
(project-compilation-buffer-name-function):
Update doc.
---
 lisp/progmodes/project.el | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 11228226592..6d058edf878 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1165,8 +1165,9 @@ project-shell
 if one already exists."
   (interactive)
   (require 'comint)
-  (let* ((default-directory (project-root (project-current t)))
-         (default-project-shell-name (project-prefixed-buffer-name "shell"))
+  (let* ((pr (project-current t))
+         (default-directory (project-root pr))
+         (default-project-shell-name (project-prefixed-buffer-name pr "shell"))
          (shell-buffer (get-buffer default-project-shell-name)))
     (if (and shell-buffer (not current-prefix-arg))
         (if (comint-check-proc shell-buffer)
@@ -1183,8 +1184,9 @@ project-eshell
 if one already exists."
   (interactive)
   (defvar eshell-buffer-name)
-  (let* ((default-directory (project-root (project-current t)))
-         (eshell-buffer-name (project-prefixed-buffer-name "eshell"))
+  (let* ((pr (project-current t))
+         (default-directory (project-root pr))
+         (eshell-buffer-name (project-prefixed-buffer-name pr "eshell"))
          (eshell-buffer (get-buffer eshell-buffer-name)))
     (if (and eshell-buffer (not current-prefix-arg))
         (pop-to-buffer eshell-buffer (bound-and-true-p display-comint-buffer-action))
@@ -1246,10 +1248,9 @@ project-query-replace-regexp
 (defvar compilation-read-command)
 (declare-function compilation-read-command "compile")
 
-(defun project-prefixed-buffer-name (mode)
+(defun project-prefixed-buffer-name (pr mode)
   (concat "*"
-          (file-name-nondirectory
-           (directory-file-name default-directory))
+          (project-name pr)
           "-"
           (downcase mode)
           "*"))
@@ -1261,7 +1262,7 @@ project-compilation-buffer-name-function
   :version "28.1"
   :group 'project
   :type '(choice (const :tag "Default" nil)
-                 (const :tag "Prefixed with root directory name"
+                 (const :tag "Prefixed with project name"
                         project-prefixed-buffer-name)
                  (function :tag "Custom function")))
 
-- 
2.30.2