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

From: Theodor Thornhill <[email-masked]>
Date: Tue, 16 Jun 2020 05:45:34 +0000

Thanks alot for your comments!

"Dmitry Gutov" <[email-masked]> writes:

[...]
> The REQUIRE-MATCH argument should be t, I think.
Done.

>  > +      (lambda (buffer)
>  > +        (when-let* ((path (buffer-file-name (cdr buffer)))

[...]

> Call it file or file-name.
Done.

>  > +                    (true (file-truename path)))
>
> Do we need this conversion? It'll add some runtime overhead, and I'm not
> sure in which conditions the result will be different.
I removed it, seems to work fine :).

>  > +          (when (file-in-directory-p true (project-root pr))
>  > +            'buffer)))))))
>
> Why 'buffer and not t?
I just figured it as readable, but t is there now!

Theo

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 218058b195..30d1d5a3dd 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -753,6 +753,19 @@ 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))))
+          (when (file-in-directory-p file root)
+            t)))))))
+
 
 ;;; Project list