Subject: Re: bug#65604: [PATCH] Display the exit code if the last command failed in Eshell

From: Eli Zaretskii <[email-masked]>
Date: Wed, 30 Aug 2023 19:45:29 +0300

> Cc: [email-masked], [email-masked]
> Date: Wed, 30 Aug 2023 17:34:51 +0200
> From:  Eshel Yaron via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> I suggest a small rephrase to avoid the passive voice:
> "Eshell now displays the exit code of the last command in the mode line
> when it's non-zero."

Always try to avoid possible confusion due to wrong attribution (does
"it's" refer to the mode line or to the last command or to the exit
code?).  So:

  If a command exits abnormally, Eshel now displays its exit code on
  the mode line.

> Also, shouldn't this also be mentioned in the manual?

Of course, it should!

> > +(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))
> > +
> 
> You should be able to use an `:eval` mode line construct here instead of
> resetting `mode-line-process` after each command this way.  This would
> allow other code to extend modify `mode-line-process` as well, without
> having the modification undone after each command.

Why do you meed :eval at all?  AFAIR, having a symbol in the mode line
automatically uses its current value when the mode line is redrawn.