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

From: "Basil L. Contovounesios" <[email-masked]>
Date: Tue, 16 Jun 2020 21:37:26 +0100

Theodor Thornhill <[email-masked]> writes:

> Thanks for your keen eye :)

Thanks for all your useful contributions!

>> I'd write something like this:
>>
>>   ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
>>
>
> Got it. I stole your comment - I hope that is OK?

Of course.
In decreasing order of preference: improved > stolen > ignored. ;)

> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index f3df44fa7b..52e8ef4ff9 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -744,6 +744,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)
> +        ;; BUFFER is an entry (BUF-NAME . BUF-OBJ) of Vbuffer_alist.
> +        (when-let ((file (buffer-file-name (cdr buffer))))
> +          (file-in-directory-p file root)))))))

LGTM, thanks.

-- 
Basil