Subject: bug#50499: 28.0.50; project.el: Root of current project

From: Augusto Stoffel <[email-masked]>
Date: Fri, 10 Sep 2021 18:08:52 +0200

On Fri, 10 Sep 2021 at 15:16, Dmitry Gutov <[email-masked]> wrote:

> On 10.09.2021 08:26, Augusto Stoffel wrote:
>> I guess most uses of `project-root' will be of the form
>>      (when-let ((p (project-current)))
>>         (project-root p))
>> Or at least this is true in the case of an user who is quickly
>> defining
>> a shortcut command in their config.
>> Wouldn't it make sense to make the PROJECT argument of
>> `project-root'
>> optional, giving the above result when omitted?
>
> Given the way it this works, it would need to be a helper function.

Okay, introducing a new name is probably not worth the trouble for such
a small benefit.  Only if it was possible/easy to overload the existing
function (and make it analogous the typical “&optional BUFFER” kind of
argument) would there be a gain in it, I think.

>
> IIUC cl-defmethod does not support default values for arguments, and
> if it did, we'd have to have an implementation of project-root, etc,
> for nil argument. Which is a bad idea because someone else might not
> want to simply do nothing when there is no project found, and our type
> system would then fail to help them notice that.
>
> I don't mind adding said helper (naming suggestions welcome), but the
> way things work now seems fine to me already. Either you have:
>
>   (project-root (project-current t))
>
> where there is no risk of returning nil, and thus no need for when-let,
> or you call (project-current) first, check it for nil, and then
> _probably_ use some other fallbacks. If you don't have fallbacks, then
> the other approach seems better, no?