Subject: Re: bug#41879: 28.0.50; [Patch]: Add project-switch-to-buffer in project.el

From: Theodor Thornhill <[email-masked]>
Date: Tue, 16 Jun 2020 06:49:01 +0000

Hi!

"Philip K." <[email-masked]> writes:

[...]

> Shouldn't this just be (file-in-directory-p file root), without the
> (when ... t)?
Yes! Thanks a lot :)

Theo

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 218058b195..a61b29abe6 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -753,6 +753,18 @@ project-compile
          (default-directory (project-root pr)))
     (compile command comint)))
 
+;;;###autoload
+(defun project-switch-to-buffer ()
+  "Switch to a buffer in the current project."
+  (interactive)
+  (let ((root (project-root (project-current t))))
+    (switch-to-buffer
+     (read-buffer
+      "Switch-to-buffer: " nil t
+      (lambda (buffer)
+        (when-let ((file (buffer-file-name (cdr buffer))))
+          (file-in-directory-p file root)))))))
+
 
 ;;; Project list