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

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

bug#27407: 25.2; SGR reset is ignored if it terminates Eshell's output


From: npostavs
Subject: bug#27407: 25.2; SGR reset is ignored if it terminates Eshell's output
Date: Sat, 17 Jun 2017 14:19:54 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux)

tags 27407 + patch
severity 27407 minor
quit

Pierre Neidhardt <ambrevar@gmail.com> writes:

> Steps to reproduce:
>
> - M-x eshell
> - Enter "hello"
>
> The new prompt becomes yellow.

You meant enter the text produced with (insert "echo \"\e[33mhello\e[0m\"").

> It does not happen if the SGR reset sequence is not last.
> This is fine for instance:
>
> - echo "hello"X
> - echo -n "hello"
>
> Maybe an off-by-one error in the `ansi-*' function?

The escape code is implemented by applying an overlay to the text
following it (see `ansi-color-apply-on-region').  The problem seems to
be that the reset sequence is translated to no face, so nothing is
applied (see `ansi-color-apply-overlay-face'), and the yellow overlay
gets extended despite the `ansi-color-freeze-overlay' modification-hook
because `eshell-output-filter' (and `eshell-send-input') let-bind
`inhibit-modification-hooks'.

I'm not sure why `inhibit-modification-hooks' needs to be let-bound at
all, but just binding it to nil around string insertion seems to be
enough:

>From 6e3892b8044fc918a5231a79963d0560adea2403 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 17 Jun 2017 12:06:37 -0400
Subject: [PATCH v1] Let ansi-color overlay hooks work in eshell (Bug#27407)

* lisp/ansi-color.el (ansi-color-make-extent): Add
`ansi-color-freeze-overlay' to `insert-behind-hooks' as well.
* lisp/eshell/esh-mode.el (eshell-output-filter): Let-bind
`inhibit-modification-hooks' to nil while inserting the string.
---
 lisp/ansi-color.el      | 1 +
 lisp/eshell/esh-mode.el | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/ansi-color.el b/lisp/ansi-color.el
index a1b4933175..72d70c2102 100644
--- a/lisp/ansi-color.el
+++ b/lisp/ansi-color.el
@@ -481,6 +481,7 @@ (defun ansi-color-make-extent (from to &optional object)
     ;; property to make sure it works.
     (let ((overlay (make-overlay from to object)))
       (overlay-put overlay 'modification-hooks '(ansi-color-freeze-overlay))
+      (overlay-put overlay 'insert-behind-hooks '(ansi-color-freeze-overlay))
       overlay)))
 
 (defun ansi-color-freeze-overlay (overlay is-after begin end &optional len)
diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el
index 0fd0c18301..0999f9c4a8 100644
--- a/lisp/eshell/esh-mode.el
+++ b/lisp/eshell/esh-mode.el
@@ -726,7 +726,9 @@ (defun eshell-output-filter (process string)
                  (setq obeg (+ obeg nchars)))
              (if (<= (point) oend)
                  (setq oend (+ oend nchars)))
-             (insert-before-markers string)
+              ;; Let the ansi-color overlay hooks run.
+              (let ((inhibit-modification-hooks nil))
+                (insert-before-markers string))
              (if (= (window-start) (point))
                  (set-window-start (selected-window)
                                    (- (point) nchars)))
-- 
2.11.1


reply via email to

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