>From 3f56b3641ba75430210325bcfd0c1bdff16f2a01 Mon Sep 17 00:00:00 2001 From: Federico Tedin 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