bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27361: Re: bug#27361: 24.4; eshell/echo silently ignores -n argument


From: Jim Porter
Subject: bug#27361: Re: bug#27361: 24.4; eshell/echo silently ignores -n argument
Date: Sat, 15 Jan 2022 23:19:50 -0800

On 9/15/2020 8:27 AM, Lars Ingebrigtsen wrote:
Glenn Morris <rgm@gnu.org> writes:

-      (concat (apply 'eshell-flatten-and-stringify args) "\n")
+      (concat (apply 'eshell-flatten-and-stringify args)
+             (unless output-newline "\n"))

Hm...  with or without the patch, and with eshell-plain-echo-behavior
set, I don't see any difference?

I still get this in eshell:

~/src/emacs/trunk $ echo -n foo; echo bar
foo
bar

I think this is due to `eshell-lisp-command' insisting that a newline is inserted after the output of *every* Lisp command (when executed interactively). It's easier to see what "-n" does by eval'ing:

  (eshell-command-result "echo hi")
  ;; and
  (eshell-command-result "echo -n hi")

One solution to this bug would be to set `eshell-ensure-newline-p' to nil inside `eshell-echo'; then it will opt out of `eshell-lisp-command's trailing-newline insertion.

I've attached a patch that does this, as well as (hopefully) resolving the unusual meaning of "-n" when echo outputs a Lisp-friendly result (i.e. when `eshell-plain-echo-behavior' is nil). Now, it warns the user to use "-N" instead if they want to add a trailing newline. Then, one day, the old meaning of "-n" can be removed. I'm not sure if this is the best way to emit a warning about this though; I wanted something that doesn't interfere with any Eshell scripts, but `display-warning' is a bit in-your-face.

I also simplified the logic of `eshell/printnl'. Since the way it called `eshell-echo' always resulted in it printing the stringified form of each argument, it's simpler just to call `eshell-stringify' directly.

Finally, I added a bit more detail about echo to the Eshell manual (taken partly from the commentary of eshell/em-basic.el), since I didn't quite understand its behavior initially.

Attachment: 0001-In-Eshell-allow-n-to-suppress-the-trailing-newline-f.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]