Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dir-locals.el process-environment

82 views
Skip to first unread message

ed...@openmail.cc

unread,
Feb 19, 2018, 4:49:16 PM2/19/18
to help-gn...@gnu.org
Hi, I am trying to customise my building environment (debugging
included). I have this in my .dir-locals.el

(("src" ;https://stackoverflow.com/a/19521152
. ((c++-mode
;https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
.
((eval ;https://emacs.stackexchange.com/a/35965
. (progn
(make-local-variable 'process-environment)
(setq process-environment
(copy-sequence process-environment))
(setenv "CC" "mpicc"))))))))

However, if I printf "$CC" I get nothing. How can I achieve this?
Thanks.

-------------------------------------------------

ONLY AT VFEmail! - Use our Metadata Mitigator to keep your email out of the NSA's hands!
$24.95 ONETIME Lifetime accounts with Privacy Features!
15GB disk! No bandwidth quotas!
Commercial and Bulk Mail Options!

ed...@openmail.cc

unread,
Feb 25, 2018, 11:30:37 PM2/25/18
to help-gn...@gnu.org
Did someone receive my question? Is this the right mailing list? Thanks!

Eli Zaretskii

unread,
Feb 26, 2018, 2:15:21 PM2/26/18
to help-gn...@gnu.org
> Date: Mon, 26 Feb 2018 04:30:02 +0000
> From: ed...@openmail.cc
>
> (("src" ;https://stackoverflow.com/a/19521152
> . ((c++-mode
> ;https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
> .
> ((eval ;https://emacs.stackexchange.com/a/35965
> . (progn
> (make-local-variable 'process-environment)
> (setq process-environment
> (copy-sequence process-environment))
> (setenv "CC" "mpicc"))))))))
>
> However, if I printf "$CC" I get nothing. How can I achieve this?

What exactly do you do to 'printf "$CC"'?

ed...@openmail.cc

unread,
Feb 28, 2018, 12:48:39 AM2/28/18
to help-gn...@gnu.org
> Message: 1
> Date: Mon, 26 Feb 2018 21:15:13 +0200
> From: Eli Zaretskii <el...@gnu.org>
> To: help-gn...@gnu.org
> Subject: Re: dir-locals.el process-environment
> Message-ID: <83k1uz1...@gnu.org>
>
>> However, if I printf "$CC" I get nothing. How can I achieve this?
>
> What exactly do you do to 'printf "$CC"'?

Thanks for your reply, Eli! I'm sorry that I was not clear. This is how
I do it:

┌──── emacs-lisp
│ (
│ ("src" ;https://stackoverflow.com/a/19521152
│ . ((c++-mode
;https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
│ .
│ ((eval ;https://emacs.stackexchange.com/a/35965
│ . (progn
│ (make-local-variable 'process-environment)
│ (setq process-environment
│ (copy-sequence process-environment))
│ (setenv "CC" "mpicc")))
│ (compile-command . "printf x$CC"))))))
└────

Eli Zaretskii

unread,
Feb 28, 2018, 11:37:22 AM2/28/18
to help-gn...@gnu.org
> Date: Wed, 28 Feb 2018 05:47:57 +0000
> From: ed...@openmail.cc
> Cc: el...@gnu.org
>
> >> However, if I printf "$CC" I get nothing. How can I achieve this?
> >
> > What exactly do you do to 'printf "$CC"'?
>
> Thanks for your reply, Eli! I'm sorry that I was not clear. This is how
> I do it:
>
> ┌──── emacs-lisp
> │ (
> │ ("src" ;https://stackoverflow.com/a/19521152
> │ . ((c++-mode
> ;https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
> │ .
> │ ((eval ;https://emacs.stackexchange.com/a/35965
> │ . (progn
> │ (make-local-variable 'process-environment)
> │ (setq process-environment
> │ (copy-sequence process-environment))
> │ (setenv "CC" "mpicc")))
> │ (compile-command . "printf x$CC"))))))
> └────

So you are saying that in some buffer that visits a file from that
directory, you verified that compile-command's value is "printf x$CC",
but running "M-x compile RET" from that same buffer produces an empty
result?

ed...@openmail.cc

unread,
Feb 28, 2018, 5:19:28 PM2/28/18
to help-gn...@gnu.org
Yes! Sorry again. Thank you for your help. The whole process is like
this:

1. create .dir-locals.el in the top directory with this:

(
("src" ;https://stackoverflow.com/a/19521152
. ((c++-mode

;https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
.
((eval ;https://emacs.stackexchange.com/a/35965
. (progn
(make-local-variable 'process-environment)
(setq process-environment
(copy-sequence process-environment))
(setenv "CC" "mpicc")))
(compile-command . "printf x$CC"))))))

2. visit src/main.C (it can be empty)
3. press F5 (or M-x compile RET)

Actual output
The result is a buffer with the following contents.
-*- mode: compilation; default-directory: "src/" -*-
Compilation started at DATE

printf x$CC
x
Compilation finished at DATE

Expected output
I was expecting
-*- mode: compilation; default-directory: "src/" -*-
Compilation started at DATE

printf x$CC
xmpicc
Compilation finished at DATE

System specifications
- GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21) of
2017-09-22, modified by Debian
- Linux 4.13.0-32-generic #35-Ubuntu (it's not like Ubuntu is my cup of
tea, but it was the best compromise at the time)

Eli Zaretskii

unread,
Feb 28, 2018, 10:32:55 PM2/28/18
to help-gn...@gnu.org
> Date: Wed, 28 Feb 2018 22:18:50 +0000
> From: ed...@openmail.cc
You make process-environment local to the buffer main.c, but
compilation runs in its own buffer, *compilation*, where
process-environment doesn't include the $CC setting.

ed...@openmail.cc

unread,
Mar 1, 2018, 9:26:13 PM3/1/18
to help-gn...@gnu.org
> Date: Thu, 01 Mar 2018 05:32:53 +0200
> From: Eli Zaretskii <el...@gnu.org>
> To: help-gn...@gnu.org
> Subject: Re: dir-locals.el process-environment>
>
> You make process-environment local to the buffer main.c, but
> compilation runs in its own buffer, *compilation*, where
> process-environment doesn't include the $CC setting.

Thanks, Eli. I removed the line

(make-local-variable 'process-environment)

and now the compile command shows what I expected :) . Than you for your
time!

Stefan Monnier

unread,
Mar 2, 2018, 9:13:30 AM3/2/18
to help-gn...@gnu.org
>> You make process-environment local to the buffer main.c, but
>> compilation runs in its own buffer, *compilation*, where
>> process-environment doesn't include the $CC setting.

Maybe `compile` should take its process-environment from the buffer from
which it is invoked, rather than from the buffer in which the command is run.


Stefan


ed...@openmail.cc

unread,
Mar 3, 2018, 12:40:50 AM3/3/18
to help-gn...@gnu.org
> Date: Fri, 02 Mar 2018 09:13:07 -0500
> From: Stefan Monnier <mon...@iro.umontreal.ca>
> To: help-gn...@gnu.org
> Subject: Re: dir-locals.el process-environment
> Message-ID: <jwv4llybm7s.fsf-monn...@gnu.org>
>
> Maybe `compile` should take its process-environment from the buffer
> from
> which it is invoked, rather than from the buffer in which the command
> is run.
>
>
> Stefan

It's not a bad idea Stefan, but I am not a fan of buffer-local variables
(if that is what you mean). I find it intrusive for other users. Thanks
for the suggestion.

I still have to check if the debugging will use those environmental
variables :P .
0 new messages