GNU bug report logs - #30134
ehsell and process-environment variable

Previous Next

Package: emacs;

Reported by: SK Kim <tttuuu888 <at> gmail.com>

Date: Tue, 16 Jan 2018 02:32:01 UTC

Severity: minor

Tags: notabug

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 30134 in the body.
You can then email your comments to 30134 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Tue, 16 Jan 2018 02:32:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to SK Kim <tttuuu888 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 16 Jan 2018 02:32:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: SK Kim <tttuuu888 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: ehsell and process-environment variable
Date: Tue, 16 Jan 2018 11:31:27 +0900
[Message part 1 (text/plain, inline)]
I found weird situation and looked into it by myself but I couldn't
solve it. so I'm writing down this mail now.

I wanted to make a new term with modifed process-environment but it
did not work properly when I make a new term from eshell buffer.  The
situation can be reproduced as below.

1) start emacs with 'emacs -Q'

2) evaluate below code in any buffer.
    (let ((process-environment (cons "TEST=1234" process-environment)))
        (make-term "test-term" "/bin/bash"))

3) moved to buffer 'test-term' and type 'echo $TEST' and you can see
   the result '1234'

Above is what I expected modified process-environment variable would
work and it actually works as I expected. However there is a condition
it doesn't work as I expected.

1) start emacs with 'emacs -Q'

2) 'M-x eshell' to open eshell buffer.

3) evaluate below code in eshell buffer.
    (let ((process-environment (cons "TEST=1234" process-environment)))
        (make-term "test-term" "/bin/bash"))

4) moved to buffer 'test-term' and type 'echo $TEST' and you can see
   nothing.

The modified process-environment variable is not properly affected if
the code is evaluated in eshell buffer. The eshell buffer is the only
buffer that I found the above code is not working properly.

This is tested on GNU Emacs 25.3.1 (x86_64-pc-linux-gnu, X toolkit,
Xaw scroll bars) of 2017-12-13

Possibly this might not be a bug and there is specific reason it works
that way but I couldn't have found any information about this and
couldn't have solved this by myself neither. So now I am sending this
bug report.

Thanks for everyone contributing to emacs. I appreciate it.

Thanks.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Tue, 16 Jan 2018 03:41:02 GMT) Full text and rfc822 format available.

Message #8 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: SK Kim <tttuuu888 <at> gmail.com>
Cc: 30134 <at> debbugs.gnu.org
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Tue, 16 Jan 2018 05:40:33 +0200
> From: SK Kim <tttuuu888 <at> gmail.com>
> Date: Tue, 16 Jan 2018 11:31:27 +0900
> 
> 1) start emacs with 'emacs -Q'
> 
> 2) 'M-x eshell' to open eshell buffer.
> 
> 3) evaluate below code in eshell buffer.
>     (let ((process-environment (cons "TEST=1234" process-environment)))
>         (make-term "test-term" "/bin/bash"))
> 
> 4) moved to buffer 'test-term' and type 'echo $TEST' and you can see
>    nothing.
> 
> The modified process-environment variable is not properly affected if
> the code is evaluated in eshell buffer. The eshell buffer is the only
> buffer that I found the above code is not working properly.

process-environment is for invoking other programs from Emacs.  By
contrast, Eshell does not invoke any other program, it is implemented
in Emacs itself.  And process-environment doesn't affect Emacs itself.
That is why you see the difference with other programs, in particular
shells invoked from Emacs.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Tue, 16 Jan 2018 17:05:01 GMT) Full text and rfc822 format available.

Message #11 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: SK Kim <tttuuu888 <at> gmail.com>
Cc: 30134 <at> debbugs.gnu.org
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Tue, 16 Jan 2018 19:04:08 +0200
[Please keep the bug address on the CC list.]

> From: SK Kim <tttuuu888 <at> gmail.com>
> Date: Tue, 16 Jan 2018 16:09:17 +0900
> 
> So that means, this result is natural in Emacs and package authors
> should also avoid such a code. Is this right?

Yes, I think so.

> Maybe if I want to guarantee the code is working properly in any
> buffers of Emacs, I should wrap the code with 'with-temp-buffer' as below.
> 
> (with-temp-buffer
>   (let ((process-environment (cons "TEST=1234" process-environment)))
>     (make-term "test-term" "/bin/bash")))

Maybe.  I will take another look in a couple of days.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Tue, 16 Jan 2018 18:04:02 GMT) Full text and rfc822 format available.

Message #14 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 30134 <at> debbugs.gnu.org, SK Kim <tttuuu888 <at> gmail.com>
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Tue, 16 Jan 2018 13:03:14 -0500
Eli Zaretskii wrote:

>> 2) 'M-x eshell' to open eshell buffer.
>> 
>> 3) evaluate below code in eshell buffer.
>>     (let ((process-environment (cons "TEST=1234" process-environment)))
>>         (make-term "test-term" "/bin/bash"))
>> 
>> 4) moved to buffer 'test-term' and type 'echo $TEST' and you can see
>>    nothing.
[...]
> process-environment is for invoking other programs from Emacs.  By
> contrast, Eshell does not invoke any other program, it is implemented
> in Emacs itself.  And process-environment doesn't affect Emacs itself.
> That is why you see the difference with other programs, in particular
> shells invoked from Emacs.

I don't think that's relevant to this report, where a bash shell is
being invoked, it just happens to be launched from an eshell buffer.

eshell seems to have some special handling for process-environment,
which is (presumably) the cause of this difference from other buffers.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Thu, 18 Jan 2018 17:46:02 GMT) Full text and rfc822 format available.

Message #17 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: SK Kim <tttuuu888 <at> gmail.com>
To: 30134 <at> debbugs.gnu.org
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Thu, 18 Jan 2018 15:11:26 +0900
[Message part 1 (text/plain, inline)]
I have looked into eshell and make-term source and narrowed down the
range of the issue somewhat.

If I evaluate the test code from eshell buffer, process-environment
lose "TEST=1234" inside make-term function as below.

(defun make-term (name program &optional startfile &rest switches)
  (let ((buffer (get-buffer-create (concat "*" name "*"))))
    (cond ((not (term-check-proc buffer))
    ;; Here, process-environemnt still have "TEST=1234"
   (with-current-buffer buffer
       ;; Here, process-environemnt lost "TEST=1234"
     (term-mode))
   (term-exec buffer name program startfile switches)))
    buffer))

I still don't know why but process-environment lost some values when
creating new buffer with 'get-buffer-create' function.

You can test this as below:

1-1) emacs -Q
1-2) evaluate below code.
     (let ((process-environment (cons "TEST=1234" process-environment)))
       (get-buffer-create "test-buffer")
       (switch-to-buffer "test-buffer")
       (member "TEST=1234" process-environment))
1-3) you can see "TEST=1234" is a member of process-environment in new
buffer.

2-1) emacs -Q
2-2) M-x eshell
2-3) evaluate below code in eshell buffer.
     (let ((process-environment (cons "TEST=1234" process-environment)))
       (get-buffer-create "test-buffer")
       (switch-to-buffer "test-buffer")
       (member "TEST=1234" process-environment))
2-4) you can see "TEST=1234" is lost from process-environment.


You can also test this simply as below.

3-1) emacs -Q
3-2) M-x eshell
3-3) evaluate below code in eshell buffer.
     (let ((process-environment (cons "TEST=1234" process-environment)))
       (with-temp-buffer
         (member "TEST=1234" process-environment)))
3-4) you can see "TEST=1234" is lost from process-environment.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Thu, 18 Jan 2018 17:50:02 GMT) Full text and rfc822 format available.

Message #20 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: SK Kim <tttuuu888 <at> gmail.com>
Cc: 30134 <at> debbugs.gnu.org
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Thu, 18 Jan 2018 12:49:28 -0500
[Please reply-to-all]

SK Kim wrote:

> I still don't know why but process-environment lost some values when
> creating new buffer with 'get-buffer-create' function.

Eshell makes process-environment buffer-local.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Thu, 18 Jan 2018 17:53:01 GMT) Full text and rfc822 format available.

Message #23 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: SK Kim <tttuuu888 <at> gmail.com>
Cc: 30134 <at> debbugs.gnu.org
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Thu, 18 Jan 2018 12:52:40 -0500
On Thu, Jan 18, 2018 at 1:11 AM, SK Kim <tttuuu888 <at> gmail.com> wrote:

> I still don't know why but process-environment lost some values when
> creating new buffer with 'get-buffer-create' function.

Probably because it's made into a buffer-local variable in eshell buffers:

(defun eshell-var-initialize ()
  "Initialize the variable handle code."
  ;; Break the association with our parent's environment.  Otherwise,
  ;; changing a variable will affect all of Emacs.
  (unless eshell-modify-global-environment
    (set (make-local-variable 'process-environment)
     (eshell-copy-environment)))
  [...]




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Thu, 18 Jan 2018 17:55:02 GMT) Full text and rfc822 format available.

Message #26 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: SK Kim <tttuuu888 <at> gmail.com>
Cc: 30134 <at> debbugs.gnu.org
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Thu, 18 Jan 2018 12:54:28 -0500
Glenn Morris wrote:

> Eshell makes process-environment buffer-local.

If you repeat your experiment with

emacs -Q --eval '(setq eshell-modify-global-environment t)' -f eshell

it works as you wanted.




Added tag(s) notabug. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 18 Jan 2018 17:55:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 30134 <at> debbugs.gnu.org and SK Kim <tttuuu888 <at> gmail.com> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Thu, 18 Jan 2018 17:55:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30134; Package emacs. (Fri, 19 Jan 2018 01:35:01 GMT) Full text and rfc822 format available.

Message #33 received at 30134 <at> debbugs.gnu.org (full text, mbox):

From: SK Kim <tttuuu888 <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 30134 <at> debbugs.gnu.org
Subject: Re: bug#30134: ehsell and process-environment variable
Date: Fri, 19 Jan 2018 10:33:54 +0900
[Message part 1 (text/plain, inline)]
Thank you for kind reply. I appreciate it.

2018. 1. 19. 오전 2:54에 "Glenn Morris" <rgm <at> gnu.org>님이 작성:

> Glenn Morris wrote:
>
> > Eshell makes process-environment buffer-local.
>
> If you repeat your experiment with
>
> emacs -Q --eval '(setq eshell-modify-global-environment t)' -f eshell
>
> it works as you wanted.
>
[Message part 2 (text/html, inline)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 16 Feb 2018 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 186 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.