From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Davide Masserut via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65604: [PATCH] Display the exit code if the last command failed in Eshell Date: Sat, 02 Sep 2023 20:54:38 +0200 Message-ID: <87zg24e1ei.fsf@mssdvd.com> References: <87cyz5wjtm.fsf@mssdvd.com> <05108d35-d095-c975-78b8-6b00fc7e6a08@gmail.com> <87o7iolg6o.fsf@mssdvd.com> <83v8cwfphy.fsf@gnu.org> <87wmxc4ah3.fsf@mssdvd.com> <83fs40fi35.fsf@gnu.org> <87msy8s344.fsf@mssdvd.com> <83a5u7g6f3.fsf@gnu.org> <87cyz38rj2.fsf@mssdvd.com> <98c6ac0f-08fd-8dd0-2213-8a482f5ac67f@gmail.com> <87msy4yl2c.fsf@mssdvd.com> <1f740d2f-ee68-7157-b6bb-d2725c9c67c3@gmail.com> Reply-To: Davide Masserut Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6677"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65604@debbugs.gnu.org, Eli Zaretskii , me@eshelyaron.com To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 02 23:01:14 2023 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 1qcXk1-0001Y2-Vq for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 02 Sep 2023 23:01:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcXji-0004TW-Gk; Sat, 02 Sep 2023 17:00:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qcXjh-0004TN-0h for bug-gnu-emacs@gnu.org; Sat, 02 Sep 2023 17:00:53 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qcXjg-0005MD-OU for bug-gnu-emacs@gnu.org; Sat, 02 Sep 2023 17:00:52 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qcXjq-0007xx-7F for bug-gnu-emacs@gnu.org; Sat, 02 Sep 2023 17:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Davide Masserut Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 02 Sep 2023 21:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65604 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 65604-submit@debbugs.gnu.org id=B65604.169368844230588 (code B ref 65604); Sat, 02 Sep 2023 21:01:02 +0000 Original-Received: (at 65604) by debbugs.gnu.org; 2 Sep 2023 21:00:42 +0000 Original-Received: from localhost ([127.0.0.1]:38778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qcXjV-0007xF-D2 for submit@debbugs.gnu.org; Sat, 02 Sep 2023 17:00:41 -0400 Original-Received: from out-220.mta0.migadu.com ([91.218.175.220]:16795) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qcXjQ-0007x2-Bm for 65604@debbugs.gnu.org; Sat, 02 Sep 2023 17:00:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mssdvd.com; s=key1; t=1693688424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SDFR8N3+tTe53A9H0IsdnG7QkkOIn5G340JB5g/1FzM=; b=cP4fjK6KNU927qHMPblXnvyJMw4u/n+jyN8i0/AHEtoRIZK+fXjx4NVgF5tjwTGxLCNFOn LuAcDzpBbF3hY2n7bUAz+rmmblpjneu/9e8E+IAhus/x/YjOFyju+rmUMMShMDjD40kF+L RLT92HqN7UgqfPyJwfj5sUPsaLCNyZrfpRtzAuu1xG5BeQjL4CLqDKTb3C6DydL/Gm4Ng8 7ylJsZfLwVwQt9vWhEUBuLE1jqpDDPOwBOUSlSFo1wFTnyhFhMxr2UsKY6ihgcTmsGiO2q /5JMovPe0qrJtJF0TytDTYdfmLIgnykZFbpq31DT4T4ChngX8iKonHJrJzb1oA== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <1f740d2f-ee68-7157-b6bb-d2725c9c67c3@gmail.com> X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:269052 Archived-At: --=-=-= Content-Type: text/plain; format=flowed Jim Porter writes: >> 2) It may require to update the regexp. > > The prompt regexp is (thankfully) almost irrelevant in Emacs 30 > now. It only matters for paragraph-movement commands, which we > could > probably just remap to the actual Eshell-specific commands to > navigate > forward and backward through the prompts. I should probably just > make > a patch for this and finally get rid of that regexp entirely. I didn't know that, thanks. >> In this case I would add a small delay before signaling that >> something is running. > > The delay isn't present in the current Eshell mode-line > implementation, and I don't think anyone's raised an issue about > that... Sorry, I meant that if we decided to show a relative long message like "Running" in the mode-line, then we should show it only when it lasts for more than, let's say, 0.5s. This would prevent the mode-line from moving to right for just a fraction of a second when running fast commands like cd or ls. > ... in any case, maybe the simplest way forward here is to put > the > (non-zero) exit status in the prompt like your original patch, > and > then separately, I can try to improve the customizability of the > prompt, as well as thinking about what to do with the mode-line. I have updated the patch. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Display-the-exit-code-if-the-last-command-failed-in-.patch >From 83f716950a60ee64c49654033430f8e09d373f24 Mon Sep 17 00:00:00 2001 From: Davide Masserut Date: Tue, 29 Aug 2023 22:33:48 +0200 Subject: [PATCH] Display the exit code if the last command failed in Eshell * doc/misc/eshell.texi (Invocation): Document change. * etc/NEWS: Announce change. * lisp/eshell/em-prompt.el (eshell-prompt-function): Insert the exit code if last command failed. * lisp/eshell/esh-io.el (eshell-last-command-status): Make it buffer-local. * test/lisp/eshell/em-prompt-tests.el (em-prompt-test/after-failure) (em-prompt-test/next-previous-prompt-with) (em-prompt-test/forward-backward-matching-input-with): New tests. --- doc/misc/eshell.texi | 3 +++ etc/NEWS | 3 +++ lisp/eshell/em-prompt.el | 2 ++ lisp/eshell/esh-io.el | 2 +- test/lisp/eshell/em-prompt-tests.el | 37 +++++++++++++++++++++++++---- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index 7a563bc794c..677bd0f3e3e 100644 --- a/doc/misc/eshell.texi +++ b/doc/misc/eshell.texi @@ -234,6 +234,9 @@ Invocation can be controlled the same way as any other background process in Emacs. +If a command exits abnormally, Eshell displays the command's exit code +in the prompt. + @subsection Command form Command form looks much the same as in other shells. A command consists of arguments separated by spaces; the first argument is the diff --git a/etc/NEWS b/etc/NEWS index 5c11b6b9ac7..7a9010a2a9a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -370,6 +370,9 @@ to load the edited aliases. Running 'rgrep' in Eshell now uses the Emacs grep facility instead of calling external rgrep. ++++ +*** If a command exits abnormally, Eshell now displays the command's exit code in the prompt. + ** Pcomplete --- diff --git a/lisp/eshell/em-prompt.el b/lisp/eshell/em-prompt.el index 42f8f273b52..692b579d02d 100644 --- a/lisp/eshell/em-prompt.el +++ b/lisp/eshell/em-prompt.el @@ -50,6 +50,8 @@ eshell-prompt-load-hook (defcustom eshell-prompt-function (lambda () (concat (abbreviate-file-name (eshell/pwd)) + (unless (eshell-exit-success-p) + (format " [%d]" eshell-last-command-status)) (if (= (file-user-uid) 0) " # " " $ "))) "A function that returns the Eshell prompt string. Make sure to update `eshell-prompt-regexp' so that it will match your diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el index c07f871dd37..cd0cee6e21d 100644 --- a/lisp/eshell/esh-io.el +++ b/lisp/eshell/esh-io.el @@ -170,7 +170,7 @@ eshell-redirection-operators-alist (defvar eshell-current-handles nil) -(defvar eshell-last-command-status 0 +(defvar-local eshell-last-command-status 0 "The exit code from the last command. 0 if successful.") (defvar eshell-last-command-result nil diff --git a/test/lisp/eshell/em-prompt-tests.el b/test/lisp/eshell/em-prompt-tests.el index 93bf9d84ab3..c90f417cefd 100644 --- a/test/lisp/eshell/em-prompt-tests.el +++ b/test/lisp/eshell/em-prompt-tests.el @@ -34,6 +34,25 @@ ;;; Tests: +(ert-deftest em-prompt-test/after-failure () + "Check that current prompt shows the exit code of the last failed command." + (with-temp-eshell + (let ((debug-on-error nil)) + (eshell-insert-command "(zerop \"foo\")")) + (let ((current-prompt (field-string (1- (point))))) + (should (equal-including-properties + current-prompt + (propertize + (concat (directory-file-name default-directory) + (unless (eshell-exit-success-p) + (format " [%d]" eshell-last-command-status)) + (if (= (file-user-uid) 0) " # " " $ ")) + 'read-only t + 'field 'prompt + 'font-lock-face 'eshell-prompt + 'front-sticky '(read-only field font-lock-face) + 'rear-nonsticky '(read-only field font-lock-face))))))) + (ert-deftest em-prompt-test/field-properties () "Check that field properties are properly set on Eshell output/prompts." (with-temp-eshell @@ -88,6 +107,8 @@ em-prompt-test--with-multiline (defun em-prompt-test/next-previous-prompt-with () "Helper for checking forward/backward navigation of old prompts." (with-temp-eshell + (let ((debug-on-error nil)) + (eshell-insert-command "(zerop \"foo\")")) ; A failed command. (eshell-insert-command "echo one") (eshell-insert-command "echo two") (eshell-insert-command "echo three") @@ -99,8 +120,11 @@ em-prompt-test/next-previous-prompt-with (end-of-line) (eshell-previous-prompt 2) (should (equal (eshell-get-old-input) "echo one")) - ;; Go forward three prompts. - (eshell-next-prompt 3) + ;; Go back one prompt. + (eshell-previous-prompt 1) + (should (equal (eshell-get-old-input) "(zerop \"foo\")")) + ;; Go forward four prompts. + (eshell-next-prompt 4) (should (equal (eshell-get-old-input) "echo fou")))) (ert-deftest em-prompt-test/next-previous-prompt () @@ -115,6 +139,8 @@ em-prompt-test/next-previous-prompt-multiline (defun em-prompt-test/forward-backward-matching-input-with () "Helper for checking forward/backward navigation via regexps." (with-temp-eshell + (let ((debug-on-error nil)) + (eshell-insert-command "(zerop \"foo\")")) ; A failed command. (eshell-insert-command "echo one") (eshell-insert-command "printnl something else") (eshell-insert-command "echo two") @@ -127,8 +153,11 @@ em-prompt-test/forward-backward-matching-input-with (end-of-line) (eshell-backward-matching-input "echo" 2) (should (equal (eshell-get-old-input) "echo one")) - ;; Go forward three prompts. - (eshell-forward-matching-input "echo" 3) + ;; Go back one prompt. + (eshell-previous-prompt 1) + (should (equal (eshell-get-old-input) "(zerop \"foo\")")) + ;; Go forward four prompts. + (eshell-forward-matching-input "echo" 4) (should (equal (eshell-get-old-input) "echo fou")))) (ert-deftest em-prompt-test/forward-backward-matching-input () -- 2.42.0 --=-=-=--