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