Subject: bug#41890: bug#42210: bug#41890: 28.0.50; [PATCH]: Add bindings for project.el

From: Sean Whitton <[email-masked]>
Date: Fri, 24 Jul 2020 08:12:13 -0700

Hello Eli,

On Fri 24 Jul 2020 at 09:01AM +03, Eli Zaretskii wrote:

>> Date: Thu, 23 Jul 2020 19:04:13 -0700
>> Cc: "Basil L. Contovounesios" <[email-masked]>,
>>  "Philip K." <[email-masked]>, [email-masked],
>>  [email-masked]
>>
>> -(defun project-switch-to-buffer ()
>> +(defun project-switch-to-buffer (&optional switching-function)
>>    "Switch to another buffer belonging to the current project.
>>  This function prompts for another buffer, offering as candidates
>>  buffers that belong to the same project as the current buffer.
>>  Two buffers belong to the same project if their project instances,
>> -as reported by `project-current' in each buffer, are identical."
>> +as reported by `project-current' in each buffer, are identical.
>> +
>> +Optional argument SWITCHING-FUNCTION is the function used to
>> +switch the buffer.  It defaults to `switch-to-buffer'."
>>    (interactive)
>
> This interface strikes me as unusual and even unexpected for a command
> that switches to another buffer.  I would expect it to have an API
> similar to that of switch-to-buffer: that it should accept the buffer
> to switch to as an argument, and set up that argument in the
> 'interactive' spec according to the preferences of this command
> (offering buffers in the same project etc.).  The API you propose
> makes it awkward, to say the least, to invoke this command from Lisp.

I added the argument just so I could reuse the code in
project-switch-to-buffer, so a simple alternative for the purposes of my
patch would be to factor that code out into a new
project--select-project-buffer defun.  Then no existing APIs would be
changed.

Would that be sufficient?

> Granted, the original API doesn't allow such invocation, either, but
> as long as we are changing this API, let's try fixing that, okay?

This is a bit tricky actually -- what should the function do if some
Lisp code passes it a buffer which is not part of the current project?
Throw an error?  But then surely the Lisp code would prefer to just
check if the buffer is part of the project itself, and use
switch-to-buffer.

I'd be grateful if you could say more about the sort of Lisp code you
have in mind.  I'm struggling to imagine wanting to call this function
from Lisp except via call-interactively.

-- 
Sean Whitton