From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "George D. Plymale" Newsgroups: gmane.emacs.bugs Subject: bug#26161: 25.1; `eshell-exit-success-p' determines that Lisp commands are successful if they return non-nil Date: Tue, 11 Apr 2017 15:48:05 -0400 Message-ID: <446FF585-0B21-4774-8966-DCECB218C96B@orbitalimpact.com> References: <7E4E5778-FFBF-4298-9DEF-0A60539999D5@orbitalimpact.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Content-Type: multipart/alternative; boundary="Apple-Mail=_3411E699-159D-43B2-8DC5-304537904803" X-Trace: blaine.gmane.org 1491940155 6240 195.159.176.226 (11 Apr 2017 19:49:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Apr 2017 19:49:15 +0000 (UTC) Cc: 26161@debbugs.gnu.org To: npostavs@users.sourceforge.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 11 21:49:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cy1mn-0001X4-NT for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Apr 2017 21:49:09 +0200 Original-Received: from localhost ([::1]:40920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy1mt-0006yl-Li for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Apr 2017 15:49:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy1mj-0006xS-8m for bug-gnu-emacs@gnu.org; Tue, 11 Apr 2017 15:49:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cy1mg-0002S7-57 for bug-gnu-emacs@gnu.org; Tue, 11 Apr 2017 15:49:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:45132) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cy1mf-0002Rz-V8 for bug-gnu-emacs@gnu.org; Tue, 11 Apr 2017 15:49:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cy1mf-00027T-P9 for bug-gnu-emacs@gnu.org; Tue, 11 Apr 2017 15:49:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <7E4E5778-FFBF-4298-9DEF-0A60539999D5@orbitalimpact.com> Resent-From: "George D. Plymale" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Apr 2017 19:49:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26161 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 26161-submit@debbugs.gnu.org id=B26161.14919401018078 (code B ref 26161); Tue, 11 Apr 2017 19:49:01 +0000 Original-Received: (at 26161) by debbugs.gnu.org; 11 Apr 2017 19:48:21 +0000 Original-Received: from localhost ([127.0.0.1]:43331 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cy1m1-00026E-Cm for submit@debbugs.gnu.org; Tue, 11 Apr 2017 15:48:21 -0400 Original-Received: from mail-qt0-f180.google.com ([209.85.216.180]:36077) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cy1lz-00025z-Iv for 26161@debbugs.gnu.org; Tue, 11 Apr 2017 15:48:20 -0400 Original-Received: by mail-qt0-f180.google.com with SMTP id v3so6629500qtd.3 for <26161@debbugs.gnu.org>; Tue, 11 Apr 2017 12:48:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orbitalimpact.com; s=google; h=from:mime-version:subject:date:cc:to:message-id; bh=lzpD12+eUAuxAxQFmkFjI95H3FDLQhxYKcdq8TTBKA0=; b=ODpjkx8BdkXVm4Ie7rRDf+5v5NQHy4sI/6EPnxBgRynbaXUfW/LRFnGpdobFaC0q4x Lm5TrMs1DrOxCD3T02Cfl6v4QaOa1hqdnMe1I4hP3Lp8CPpCbevYYoTzx/rwtftRHEo3 iFoHLU4bnDgXmUrtU8a23IAOIBarRTr524c5s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:cc:to:message-id; bh=lzpD12+eUAuxAxQFmkFjI95H3FDLQhxYKcdq8TTBKA0=; b=oRIHSqGwWobi9GqMjjyLTjanc+DN7nn2ZQx2Ua4ylo7ML0q+kuufjtZV/4/n+7/IU+ eSzp1lEJZkp4kCxQw32xBqqxjRShFy7vYS0uxe+UxpDbVociXMPs5oVrJ9sgRKbovc9v P39tzOCnzPLPQT+OgVgJXehn/iJDMpRlSAWVCrFqIW8cAbOn+Jga0IAXBNzc3qezDizx 0YouuLDfboJHsdxiKlJXwBJQcGsd6ikCFMoFfz4bH2INkzrgBb9vbOASDuHnOl/Y2T6+ gfK4iyE0rJNsgKtOT7TA/rv2HsnCObTRPdB3YuTvJN80pVRS229z+wua94RrjjIsRxSu K/Bg== X-Gm-Message-State: AN3rC/7jqsgNuBh2o/Q0Ra8U0WiNeV8n3JQpC/0UoqLJsom1Kx8oT1qCHNLZDptkYz8J4w== X-Received: by 10.200.56.175 with SMTP id f44mr15231902qtc.161.1491940093818; Tue, 11 Apr 2017 12:48:13 -0700 (PDT) Original-Received: from [10.54.10.6] ([208.167.254.13]) by smtp.gmail.com with ESMTPSA id c26sm7057722qte.19.2017.04.11.12.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 12:48:12 -0700 (PDT) X-Mailbutler-Tracking-Uuid: 406B8614-AE3B-4088-9C5B-6F43723FD10C X-Mailbutler-Link-Tracking-Uuid: X-Mailer: Apple Mail (2.3273) 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: 208.118.235.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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:131483 Archived-At: --Apple-Mail=_3411E699-159D-43B2-8DC5-304537904803 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=bug_26161_fix.diff Content-Description: Fix for bug#26161 diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index 583ba6ac42..86e7b83c28 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el @@ -575,14 +575,9 @@ eshell-rewrite-if-command (defvar eshell-last-command-result) ;Defined in esh-io.el. (defun eshell-exit-success-p () - "Return non-nil if the last command was \"successful\". -For a bit of Lisp code, this means a return value of non-nil. -For an external command, it means an exit code of 0." - (if (save-match-data - (string-match "#<\\(Lisp object\\|function .*\\)>" - eshell-last-command-name)) - eshell-last-command-result - (= eshell-last-command-status 0))) + "Return non-nil if the last command was successful. +This means an exit code of 0." + (= eshell-last-command-status 0)) (defvar eshell--cmd) @@ -1257,6 +1252,7 @@ eshell-exec-lisp (and result (funcall printer result)) result) (error + (setq eshell-last-command-status 1) (let ((msg (error-message-string err))) (if (and (not form-p) (string-match "^Wrong number of arguments" msg) --=-=-= Content-Type: text/plain Okay, so I created a patch to fix this issue. Go easy on me since this is my first patch to Emacs ;) The changes are pretty simple: - `eshell-exit-success-p' has been changed to only check if the last exit code was zero, rather than first checking whether the last command returned nil. - `eshell-exec-lisp' has been changed so that it will set `eshell-last-command-status' to 1 if it catches an error. - These changes together make it so that the `&&' operator in Eshell behaves more expectedly to someone who has used a bash-like shell and so that other things involving the success of Lisp commands in Eshell are more reliable. Feel free to point out anything else that should be done here or any errors on my part. I have tested these changes out and everything seems okay. I can run the aforementioned commands that were problematic. Examples: ~ $ cd .. && pwd /Users /Users $ cd - && pwd /Users/my_username ~ $ .. && pwd /Users /Users $ cd - && pwd /Users/my_username ~ $ cat ~/.emacs && pwd ;; Emacs init file stuff (foo bar)/Users/my_username ~ $ cat nowhere && pwd cat: nowhere: No such file or directory ~ $ cat nowhere ; pwd cat: nowhere: No such file or directory /Users/my_username ~ $ --=-=-=-- --Apple-Mail=_3411E699-159D-43B2-8DC5-304537904803 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
--=3D-=3D-=3D
Content-Type: text/x-patch
Content-Disposition: attachment; = filename=3Dbug_26161_fix.diff
Content-Description: Fix for = bug#26161

diff --git = a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index = 583ba6ac42..86e7b83c28 100644
--- = a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -575,14 +575,9 @@ eshell-rewrite-if-command
= (defvar eshell-last-command-result)     ;Defined = in esh-io.el.

(defun = eshell-exit-success-p ()
-  "Return non-nil if the = last command was \"successful\".
-For a bit of Lisp code, = this means a return value of non-nil.
-For an external = command, it means an exit code of 0."
-  (if (save-match-data
- = (string-match "#<\\(Lisp object\\|function .*\\)>"
- = =       = eshell-last-command-name))
-      = eshell-last-command-result
-    (=3D = eshell-last-command-status 0)))
+  "Return non-nil if the = last command was successful.
+This means an exit code of = 0."
+  = (=3D eshell-last-command-status 0))

= (defvar eshell--cmd)

@@ -1257,6 +1252,7 @@ = eshell-exec-lisp
       =   (and result (funcall printer result))
       =   result)
     = (error
+     (setq = eshell-last-command-status 1)
      = (let ((msg (error-message-string err)))
       = (if (and (not form-p)
       =           = (string-match "^Wrong number of arguments" msg)

--=3D-=3D-=3D
Content-Type: text/plain

Okay, so I created a patch to fix this issue. = Go easy on me since this
is my first patch to Emacs ;)

The changes are pretty simple:
- `eshell-exit-success-p' has been changed to only check if = the last
 = exit code was zero, rather than first checking whether the last = command
  = returned nil.
- `eshell-exec-lisp' has been changed so = that it will set
  = `eshell-last-command-status' to 1 if it catches an error.
- = These changes together make it so that the `&&' operator in = Eshell
  = behaves more expectedly to someone who has used a bash-like shell and
  so that = other things involving the success of Lisp commands in Eshell
  are more = reliable.
 
Feel free = to point out anything else that should be done here or any
errors on my part. I have tested these changes out and = everything seems
okay. I can run the aforementioned = commands that were problematic. Examples:

~ = $ cd .. && pwd
/Users

/Users $ cd - && pwd
/Users/my_username

~ $ .. = && pwd
/Users

/Users = $ cd - && pwd
/Users/my_username

~ $ cat ~/.emacs && pwd
;; Emacs init = file stuff
(foo bar)/Users/my_username

~ $ cat nowhere && pwd
cat: nowhere: No = such file or directory

~ $ cat nowhere ; = pwd
cat: nowhere: No such file or directory
/Users/my_username

~ $

--=3D-=3D-=3D--



3D""= --Apple-Mail=_3411E699-159D-43B2-8DC5-304537904803--