GNU bug report logs - #31662
[PATCH] fix double counting bug in term.el

Previous Next

Package: emacs;

Reported by: John Shahid <jvshahid <at> gmail.com>

Date: Thu, 31 May 2018 04:51:01 UTC

Severity: normal

Tags: fixed, patch

Found in version 27.0.50

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 31662 in the body.
You can then email your comments to 31662 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#31662; Package emacs. (Thu, 31 May 2018 04:51:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to John Shahid <jvshahid <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 31 May 2018 04:51:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: John Shahid <jvshahid <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] fix double counting bug in term.el
Date: Thu, 31 May 2018 04:49:53 +0000
[Message part 1 (text/plain, inline)]
Hi all,

Today I was trying to run fzf[1] in term when I ran into a weird issue
that will cause the term output to be clobbered with certain output. The
root cause seems to be a double counting in the column offset. This is
usually fine, unless `2*len(inserted text)' causes the point to be equal
to the window width. I fixed the issue and added a new test in the
attached patch

[1] https://github.com/junegunn/fzf

[0001-lisp-term.el-term-emulate-terminal-fix-column-double.patch (text/x-diff, inline)]
From efeec7bb556084f7004a83faf679f724bb8a0fe8 Mon Sep 17 00:00:00 2001
From: John Shahid <jvshahid <at> gmail.com>
Date: Wed, 30 May 2018 23:55:16 -0400
Subject: [PATCH] * lisp/term.el (term-emulate-terminal): fix column double
 counting

---
 lisp/term.el            | 3 ++-
 test/lisp/term-tests.el | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/term.el b/lisp/term.el
index 19e68ddb49..67cebda1be 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -2904,7 +2904,8 @@ term-emulate-terminal
                   (when (not (or (eobp) term-insert-mode))
                     (let ((pos (point)))
                       (term-move-columns columns)
-                      (delete-region pos (point))))
+                      (delete-region pos (point))
+                      (term-move-columns (- columns))))
                   ;; In insert mode if the current line
                   ;; has become too long it needs to be
                   ;; chopped off.
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index 8aaa61a210..e27dd0354d 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -89,6 +89,13 @@ term-test-screen-from-input
                                               "\e[2;1Hc"
                                               "\e[1;2Hb"
                                               "\e[1;1Ha") "" t))))
+  (should (equal "abcde    j"
+                 (term-test-screen-from-input
+                  10 12 (concat "\e[mabcdefghij"
+                                "\e[H"  ;move back to point-min
+                                "\e[mabcde"
+                                "\e[m    j"))))
+
   ;; Relative positioning.
   (should (equal "ab\ncd"
                  (term-test-screen-from-input
-- 
2.17.0


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31662; Package emacs. (Thu, 31 May 2018 22:52:01 GMT) Full text and rfc822 format available.

Message #8 received at 31662 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: John Shahid <jvshahid <at> gmail.com>
Cc: 31662 <at> debbugs.gnu.org
Subject: Re: bug#31662: [PATCH] fix double counting bug in term.el
Date: Thu, 31 May 2018 18:51:06 -0400
John Shahid <jvshahid <at> gmail.com> writes:
>                    (when (not (or (eobp) term-insert-mode))
>                      (let ((pos (point)))
>                        (term-move-columns columns)
> -                      (delete-region pos (point))))
> +                      (delete-region pos (point))
> +                      (term-move-columns (- columns))))

I think it's a better idea to just reset term-current-column to nil,
like what happens in Emacs 26.

> +  (should (equal "abcde    j"
> +                 (term-test-screen-from-input
> +                  10 12 (concat "\e[mabcdefghij"
> +                                "\e[H"  ;move back to point-min
> +                                "\e[mabcde"
> +                                "\e[m    j"))))
> +

The "\e[m" is just to make the strings get processed separately, right?
You can pass a list of strings instead:

    (term-test-screen-from-input
     10 12 (list "abcdefghij"
                 "\e[H" ;move back to point-min
                 "abcde"
                 "    j"))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31662; Package emacs. (Fri, 01 Jun 2018 02:52:01 GMT) Full text and rfc822 format available.

Message #11 received at 31662 <at> debbugs.gnu.org (full text, mbox):

From: John Shahid <jvshahid <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 31662 <at> debbugs.gnu.org
Subject: Re: bug#31662: [PATCH] fix double counting bug in term.el
Date: Fri, 01 Jun 2018 02:51:11 +0000
[Message part 1 (text/plain, inline)]
Thanks for the feedback. I fixed both issues in the attached patch.

Noam Postavsky <npostavs <at> gmail.com> writes:

> John Shahid <jvshahid <at> gmail.com> writes:
>>                    (when (not (or (eobp) term-insert-mode))
>>                      (let ((pos (point)))
>>                        (term-move-columns columns)
>> -                      (delete-region pos (point))))
>> +                      (delete-region pos (point))
>> +                      (term-move-columns (- columns))))
>
> I think it's a better idea to just reset term-current-column to nil,
> like what happens in Emacs 26.
>
>> +  (should (equal "abcde    j"
>> +                 (term-test-screen-from-input
>> +                  10 12 (concat "\e[mabcdefghij"
>> +                                "\e[H"  ;move back to point-min
>> +                                "\e[mabcde"
>> +                                "\e[m    j"))))
>> +
>
> The "\e[m" is just to make the strings get processed separately, right?
> You can pass a list of strings instead:
>
>     (term-test-screen-from-input
>      10 12 (list "abcdefghij"
>                  "\e[H" ;move back to point-min
>                  "abcde"
>                  "    j"))



[0001-lisp-term.el-term-emulate-terminal-fix-column-double.patch (text/x-diff, inline)]
From c9a8ac75923f7b48bcf3285f2c3b6e3a6d9e75b2 Mon Sep 17 00:00:00 2001
From: John Shahid <jvshahid <at> gmail.com>
Date: Wed, 30 May 2018 23:55:16 -0400
Subject: [PATCH] * lisp/term.el (term-emulate-terminal): fix column double
 counting

---
 lisp/term.el            | 3 ++-
 test/lisp/term-tests.el | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/term.el b/lisp/term.el
index 19e68ddb49..715f39bbbf 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -2904,7 +2904,8 @@ term-emulate-terminal
                   (when (not (or (eobp) term-insert-mode))
                     (let ((pos (point)))
                       (term-move-columns columns)
-                      (delete-region pos (point))))
+                      (delete-region pos (point))
+                      (setq term-current-column nil)))
                   ;; In insert mode if the current line
                   ;; has become too long it needs to be
                   ;; chopped off.
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index 8aaa61a210..72a9ad1ef7 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -89,6 +89,13 @@ term-test-screen-from-input
                                               "\e[2;1Hc"
                                               "\e[1;2Hb"
                                               "\e[1;1Ha") "" t))))
+  (should (equal "abcde    j"
+                 (term-test-screen-from-input
+                  10 12 '("abcdefghij"
+                          "\e[H"  ;move back to point-min
+                          "abcde"
+                          "    j"))))
+
   ;; Relative positioning.
   (should (equal "ab\ncd"
                  (term-test-screen-from-input
-- 
2.17.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31662; Package emacs. (Sat, 02 Jun 2018 02:26:01 GMT) Full text and rfc822 format available.

Message #14 received at 31662 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: John Shahid <jvshahid <at> gmail.com>
Cc: 31662 <at> debbugs.gnu.org
Subject: Re: bug#31662: [PATCH] fix double counting bug in term.el
Date: Fri, 01 Jun 2018 22:24:57 -0400
John Shahid <jvshahid <at> gmail.com> writes:

> Thanks for the feedback. I fixed both issues in the attached patch.

Thanks, looks good.

> Subject: [PATCH] * lisp/term.el (term-emulate-terminal): fix column double
>  counting

Minor nitpick ChangeLog formatting nitpick, the sentence should be
capitalized and end with a period.

Have you assigned copyright for Emacs?  (the patch is small enough to go
in regardless, but it would need to be marked as a tiny change)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31662; Package emacs. (Sat, 02 Jun 2018 02:44:02 GMT) Full text and rfc822 format available.

Message #17 received at 31662 <at> debbugs.gnu.org (full text, mbox):

From: John Shahid <jvshahid <at> gmail.com>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: 31662 <at> debbugs.gnu.org
Subject: Re: bug#31662: [PATCH] fix double counting bug in term.el
Date: Sat, 02 Jun 2018 02:43:23 +0000
[Message part 1 (text/plain, inline)]
Noam Postavsky <npostavs <at> gmail.com> writes:

> John Shahid <jvshahid <at> gmail.com> writes:
>
>> Thanks for the feedback. I fixed both issues in the attached patch.
>
> Thanks, looks good.
>
>> Subject: [PATCH] * lisp/term.el (term-emulate-terminal): fix column double
>>  counting
>
> Minor nitpick ChangeLog formatting nitpick, the sentence should be
> capitalized and end with a period.

fixed in the attached patch

>
> Have you assigned copyright for Emacs?  (the patch is small enough to go
> in regardless, but it would need to be marked as a tiny change)

Yes I did. Should I attach the signed assignment to the bug report ?

cheers,

-js

[0001-lisp-term.el-term-emulate-terminal-Fix-column-double.patch (text/x-diff, inline)]
From 26219852992155889e142fb2b45f559ec6318c28 Mon Sep 17 00:00:00 2001
From: John Shahid <jvshahid <at> gmail.com>
Date: Wed, 30 May 2018 23:55:16 -0400
Subject: [PATCH] * lisp/term.el (term-emulate-terminal): Fix column double
 counting.

---
 lisp/term.el            | 3 ++-
 test/lisp/term-tests.el | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lisp/term.el b/lisp/term.el
index 19e68ddb49..715f39bbbf 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -2904,7 +2904,8 @@ term-emulate-terminal
                   (when (not (or (eobp) term-insert-mode))
                     (let ((pos (point)))
                       (term-move-columns columns)
-                      (delete-region pos (point))))
+                      (delete-region pos (point))
+                      (setq term-current-column nil)))
                   ;; In insert mode if the current line
                   ;; has become too long it needs to be
                   ;; chopped off.
diff --git a/test/lisp/term-tests.el b/test/lisp/term-tests.el
index 8aaa61a210..72a9ad1ef7 100644
--- a/test/lisp/term-tests.el
+++ b/test/lisp/term-tests.el
@@ -89,6 +89,13 @@ term-test-screen-from-input
                                               "\e[2;1Hc"
                                               "\e[1;2Hb"
                                               "\e[1;1Ha") "" t))))
+  (should (equal "abcde    j"
+                 (term-test-screen-from-input
+                  10 12 '("abcdefghij"
+                          "\e[H"  ;move back to point-min
+                          "abcde"
+                          "    j"))))
+
   ;; Relative positioning.
   (should (equal "ab\ncd"
                  (term-test-screen-from-input
-- 
2.17.1


Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#31662; Package emacs. (Sat, 02 Jun 2018 03:14:02 GMT) Full text and rfc822 format available.

Message #20 received at 31662 <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> gmail.com>
To: John Shahid <jvshahid <at> gmail.com>
Cc: 31662 <at> debbugs.gnu.org
Subject: Re: bug#31662: [PATCH] fix double counting bug in term.el
Date: Fri, 01 Jun 2018 23:13:01 -0400
found 31662 27.0.50
tags 31662 fixed
close 31662 
quit

John Shahid <jvshahid <at> gmail.com> writes:

>> Minor nitpick ChangeLog formatting nitpick, the sentence should be
>> capitalized and end with a period.
>
> fixed in the attached patch

Thanks, pushed to master [1: 9ac76456eb].  (Actually, I noticed the
commit message had gotten too long, so I edited that a bit more first)

>> Have you assigned copyright for Emacs?  (the patch is small enough to go
>> in regardless, but it would need to be marked as a tiny change)
>
> Yes I did. Should I attach the signed assignment to the bug report ?

No need for that, I just take your word for it.  I'm sure Eli (who has
access to the official list) will step in if anybody lies about it, but
why would they? :)

[1: 9ac76456eb]: 2018-06-01 23:06:34 -0400
  Fix column double counting in term.el (Bug#31662)
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=9ac76456eb104f749aa9c60b99c68a649214efc6




bug Marked as found in versions 27.0.50. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 02 Jun 2018 03:14:02 GMT) Full text and rfc822 format available.

Added tag(s) fixed. Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 02 Jun 2018 03:14:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 31662 <at> debbugs.gnu.org and John Shahid <jvshahid <at> gmail.com> Request was from Noam Postavsky <npostavs <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 02 Jun 2018 03:14:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 30 Jun 2018 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 73 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.