]> git.eshelyaron.com Git - emacs.git/commitdiff
project-shell: Pop to an existing shell buffer by default
authorTheodor Thornhill <theo@thornhill.no>
Sat, 20 Jun 2020 01:02:18 +0000 (04:02 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 20 Jun 2020 01:02:18 +0000 (04:02 +0300)
* 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

index be1b801ca2b2db63a911eb4a9a880054c994c14c..d35bdf6ce0c81520dcc88ba9f8c7a2c5bf0772eb 100644 (file)
@@ -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 ()