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: Wed, 30 Aug 2023 11:18:49 +0200 Message-ID: <87o7iolg6o.fsf@mssdvd.com> References: <87cyz5wjtm.fsf@mssdvd.com> <05108d35-d095-c975-78b8-6b00fc7e6a08@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="36863"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 65604@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 30 17:11:21 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 1qbMqm-0009NC-MF for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Aug 2023 17:11:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbMqU-0002jB-3k; Wed, 30 Aug 2023 11:11:02 -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 1qbMqS-0002j1-O9 for bug-gnu-emacs@gnu.org; Wed, 30 Aug 2023 11:11:00 -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 1qbMqM-0005Hh-Ip for bug-gnu-emacs@gnu.org; Wed, 30 Aug 2023 11:11:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qbMqT-0005BP-QF for bug-gnu-emacs@gnu.org; Wed, 30 Aug 2023 11:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Davide Masserut Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 30 Aug 2023 15:11:01 +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.169340822819878 (code B ref 65604); Wed, 30 Aug 2023 15:11:01 +0000 Original-Received: (at 65604) by debbugs.gnu.org; 30 Aug 2023 15:10:28 +0000 Original-Received: from localhost ([127.0.0.1]:53759 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qbMpv-0005AY-Ix for submit@debbugs.gnu.org; Wed, 30 Aug 2023 11:10:28 -0400 Original-Received: from out-247.mta1.migadu.com ([2001:41d0:203:375::f7]:53618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qbMpr-0005AL-3i for 65604@debbugs.gnu.org; Wed, 30 Aug 2023 11:10:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mssdvd.com; s=key1; t=1693408212; 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=G35xytxy6VU+wfcKoyeqBnMDVMs/KOd8WT7IZrW8tC0=; b=XdEPkhlMqk51FaThJwgSkJbLILT4m/8TlQqsyg3GJGa+LvV/f1YF6lWp+yT6UWfDRaoVDj FWuRrEm9pyHRW6KMYfdHpIcQosptrMWxlmgXsT2bURyTzRKIxhgWjopUA2SeXisTUnkN0o RQXVf9RU+/UxZ5d7RWg1NmELnJI1ZFekWdoJNdLiJH6zb6nrT3PFYzPJJfZbt+NdoFByqZ kgKf0zX+gEcCdOIqduxuHeecn1PlpyjWQGozWnIcnYu8GOP6UABXPKeTxhBrCIdZtilfU2 wKSGeu+qx9lhBnz2JyGgpjg0GSCv0R0eG//tZ7hmCzznxh2bOQHOrm2pMjWdog== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <05108d35-d095-c975-78b8-6b00fc7e6a08@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:268717 Archived-At: --=-=-= Content-Type: text/plain; format=flowed Jim Porter 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Display-the-exit-code-if-the-last-command-failed-in-.patch >From 8b9f3870e00cdf920e803d92138a9bb0f3c3b645 Mon Sep 17 00:00:00 2001 From: Davide Masserut 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 --=-=-=--