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).
This commit is contained in:
Dmitry Gutov 2023-04-22 02:27:22 +03:00
parent 42def8422f
commit 4f3dae2b0d

View file

@ -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)