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 22:20:56 +0200 Message-ID: <87il8ws2aa.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> 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="19864"; mail-complaints-to="usenet@ciao.gmane.io" To: Eli Zaretskii , me@eshelyaron.com, 65604@debbugs.gnu.org, jporterbugs@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Aug 30 22:29:15 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 1qbRoP-0004x0-Qg for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 30 Aug 2023 22:29:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbRo7-0007dI-IG; Wed, 30 Aug 2023 16:28:55 -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 1qbRo6-0007d9-Q5 for bug-gnu-emacs@gnu.org; Wed, 30 Aug 2023 16:28:54 -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 1qbRo6-0007r6-IN for bug-gnu-emacs@gnu.org; Wed, 30 Aug 2023 16:28:54 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qbRoE-0005Ai-7k for bug-gnu-emacs@gnu.org; Wed, 30 Aug 2023 16:29: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: Wed, 30 Aug 2023 20:29: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.169342733319851 (code B ref 65604); Wed, 30 Aug 2023 20:29:02 +0000 Original-Received: (at 65604) by debbugs.gnu.org; 30 Aug 2023 20:28:53 +0000 Original-Received: from localhost ([127.0.0.1]:54191 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qbRo4-0005A4-E5 for submit@debbugs.gnu.org; Wed, 30 Aug 2023 16:28:53 -0400 Original-Received: from out-253.mta0.migadu.com ([2001:41d0:1004:224b::fd]:22702) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qbRo0-00059n-4C for 65604@debbugs.gnu.org; Wed, 30 Aug 2023 16:28:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mssdvd.com; s=key1; t=1693427318; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kJpuS4iRh+eughlhLwURrLAwVpTnHoiuw3atcJdOVhk=; b=vRt4lva4lBfg55i2oJXUe96tY3lJmQ1rK5G/7wXoeDg+MipZz5P1DoBzYojcTAHxoPXdiU DfbJPEUfNY23R/uvZ55L/4u8z6I3ZPOQlYiYT/BYv72UlEtMiFYQrCz6LQVW1JHsphZVMC i0A1T8VAlm9dgQUgvFTlkVmCduQklPqwDFYjDCgsG1cVI0IPihunieqDf+KDUuQPbgJx9i B4lIDLvFzQXF1Fm1hNOiIz4yQmEX2xfWM9ahO56+33RSH/GIV5towY0GN/mCy92edGo5pd piXU71WBQMv0dQTxNzAQ3AdjldYkCU3TyABPT2SdSSH7kK8gEBEZH24EyXIRnA== X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <87msy8s344.fsf@mssdvd.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:268753 Archived-At: --=-=-= Content-Type: text/plain; format=flowed I updated the NEWS file, the manual and used the ":eval" construct to update "mode-line-process". --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Display-the-exit-code-if-the-last-command-failed-in-.patch >From 33e97ff350e1184f97c2867bd689a77291a2c7fd Mon Sep 17 00:00:00 2001 From: Davide Masserut Date: Wed, 30 Aug 2023 21:34:08 +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/esh-io.el (eshell-last-command-status): Make it buffer-local. * lisp/eshell/esh-mode.el (compile): Require it for a face. (eshell-mode): Update mode-line-process based on the exit code of the last command. * test/lisp/eshell/esh-io-tests.el (eshell) (esh-io-test/modeline-after-failure): Add test. --- doc/misc/eshell.texi | 3 +++ etc/NEWS | 3 +++ lisp/eshell/esh-io.el | 2 +- lisp/eshell/esh-mode.el | 12 ++++++++++++ test/lisp/eshell/esh-io-tests.el | 16 ++++++++++++++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/doc/misc/eshell.texi b/doc/misc/eshell.texi index f8f60bae13a..b544e0cda41 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 +on the mode line. + @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 9a98db8c83a..fe81cfc2477 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 on the mode line. + ** Pcomplete --- 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/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 0c381dbb86a..71ff901c764 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -69,6 +69,8 @@ (require 'esh-util) (require 'esh-var) +(require 'compile) + (defgroup eshell-mode nil "This module contains code for handling input from the user." :tag "User interface" @@ -369,6 +371,16 @@ eshell-mode ;; strong R2L character. (setq bidi-paragraph-direction 'left-to-right) + (setq-local + mode-line-process + '(:eval + (when (> eshell-last-command-status 0) + (propertize + (format ":[%s]" eshell-last-command-status) + 'help-echo (format "Last command exited with code %s" + eshell-last-command-status) + 'face 'compilation-mode-line-fail)))) + ;; load extension modules into memory. This will cause any global ;; variables they define to be visible, since some of the core ;; modules sometimes take advantage of their functionality if used. diff --git a/test/lisp/eshell/esh-io-tests.el b/test/lisp/eshell/esh-io-tests.el index ce80f3a8f08..349c4332d82 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,19 @@ 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 + '(:eval + (when (> eshell-last-command-status 0) + (propertize + (format ":[%s]" eshell-last-command-status) + 'help-echo (format "Last command exited with code %s" + eshell-last-command-status) + 'face 'compilation-mode-line-fail))))))) + ;;; esh-io-tests.el ends here -- 2.42.0 --=-=-=--