Subject: bug#69606: [PATCH] Ensure default-directory exists when generating diff

From: Philip Kaludercic <[email-masked]>
Date: Wed, 26 Feb 2025 16:49:52 +0000

Juri Linkov <[email-masked]> writes:

>>>>> Is it safe to always use a temporary directory?  I would have expected
>>>>> there to be edge-cases when using TRAMP where that might matter, and we
>>>>> should only fall back if really necessary?
>>>>
>>>> There is no problem wrt temporary-file-directory and Tramp.
>>>
>>> Then we should go with that approach.  Do you want to push the change?
>>
>> I thought you do :-) But no problem, I can do it.
>
> It was completely unexpected surprise that now diff is broken
> since 'C-x C-j' goes into an unrelated directory, but not
> going from the diff buffer to the dired where it was created.
>
> I didn't have the initial problem since using
>
>   (add-hook 'diff-mode-hook 'rename-uniquely)
>
> (I know that this pollutes with temp buffers in org-src-font-lock-fontify-block
> that has ‘(get-buffer-create (format " *org-src-fontification:%s*" lang-mode))’
> because it renames internal buffers, so they can't be reused.  But this is
> not a problem.)
>
> But even with the default settings of reusing the same diff buffer,
> why change the default directory when it exists?  Why not to check
> if the dir still exists like Philip proposed initially?

I have also run into this issue when trying to save a diff buffer, and
it not appearing in the expected place but under /tmp/.