]> git.eshelyaron.com Git - emacs.git/commitdiff
project-switch-to-buffer: Don't filter based on default-directory
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 5 Jul 2020 00:35:00 +0000 (03:35 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 5 Jul 2020 21:51:24 +0000 (00:51 +0300)
* lisp/progmodes/project.el (project-switch-to-buffer):
Don't filter based on default-directory
(https://lists.gnu.org/archive/html/emacs-devel/2020-07/msg00075.html).
(project-switch-to-buffer): Ditto.

lisp/progmodes/project.el

index 0a15939d243718936de06e1bb71f960c8fdfb75a..03f7c995e8508f762cc3e523cdb50072da66b18f 100644 (file)
@@ -800,10 +800,10 @@ Arguments the same as in `compile'."
 ;;;###autoload
 (defun project-switch-to-buffer ()
   "Switch to another buffer that is related to the current project.
-A buffer is related to a project if its `default-directory'
-is inside the directory hierarchy of the project's root."
+A buffer is related to a project if `project-current' returns the
+same (equal) value when called in that buffer."
   (interactive)
-  (let* ((root (project-root (project-current t)))
+  (let* ((pr (project-current t))
          (current-buffer (current-buffer))
          (other-buffer (other-buffer current-buffer))
          (other-name (buffer-name other-buffer))
@@ -811,10 +811,9 @@ is inside the directory hierarchy of the project's root."
           (lambda (buffer)
             ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
             (and (cdr buffer)
-                 (not (eq (cdr buffer) current-buffer))
-                 (when-let ((file (buffer-local-value 'default-directory
-                                                      (cdr buffer))))
-                   (file-in-directory-p file root))))))
+                 (equal pr
+                        (with-current-buffer (cdr buffer)
+                          (project-current)))))))
     (switch-to-buffer
      (read-buffer
       "Switch to buffer: "
@@ -836,13 +835,12 @@ any of the conditions will not be killed."
 
 (defun project--buffer-list (pr)
   "Return the list of all buffers in project PR."
-  (let ((root (project-root pr))
-        bufs)
+  (let (bufs)
     (dolist (buf (buffer-list))
-      (let ((filename (or (buffer-file-name buf)
-                          (buffer-local-value 'default-directory buf))))
-        (when (and filename (file-in-directory-p filename root))
-          (push buf bufs))))
+      (when (equal pr
+                   (with-current-buffer buf
+                     (project-current)))
+        (push buf bufs)))
     (nreverse bufs)))
 
 ;;;###autoload