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

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 08 Aug 2025 10:19:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
79126: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=79126
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#79126: vc-switch-working-tree does not work if there is no matching file
From: Sean Whitton <[email-masked]>
To: Dmitry Gutov <[email-masked]>
Cc: Spencer Baugh <[email-masked]>, Eshel Yaron <[email-masked]>, [email-masked]
Date: Fri, 08 Aug 2025 11:18:45 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

On Fri 08 Aug 2025 at 03:35am +03, Dmitry Gutov wrote:

> On 07/08/2025 15:38, Sean Whitton wrote:
>> Thanks again all.  Here's the revised patch.
>
> Nice! Looking good.
>
>> +;; The default value works for file-visiting and Dired buffers.
>> +;; Non-file-visiting major modes (other than `dired-mode'), where there
>> +;; is a sensible notion of a matching buffer, can set this.
>> +;; File-visiting major modes shouldn't set it, except possibly some
>> +;; highly specialized ones.
>> +(defvar project-find-matching-buffer-function
>> +  #'project-find-matching-file-or-directory
>> +  "Function to switch to a matching buffer in another project.
>> +Usually set buffer-locally by non-file-visiting major modes.
>> +The function will be called with two arguments, the project instance for
>> +this buffer's project, and the project instance for the matching buffer.")
>
> I suggest to try to get more of the info from the comment into the docstring.

Thanks yeah, I think it's fine to just move it all in, as a second
paragraph.

>> +         (dirp (derived-mode-p 'dired-mode))
>
> One more thing to try is not to specialize on Dired mode: and default to
> assuming that any buffer without buffer-file-name is "dirp".

This seems like a useful fallback -- it gets you into a buffer with the
default-directory you wanted, so you could conveniently run some other
command in the right place, even if the dired buffer isn't much use.

> The default implementation would either find/create a Dired buffer in
> the same dir, or even search through the buffer list for a buffer with
> matching values of major-mode and default-directory.

I believe that find-file/dired already handle reusing buffers if they
already exist, so we don't need to search.

Installed and closing the bug.

-- 
Sean Whitton

Subject: vc-switch-working-tree does not work if there is no matching file
From: Dmitry Gutov <[email-masked]>
To: [email-masked]
Date: Wed, 30 Jul 2025 05:36:54 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

X-Debbugs-CC: [email-masked], [email-masked]

Hi!

If the current buffer does not visit a file (such as Dired, mentioned in 
a FIXME comment), or if the current file has no corresponding on the 
other worktree, we end up with an error.

Like

   file-relative-name: Wrong type argument: stringp, nil

or

   File ‘lisp/progmodes/abc.el’ not found in ‘~/vc/emacs-28/’

I guess some of these could be improved in project-find-matching-file 
(support for more major modes?) but semantically it seems like 
vc-switch-working-tree should try harder. Falling back to visiting the 
worktree root in Dired, if it doesn't find a better choice.