all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Federico Tedin <federicotedin@gmail.com>
To: Pierre Neidhardt <mail@ambrevar.xyz>
Cc: 39596@debbugs.gnu.org
Subject: bug#39596: 26.3; Export INSIDE_EMACS with Eshell
Date: Wed, 19 Feb 2020 00:18:39 +0100	[thread overview]
Message-ID: <m1k14jpjqo.fsf@gmail.com> (raw)
In-Reply-To: <87a75lvds8.fsf@ambrevar.xyz> (Pierre Neidhardt's message of "Fri, 14 Feb 2020 08:17:11 +0100")

[-- Attachment #1: Type: text/plain, Size: 679 bytes --]

> Eshell does not have INSIDE_EMACS in its environment (unlike M-x shell)
> which I think is a bug as it breaks the behaviour of programs that make
> provisions for Emacs being used as a shell.
>
> See
> https://lists.gnu.org/archive/html/guix-devel/2020-02/msg00029.html
> for a discussion.
>
> Would it be possible to export this variable with Eshell?  Thanks!

I have added this feature to Eshell and created a patch, please check if
this works for you.

Additionally, I noticed that the doc string for
`eshell-variable-aliases-list' mentioned an `eshell-user-aliases-list',
variable but wasn't able to find it anywhere (neither using the Git
log), so I removed the mention.


[-- 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-patch, Size: 4158 bytes --]

From cf93960de7d3d92ccb7a5465851bbcb55a0f20d9 Mon Sep 17 00:00:00 2001
From: Federico Tedin <federicotedin@gmail.com>
Date: Wed, 19 Feb 2020 00:11:35 +0100
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.
* 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           |  3 +++
 lisp/eshell/esh-var.el           | 11 ++++++-----
 test/lisp/eshell/eshell-tests.el |  9 ++++++++-
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 1f8e6049a8..238184df24 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -120,6 +120,12 @@ To revert to the previous behaviour,
 unconditionally aborts the current edebug instrumentation with the
 supplied error message.
 
+** 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..b478ee028a 100644
--- a/lisp/eshell/em-dirs.el
+++ b/lisp/eshell/em-dirs.el
@@ -191,6 +191,9 @@ eshell-dirs-initialize
 		        (unless (ring-empty-p eshell-last-dir-ring)
 			  (expand-file-name
 			   (ring-ref eshell-last-dir-ring 0))))
+            t)
+           ("INSIDE_EMACS" ,(lambda (_indices)
+                              (format "%s,eshell" emacs-version))
             t))))
 
   (when eshell-cd-on-directory
diff --git a/lisp/eshell/esh-var.el b/lisp/eshell/esh-var.el
index 327a1def46..4231be92fb 100644
--- a/lisp/eshell/esh-var.el
+++ b/lisp/eshell/esh-var.el
@@ -179,10 +179,8 @@ 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 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'.
 
 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 +188,10 @@ 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.
+
+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..f98e4ce92b 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -167,7 +167,14 @@ eshell-test/last-arg-var
   "Test using the \"last arg\" ($_) variable"
   (with-temp-eshell
    (eshell-command-result-p "+ 1 2; + $_ 4"
-                             "3\n6\n")))
+                            "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
-- 
2.21.1 (Apple Git-122.3)


  reply	other threads:[~2020-02-18 23:18 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14  7:17 bug#39596: 26.3; Export INSIDE_EMACS with Eshell Pierre Neidhardt
2020-02-18 23:18 ` Federico Tedin [this message]
2020-02-19  7:40   ` Pierre Neidhardt
2020-02-19 16:22     ` Federico Tedin
2020-02-19 16:30       ` Pierre Neidhardt
2020-02-19 17:10       ` Andreas Schwab
2020-02-19 21:16         ` Federico Tedin

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1k14jpjqo.fsf@gmail.com \
    --to=federicotedin@gmail.com \
    --cc=39596@debbugs.gnu.org \
    --cc=mail@ambrevar.xyz \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.