]> git.eshelyaron.com Git - emacs.git/commitdiff
project--read-project-buffer: Fixup default-directory if needed
authorDmitry Gutov <dmitry@gutov.dev>
Fri, 21 Apr 2023 23:27:22 +0000 (02:27 +0300)
committerDmitry Gutov <dmitry@gutov.dev>
Fri, 21 Apr 2023 23:27:34 +0000 (02:27 +0300)
* 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).

lisp/progmodes/project.el

index 04c67710d712002ab78bd0c463c562827d8c4039..7c51778d5d4fc1f8c3c4ed9727accd240619c71c 100644 (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)