From: Davide Masserut via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Jim Porter <jporterbugs@gmail.com>
Cc: 65604@debbugs.gnu.org
Subject: bug#65604: [PATCH] Display the exit code if the last command failed in Eshell
Date: Wed, 30 Aug 2023 11:18:49 +0200 [thread overview]
Message-ID: <87o7iolg6o.fsf@mssdvd.com> (raw)
In-Reply-To: <05108d35-d095-c975-78b8-6b00fc7e6a08@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 676 bytes --]
Jim Porter <jporterbugs@gmail.com> writes:
> Thanks. I think this makes sense as an option, but I wonder if
> this is
> the right default place to put it. Instead, what about putting
> the
> exit status in the mode-line, like with compilation buffers?
> Eshell
> already uses the mode-line to show when a command is running, so
> I
> think it's an obvious enhancement to show the status of a
> command that
> just finished running. This does mean you don't see the
> *history* of
> failed commands, but it still provides useful feedback for users
> without requiring a change to the prompt (which is a bit more
> in-your-face).
I have made the changes you suggested.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Display-the-exit-code-if-the-last-command-failed-in-.patch --]
[-- Type: text/x-patch, Size: 5045 bytes --]
From 8b9f3870e00cdf920e803d92138a9bb0f3c3b645 Mon Sep 17 00:00:00 2001
From: Davide Masserut <dm@mssdvd.com>
Date: Wed, 30 Aug 2023 16:38:07 +0200
Subject: [PATCH] Display the exit code if the last command failed in Eshell
* etc/NEWS: Announce change.
* lisp/eshell/esh-cmd.el (eshell-exec-lisp):
(eshell-lisp-command): Use new helper function.
* lisp/eshell/esh-io.el:
(eshell-close-handles): Use new helper function.
(eshell-update-last-command-status): Add new helper function.
* test/lisp/eshell/em-io-tests.el
(em-io-test/modeline-after-failure): Add new test.
---
etc/NEWS | 3 +++
lisp/eshell/esh-cmd.el | 8 ++++----
lisp/eshell/esh-io.el | 15 ++++++++++++++-
test/lisp/eshell/esh-io-tests.el | 15 +++++++++++++++
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 9a98db8c83a..810172e3b11 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 the last command failed, its exit code is now displayed in the modeline.
+
** Pcomplete
---
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 80066263396..3672481a66a 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -1407,10 +1407,10 @@ eshell-exec-lisp
;; command status to some non-zero value to indicate an error; to
;; match GNU/Linux, we use 141, which the numeric value of
;; SIGPIPE on GNU/Linux (13) with the high bit (2^7) set.
- (setq eshell-last-command-status 141)
+ (eshell-update-last-command-status 141)
nil)
(error
- (setq eshell-last-command-status 1)
+ (eshell-update-last-command-status 1)
(let ((msg (error-message-string err)))
(if (and (not form-p)
(string-match "^Wrong number of arguments" msg)
@@ -1481,8 +1481,8 @@ eshell-lisp-command
(unless eshell-allow-commands
(signal 'eshell-commands-forbidden '(lisp)))
(catch 'eshell-external ; deferred to an external command
- (setq eshell-last-command-status 0
- eshell-last-arguments args)
+ (eshell-update-last-command-status 0)
+ (setq eshell-last-arguments args)
(let* ((eshell-ensure-newline-p (eshell-interactive-output-p))
(command-form-p (functionp object))
(result
diff --git a/lisp/eshell/esh-io.el b/lisp/eshell/esh-io.el
index c07f871dd37..d734a83e02f 100644
--- a/lisp/eshell/esh-io.el
+++ b/lisp/eshell/esh-io.el
@@ -70,6 +70,7 @@
(require 'esh-arg)
(require 'esh-util)
+(require 'compile)
(eval-when-compile
(require 'cl-lib))
@@ -362,7 +363,7 @@ eshell-close-handles
RESULT is the quoted value of the last command. If nil, then use
the value already set in `eshell-last-command-result'."
(when exit-code
- (setq eshell-last-command-status exit-code))
+ (eshell-update-last-command-status exit-code))
(when result
(cl-assert (eq (car result) 'quote))
(setq eshell-last-command-result (cadr result)))
@@ -670,5 +671,17 @@ eshell-output-object
(dolist (target targets)
(eshell-output-object-to-target object target))))
+(defun eshell-update-last-command-status (exit-code)
+ "Set `eshell-last-command-status' to EXIT-CODE and update `mode-line-process'."
+ (setq mode-line-process
+ (when (> exit-code 0)
+ (list
+ (let ((out-string (format ":[%s]" exit-code))
+ (msg (format "Last command exited with code %s" exit-code)))
+ (propertize out-string
+ 'help-echo msg
+ 'face 'compilation-mode-line-fail))))
+ eshell-last-command-status exit-code))
+
(provide 'esh-io)
;;; esh-io.el ends here
diff --git a/test/lisp/eshell/esh-io-tests.el b/test/lisp/eshell/esh-io-tests.el
index ce80f3a8f08..c134f262007 100644
--- a/test/lisp/eshell/esh-io-tests.el
+++ b/test/lisp/eshell/esh-io-tests.el
@@ -23,6 +23,7 @@
(require 'ert-x)
(require 'esh-mode)
(require 'eshell)
+(require 'compile)
(require 'eshell-tests-helpers
(expand-file-name "eshell-tests-helpers"
@@ -370,4 +371,18 @@ esh-io-test/virtual/dev-kill
(eshell-insert-command "echo three >> /dev/kill")
(should (equal (car kill-ring) "twothree"))))
+(ert-deftest esh-io-test/modeline-after-failure ()
+ "Check that exit code is displayed after a failure."
+ (with-temp-eshell
+ (let ((debug-on-error nil))
+ (eshell-insert-command "(zerop \"foo\")")) ; A failed command.
+ (should (equal-including-properties
+ mode-line-process
+ (list
+ (let ((out-string (format ":[%s]" eshell-last-command-status))
+ (msg (format "Last command exited with code %s" eshell-last-command-status)))
+ (propertize out-string
+ 'help-echo msg
+ 'face 'compilation-mode-line-fail)))))))
+
;;; esh-io-tests.el ends here
--
2.42.0
next prev parent reply other threads:[~2023-08-30 9:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 22:24 bug#65604: [PATCH] Display the exit code if the last command failed in Eshell Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-30 1:52 ` Jim Porter
2023-08-30 9:18 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-08-30 15:26 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-30 15:34 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-30 16:45 ` Eli Zaretskii
2023-08-30 16:58 ` Eli Zaretskii
2023-08-30 19:02 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-30 19:25 ` Eli Zaretskii
2023-08-30 19:59 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-30 20:20 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-31 4:52 ` Eli Zaretskii
2023-08-31 9:31 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-02 5:17 ` Jim Porter
2023-09-02 8:47 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-02 18:40 ` Jim Porter
2023-09-02 18:54 ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-02 22:46 ` Jim Porter
2023-09-10 14:44 ` Sean Whitton
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o7iolg6o.fsf@mssdvd.com \
--to=bug-gnu-emacs@gnu.org \
--cc=65604@debbugs.gnu.org \
--cc=dm@mssdvd.com \
--cc=jporterbugs@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).