emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master be5d0c0: project-shell: Pop to an existing shell buffer by defaul


From: Dmitry Gutov
Subject: master be5d0c0: project-shell: Pop to an existing shell buffer by default
Date: Fri, 19 Jun 2020 21:02:25 -0400 (EDT)

branch: master
commit be5d0c0f63081b5aee5efe2fbcc5c4ace6ca9a02
Author: Theodor Thornhill <theo@thornhill.no>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    project-shell: Pop to an existing shell buffer by default
    
    * lisp/progmodes/project.el (project-shell):
    Pop to an existing shell buffer by default.
    If there's none, or if universal argument is used, open a subsequent
    shell buffer and jump to it.  Prefix shell buffer name with the base
    name of project root directory. (Bug#41858)
---
 lisp/progmodes/project.el | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index be1b801..d35bdf6 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -715,11 +715,20 @@ PREDICATE, HIST, and DEFAULT have the same meaning as in
 
 ;;;###autoload
 (defun project-shell ()
-  "Start an inferior shell in the current project's root directory."
+  "Start an inferior shell in the current project's root directory.
+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 ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]