Augusto Stoffel <[email protected]> writes:

> On Tue, 27 Oct 2026, Michael Albinus wrote:
>
>> I don't know magit at all, so it might be dumb what I'm saying. However,
>> there is
>>
>> (defmacro magit--with-temp-process-buffer (&rest body)
>>   "Like `with-temp-buffer', but always propagate `process-environment'.
>> When that var is buffer-local in the calling buffer, it is not
>> propagated by `with-temp-buffer', so we explicitly ensure that
>> happens, so that processes will be invoked consistently.  BODY is
>> as for that macro."
>>   (declare (indent 0) (debug (body)))
>>   (let ((p (gensym)))
>>     `(let ((,p process-environment))
>>        (with-temp-buffer
>>          (setq-local process-environment ,p)
>>          ,@body))))

Ah, I forgot about that because Magit does not make that variable local
for its own purposes.  It sets it here to deal with the fact that other
packages may make this variable buffer-local.

> On the same vein as the aforementioned bug#81175, I'd say the correct
> version of that macro should read
>
> (let ((,p (or (ignore-error void-variable
>                 (buffer-local-toplevel-value 'process-environment))
>               (default-toplevel-value 'process-environment))))
>    ...)


The problem isn't with how this macro retrieves the value, but in how it
"sets" it in the temporary buffer.

Fixed with:

(defmacro magit--with-temp-process-buffer (&rest body)
  "Like `with-temp-buffer', but propagate `process-environment' binding.

When that variable is buffer-local in the previously current buffer,
it is not propagated by `with-temp-buffer', so we explicitly ensure
that happens, so that processes are invoked consistently.  BODY is
as for that macro.

Note that itself Magit does not ever make this variable buffer-local.
This macro only exists to cope with third-party code doing that."
  (declare (indent 0) (debug (body)))
  (let ((p (gensym)))
    `(let ((,p process-environment))
       (with-temp-buffer
         (let ((process-environment ,p))
           ,@body)))))

Reply via email to