Subject: Re: bug#32129: 26.1; Bug in add-dir-local-variable when used with eval, progn and setenv

From: Noam Postavsky <[email-masked]>
Date: Wed, 11 Jul 2018 19:20:27 -0400

Luis Gerhorst <[email-masked]> writes:

> (1) Open Emacs with emacs -Q
> (2) Type the following code into *scratch*
>
>     (add-dir-local-variable
>      'c-mode
>      'eval
>      '(progn (make-local-variable 'process-environment)
>              (setq process-environment (copy-sequence process-environment))
>              (setenv "TEST" "hello")))
>
> (3) M-x eval-buffer
>
> Expected .dir-locals.el contents:
> ((c-mode (eval . (progn (make-local-variable 'process-environment)
>                         (setq process-environment (copy-sequence process-environment))
>                         (setenv "TEST" "hello")))))
>
> Actual contents:
> ((c-mode (eval progn (make-local-variable 'process-environment)
>                      (setq process-environment (copy-sequence process-environment))
>                      (setenv "TEST" "hello"))))
>
> When I open a C file and inspect process-environment, TEST is not set.
>
> When I manually create a .dir-locals.el with the expected contents, it
> works.

When I manually create a .dir-locals.el with the actual contents it
works too.

> Please correct me if I'm using add-dir-local-variable wrong, I was not
> able to find a version that works as expected with the above
> progn. Strangely, if I use (progn (message "hello")), instead of the
> progn with setenv, "hello" gets printed every time I open a C file.

I think add-dir-local-variable is fine, both the expected and actual
values you posted are the same (the expected one just happens to use
dotted pair notation).

Maybe the problem is that you need to use

    (setq-local process-environment ...)

Otherwise your eval clause sets the global value (which is possibly
being clobbered by other things in your config?).