From be5d0c0f63081b5aee5efe2fbcc5c4ace6ca9a02 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Sat, 20 Jun 2020 04:02:18 +0300 Subject: [PATCH] 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 be1b801ca2b..d35bdf6ce0c 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 () -- 2.39.5