From: Dmitry Gutov Date: Fri, 21 Apr 2023 23:27:22 +0000 (+0300) Subject: project--read-project-buffer: Fixup default-directory if needed X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4f3dae2b0d5fc43e5e2effa6d36544b6de2a43d8;p=emacs.git project--read-project-buffer: Fixup default-directory if needed * lisp/progmodes/project.el (project--read-project-buffer): Make sure that when the read buffer is new, its default-directory belongs to the project (bug#62974). --- diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 04c67710d71..7c51778d5d4 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1327,13 +1327,23 @@ general form of conditions." (and (memq (cdr buffer) buffers) (not (project--buffer-check - (cdr buffer) project-ignore-buffer-conditions)))))) - (read-buffer - "Switch to buffer: " - (when (funcall predicate (cons other-name other-buffer)) - other-name) - nil - predicate))) + (cdr buffer) project-ignore-buffer-conditions))))) + (buffer (read-buffer + "Switch to buffer: " + (when (funcall predicate (cons other-name other-buffer)) + other-name) + nil + predicate))) + ;; XXX: This check hardcodes the default buffer-belonging relation + ;; which `project-buffers' is allowed to override. Straighten + ;; this up sometime later. Or not. Since we can add a method + ;; `project-contains-buffer-p', but a separate method to create a + ;; new project buffer seems too much. + (if (or (get-buffer buffer) + (file-in-directory-p default-directory (project-root pr))) + buffer + (let ((default-directory (project-root pr))) + (get-buffer-create buffer))))) ;;;###autoload (defun project-switch-to-buffer (buffer-or-name)