From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Federico Tedin Newsgroups: gmane.emacs.bugs Subject: bug#25496: 25.1.91; INSIDE_EMACS env variable is not set in eshell Date: Mon, 30 Mar 2020 21:52:49 +0200 Message-ID: <87wo71ipri.fsf@gmail.com> References: <87zhc0huyn.fsf@gmail.com> <874ku6yeu4.fsf@gmail.com> <87sghqipkx.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="6356"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: 25496@debbugs.gnu.org To: Noam Postavsky Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 30 21:53:14 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJ0TC-0001Z2-KF for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Mar 2020 21:53:14 +0200 Original-Received: from localhost ([::1]:55766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJ0TB-0004SD-J9 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 30 Mar 2020 15:53:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59733) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jJ0T1-0004RG-OA for bug-gnu-emacs@gnu.org; Mon, 30 Mar 2020 15:53:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jJ0T0-0002GN-5e for bug-gnu-emacs@gnu.org; Mon, 30 Mar 2020 15:53:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jJ0Sz-0002FO-U4 for bug-gnu-emacs@gnu.org; Mon, 30 Mar 2020 15:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jJ0Sz-000208-SQ for bug-gnu-emacs@gnu.org; Mon, 30 Mar 2020 15:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Federico Tedin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 30 Mar 2020 19:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25496 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 25496-submit@debbugs.gnu.org id=B25496.15855979807685 (code B ref 25496); Mon, 30 Mar 2020 19:53:01 +0000 Original-Received: (at 25496) by debbugs.gnu.org; 30 Mar 2020 19:53:00 +0000 Original-Received: from localhost ([127.0.0.1]:35111 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jJ0Sx-0001zt-QJ for submit@debbugs.gnu.org; Mon, 30 Mar 2020 15:53:00 -0400 Original-Received: from mail-wm1-f52.google.com ([209.85.128.52]:35366) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jJ0Sw-0001zf-0i for 25496@debbugs.gnu.org; Mon, 30 Mar 2020 15:52:58 -0400 Original-Received: by mail-wm1-f52.google.com with SMTP id i19so181392wmb.0 for <25496@debbugs.gnu.org>; Mon, 30 Mar 2020 12:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=ZsQzrHNw4RV7c93a/X2R8HuWrNVhrznYoDKi/y2Bw60=; b=APtmdkwps6fEU5mxOo1q0WNzroHRMMbOiuxl0wlLgI+XOZMHnr9a9k0DeD5RJB8gjw XcRPcaaKgJL09VEfieSRyzR0Zy/JQvT5nkEyJusGzPnmSMC8xE07z2EnjGTV5bDUMbd4 qKRykPnVwV/cCE24IDCgTJfDZJXsFVA1Dg9H4xSWoxybTyW6i8sTxyMD9mkspstT+5i6 7aZmJ5xx3wY21I3ZVMziWWYJhGgP7UBxgQEwezYUlPzhLyENrmbCQCqeQR31SrkN2XJ1 +BNfafJyerZmMtV0GP0CPgV9YUaWtTYXwC4uUNbcjRdzGQaL4bggXN2WUYGQOFWTjgbl v3XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=ZsQzrHNw4RV7c93a/X2R8HuWrNVhrznYoDKi/y2Bw60=; b=VCHYrmulqvc8uxXVukA8/w4GF5rT8bdQEGmeNCLmlbfLjTGZnvPJgCLbKSaFto/ClM lpgXM8S5Rz+aaG6CWJkh253b/K6IiwS50mLRU7j7Fe8NfHdGdy6B9F3LGArEVwwnfQdj okoO3ql9bMKsH5SCSjKo+4hRx/WyKAQNGczNhXY3cuaQvbYF0jGYKsw79rHS+OTXXJ37 BS27hNIHR6oTJqMI6A3hqi02TCze/or8jmLj66/vxvKbpTL3qiZkb3QOyckOdGytBeIX 66KfZfmczQSbWoRermniWdpWvyiPnKPBLx5fsxYxGjLFdY6Jd51HaPH8AWKAWKwMbD0e 3cGw== X-Gm-Message-State: ANhLgQ26t5GFgmdL9wna3Y0OyfuPZEk9utavxScYGHE9J5N2f+jdwbDf /UOL26TGbZV8wuTg9TnWIoHRC3fpXgE= X-Google-Smtp-Source: ADFU+vu9YK4xWKOb51GAk+XAgz29yQIeDTBhI3wu4LB5T858jgKYmwUMB90x6Sl8gYVq6KSBWaB0CQ== X-Received: by 2002:a7b:cf19:: with SMTP id l25mr856330wmg.131.1585597971616; Mon, 30 Mar 2020 12:52:51 -0700 (PDT) Original-Received: from lead ([2a02:8109:8ac0:2ff0:7061:a1a:dea7:463d]) by smtp.gmail.com with ESMTPSA id p10sm24036745wrm.6.2020.03.30.12.52.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Mar 2020 12:52:50 -0700 (PDT) In-Reply-To: <87sghqipkx.fsf@gmail.com> (Noam Postavsky's message of "Sun, 29 Mar 2020 21:44:30 -0400") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177884 Archived-At: --=-=-= Content-Type: text/plain >> 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!) --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Copy-INSIDE_EMACS-env-variable-to-subprocesses-in-Es.patch >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 --=-=-=--