Subject: bug#79126: vc-switch-working-tree does not work if there is no matching file

From: Eshel Yaron <[email-masked]>
Date: Thu, 07 Aug 2025 07:51:26 +0200

Sean Whitton <[email-masked]> writes:
>
> On Wed 06 Aug 2025 at 06:15pm +02, Eshel Yaron wrote:
>>
>> Sean Whitton <[email-masked]> writes:
>>>
>>> * lisp/progmodes/project.el (dired-current-directory): Declare.
>>> (project-find-matching-file): Handle Dired buffers (bug#79126).
>>
>> Any good reason to special-case Dired?  Wouldn't it be nicer to have
>> Dired set project-find-matching-buffer-function appropriately, as I do
>> in my implementation with vc-switch-working-tree-function? :)
>
> Heh.  I tried that first, but found myself duplicating code, so decided
> that folding it into project-find-matching-file was neatest.

I see.  Note that if you stumbled upon such need to duplicate code,
others trying to use this variable to support additional buffers (say,
Shell buffers) will likely have similar difficulties.  In other words,
it's an indication that the extension mechanism could be more convenient
or could benefit from some helper function(s) to avoid duplication.

>>> +                               (dirp (dired-current-directory))
>>
>> I don't think dired-current-directory is the right choice here.  It does
>> the wrong thing when point is in a subdir added with 'i' (it gives you
>> the subdir, not the dir of the current buffer).
>
> This was deliberate.  To me it seems desirable to look for the matching
> subdirectory.  Sounds like you disagree?

It's nothing crucial, but IMO getting a different result depending on
the position of point in the Dired buffer is slightly non-intuitive.
Few will probably experience this difference in practice, so it doesn't
matter to much either way.

Best,

Eshel