From: Federico Tedin <federicotedin@gmail.com>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 25496@debbugs.gnu.org
Subject: bug#25496: 25.1.91; INSIDE_EMACS env variable is not set in eshell
Date: Mon, 30 Mar 2020 21:52:49 +0200 [thread overview]
Message-ID: <87wo71ipri.fsf@gmail.com> (raw)
In-Reply-To: <87sghqipkx.fsf@gmail.com> (Noam Postavsky's message of "Sun, 29 Mar 2020 21:44:30 -0400")
[-- Attachment #1: Type: text/plain, Size: 1860 bytes --]
>> I've removed the lambda, but I wasn't able to use a string directly, I
>> had to set the value elsewhere using a defconst. This is due to how
>> `eshell-get-variable' interprets string values associated to
>> variables.
>
> Oh, a string is actually taken as an environment variable to alias. I
> guess that does justify the name. I think we might actually be better
> off with the lambda, what do you think?
Hmm, actually now it's working fine - the value associated with
INSIDE_EMACS is the symbol `eshell-inside-emacs'. Then
`eshell-get-variable' is returning that symbol's value, which is what we
want. The `$$', `$?' and `$0' variables are also set to symbols.
(But the lambda would also work, of course. No preferences here.)
>> "This list provides aliasing for variable references.
>> -It is very similar in concept to what `eshell-user-aliases-list' does
>> -for commands. Each member of this defines the name of a command,
>> -and the Lisp value to return for that variable if it is accessed
>> -via the syntax `$NAME'.
>> +Each member defines the name of a variable, and the Lisp value to
>> +return for that variable if it is accessed via the syntax `$NAME'.
>
> Again, not a problem introduced by your patch, but "Lisp value to
> return" seem pretty inaccurate (if you don't feel like fixing this, it's
> okay, I think describing it correctly is somewhat non-trivial).
Aaah sorry, I hadn't read your comment correctly. I've rewritten that
part and expanded a bit upon it. I think the most confusing part is that
when a user does `$foobar', if "foobar" is not in
eshell-variable-aliases-list, then "foobar" itself is used as a "value"
(which may or may not end up pointing to an env var, or a Lisp var). But
I don't think this is relevant when explaining what
eshell-variable-aliases-list should contain.
(I've attached a new patch!)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Copy-INSIDE_EMACS-env-variable-to-subprocesses-in-Es.patch --]
[-- Type: text/x-diff, Size: 4988 bytes --]
From 3f56b3641ba75430210325bcfd0c1bdff16f2a01 Mon Sep 17 00:00:00 2001
From: Federico Tedin <federicotedin@gmail.com>
Date: Mon, 30 Mar 2020 21:44:47 +0200
Subject: [PATCH] Copy INSIDE_EMACS env variable to subprocesses in Eshell
* lisp/eshell/em-dirs.el (eshell-dirs-initialize): Add INSIDE_EMACS
variable to buffer-local value of eshell-variable-aliases-alist.
(eshell-inside-emacs): Add new constant used for INSIDE_EMACS.
* lisp/eshell/esh-var.el (eshell-variable-aliases-list): Update doc
string; remove mention of eshell-user-aliases-list and explain that
variables can optionally be copied to subprocesses' environments.
* test/lisp/eshell/eshell-tests.el (eshell-test/inside-emacs-var): Add
test for the INSIDE_EMACS variable.
* etc/NEWS: Announce changes.
---
etc/NEWS | 6 ++++++
lisp/eshell/em-dirs.el | 5 +++++
lisp/eshell/esh-var.el | 23 ++++++++++++++++++-----
test/lisp/eshell/eshell-tests.el | 7 +++++++
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 4b477e5def..9ac90ecabf 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -161,6 +161,12 @@ functions accessible to the user through the existing single function hook
Modes should use the new hook instead of this user option to register
their backends.
+** Eshell
+
+---
+*** Environment variable INSIDE_EMACS is now copied to subprocesses.
+Its value equals the result of evaluating '(format "%s,eshell" emacs-version)'.
+
** Tramp
+++
diff --git a/lisp/eshell/em-dirs.el b/lisp/eshell/em-dirs.el
index 1949e5dc8f..51df6fa1d5 100644
--- a/lisp/eshell/em-dirs.el
+++ b/lisp/eshell/em-dirs.el
@@ -168,6 +168,9 @@ eshell-dirstack
(defvar eshell-last-dir-ring nil
"The last directory that Eshell was in.")
+(defconst eshell-inside-emacs (format "%s,eshell" emacs-version)
+ "Value for the `INSIDE_EMACS' environment variable.")
+
;;; Functions:
(defun eshell-dirs-initialize () ;Called from `eshell-mode' via intern-soft!
@@ -191,6 +194,8 @@ eshell-dirs-initialize
(unless (ring-empty-p eshell-last-dir-ring)
(expand-file-name
(ring-ref eshell-last-dir-ring 0))))
+ t)
+ ("INSIDE_EMACS" eshell-inside-emacs
t))))
(when eshell-cd-on-directory
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index 327a1def46..c12999ee0d 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -179,10 +179,9 @@ eshell-variable-aliases-list
(eshell-apply-indices eshell-command-arguments
indices)))))
"This list provides aliasing for variable references.
-It is very similar in concept to what `eshell-user-aliases-list' does
-for commands. Each member of this defines the name of a command,
-and the Lisp value to return for that variable if it is accessed
-via the syntax `$NAME'.
+Each member defines the name of a variable, and a Lisp value used to
+compute the string value that will be returned when the variable is
+accessed via the syntax `$NAME'.
If the value is a function, that function will be called with two
arguments: the list of the indices that was used in the reference, and
@@ -190,7 +189,21 @@ eshell-variable-aliases-list
For example, a reference of `$NAME[10][20]' would result in the
function for alias `NAME' being called (assuming it were aliased to a
function), and the arguments passed to this function would be the list
-'(10 20)', and nil."
+'(10 20)', and nil.
+
+If the value is a string, the value for the variable with that name in
+the current environment will be returned. If no variable with that
+name exists in the environment, but if a symbol with that same name
+exists and has a value bound to it, then that value will be used. You
+can prioritize symbol values over environment values by setting
+`eshell-prefer-lisp-variables' to t.
+
+If the value is a symbol, the value bound to that symbol will be used.
+
+If the value has any other type, `error' will be signaled.
+
+Additionally, each member may specify if it should be copied to the
+environment of created subprocesses."
:type '(repeat (list string sexp
(choice (const :tag "Copy to environment" t)
(const :tag "Use only in Eshell" nil)))))
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index 026818ab06..ce8d728833 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -169,6 +169,13 @@ eshell-test/last-arg-var
(eshell-command-result-p "+ 1 2; + $_ 4"
"3\n6\n")))
+(ert-deftest eshell-test/inside-emacs-var ()
+ "Test presence of \"INSIDE_EMACS\" in subprocesses"
+ (with-temp-eshell
+ (eshell-command-result-p "env"
+ (format "INSIDE_EMACS=%s,eshell"
+ emacs-version))))
+
(ert-deftest eshell-test/escape-nonspecial ()
"Test that \"\\c\" and \"c\" are equivalent when \"c\" is not a
special character."
--
2.17.1
next prev parent reply other threads:[~2020-03-30 19:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-20 22:32 bug#25496: 25.1.91; INSIDE_EMACS env variable is not set in eshell Alex Hutcheson
2017-01-23 20:20 ` Glenn Morris
2017-01-23 20:36 ` Alex Hutcheson
2020-03-08 16:50 ` Federico Tedin
2020-03-28 15:05 ` Federico Tedin
2020-03-29 0:21 ` Noam Postavsky
2020-03-29 22:29 ` Federico Tedin
2020-03-30 1:44 ` Noam Postavsky
2020-03-30 19:52 ` Federico Tedin [this message]
2020-03-30 23:11 ` Noam Postavsky
2020-04-02 23:06 ` Noam Postavsky
2020-04-03 12:17 ` Eli Zaretskii
2020-04-04 10:08 ` Federico Tedin
2020-04-11 9:20 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wo71ipri.fsf@gmail.com \
--to=federicotedin@gmail.com \
--cc=25496@debbugs.gnu.org \
--cc=npostavs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).