GNU bug report logs - #24124
emacs terminal escape command error

Previous Next

Package: emacs;

Reported by: modem <modem <at> member.fsf.org>

Date: Mon, 1 Aug 2016 15:03:02 UTC

Severity: normal

Done: Stefan Kangas <stefan <at> marxist.se>

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 24124 in the body.
You can then email your comments to 24124 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#24124; Package emacs. (Mon, 01 Aug 2016 15:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to modem <modem <at> member.fsf.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 01 Aug 2016 15:03:02 GMT) Full text and rfc822 format available.

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

From: modem <modem <at> member.fsf.org>
To: bug-gnu-emacs <at> gnu.org
Subject: emacs terminal escape command error
Date: Mon, 1 Aug 2016 16:34:43 +0200
Hi,


I am facing a problem with emacs inside tmux.
The problem can be reproduced easily.

Emacs seems to have an terminal issue when being back from background
mode on shell.

Let me explain:
When I put emacs in background (^z) and then in foreground again ("fg",
bash) sometime emacs will not reset properly the terminal and I won't be
able to scroll up (using PageUp/PageDown).

After debugging the issue with a tmux developer, we tracked it down to
emacs and believe this is an emacs issue with terminal handling when
going back from background mode.

I am attaching a snippet of the technical detail about this issue :

>  When you ^Z, tmux gets 112 bytes in all cases:
>
>  input_parse: %0 ground, 40 bytes:
\n\n\033[K\033[?1l\033>\033[34h\033[?25h\033[?1049l\033[39;49m\r
>  input_parse: %0 ground, 72 bytes: \r\n[1]+  Stopped
emacs large_text_file.txt\r\nroot <at> milu:~#
>
>  \033[?1049l is rmcup which exits cursor positioning (alternate
screen) mode.
>
>  Then when you type fg, it gets:
>
>  input_parse: %0 ground, 694 bytes:
\033[?1049h\033[34l\033[?1h\033=\033[24;1H\033[K\033[H\033[?25l\033[3mFile
Edit Options Buffers ...
>
>  \033[?1049h is smcup which turns it on again.
>
>  But sometimes, it gets:
>
>  input_parse: %0 ground, 674 bytes:
\033[24;1H\033[K\033[H\033[?25l\033[3mFile Edit Options Buffers ...
>
>  Where emacs is not sending \033[1049h, or in fact any of the smcup,
>  cvvis, smkx sequence it normally sends.

This can be reproduced by hitting ^z and then "fg" in a loop for a
couples of minutes. If you run tmux with "tmux -vvvv" you will be able
to obtain the logs mentionned above. To observe the problem you can just
press PageUp each time you are back in emacs, when the bug will
reproduce you won't pageUp inside emacs but enter the tmux's copy-mode.
My ~/.tmux.conf only has 1 line:
bind-key -T root PPage if-shell -F "#{alternate_on}" "send-keys PPage"
"copy-mode -e -u"


If you need me to apply some patch and/or reproduce just let me know I
will happily helps.

Thanks a lot,


-- modem




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24124; Package emacs. (Mon, 01 Aug 2016 15:19:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: modem <modem <at> member.fsf.org>
Cc: 24124 <at> debbugs.gnu.org
Subject: Re: bug#24124: emacs terminal escape command error
Date: Mon, 01 Aug 2016 18:18:02 +0300
> From: modem <modem <at> member.fsf.org>
> Date: Mon, 1 Aug 2016 16:34:43 +0200
> 
> When I put emacs in background (^z) and then in foreground again ("fg",
> bash) sometime emacs will not reset properly the terminal and I won't be
> able to scroll up (using PageUp/PageDown).
> 
> After debugging the issue with a tmux developer, we tracked it down to
> emacs and believe this is an emacs issue with terminal handling when
> going back from background mode.
> 
> I am attaching a snippet of the technical detail about this issue :
> 
> >  When you ^Z, tmux gets 112 bytes in all cases:
> >
> >  input_parse: %0 ground, 40 bytes:
> \n\n\033[K\033[?1l\033>\033[34h\033[?25h\033[?1049l\033[39;49m\r
> >  input_parse: %0 ground, 72 bytes: \r\n[1]+  Stopped
> emacs large_text_file.txt\r\nroot <at> milu:~#
> >
> >  \033[?1049l is rmcup which exits cursor positioning (alternate
> screen) mode.
> >
> >  Then when you type fg, it gets:
> >
> >  input_parse: %0 ground, 694 bytes:
> \033[?1049h\033[34l\033[?1h\033=\033[24;1H\033[K\033[H\033[?25l\033[3mFile
> Edit Options Buffers ...
> >
> >  \033[?1049h is smcup which turns it on again.
> >
> >  But sometimes, it gets:
> >
> >  input_parse: %0 ground, 674 bytes:
> \033[24;1H\033[K\033[H\033[?25l\033[3mFile Edit Options Buffers ...
> >
> >  Where emacs is not sending \033[1049h, or in fact any of the smcup,
> >  cvvis, smkx sequence it normally sends.

Probably because Emacs tries to optimize the cursor motion commands
for minimal cost.  See the code of the cmgoto function (in cm.c in
Emacs sources).

But you didn't tell what terminfo entry is used by Emacs on your
system, and didn't tell what the above terminal commands do on your
terminal, so it's hard to proceed in investigating this issue.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24124; Package emacs. (Tue, 02 Aug 2016 15:41:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: modem <modem <at> member.fsf.org>
Cc: 24124 <at> debbugs.gnu.org
Subject: Re: bug#24124: emacs terminal escape command error
Date: Tue, 02 Aug 2016 18:39:57 +0300
[Please keep the bug address on the CC list.]

> From: modem <modem <at> member.fsf.org>
> Date: Tue, 2 Aug 2016 11:47:55 +0200
> 
> Thanks you for your advises.
> 
> My terminfo: "echo $TERM" return "screen". Is that it ?

Probably.

> I recompiled emacs after commenting a few optimization in src/cm.c (cmgoto).
> Unfortunately I can still reproduce the bug with this binary.
> 
> I am attaching you the patch I did.

I think you disabled the wrong code.  What you need is force Emacs to
always do this:

      if (cost <= relcost)
	{	/* really is cheaper */
	  emacs_tputs (tty, p, 1, cmputc);
	  curY (tty) = row, curX (tty) = col;
	  return;
	}




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24124; Package emacs. (Wed, 03 Aug 2016 13:23:01 GMT) Full text and rfc822 format available.

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

From: modem <modem <at> member.fsf.org>
To: 24124 <at> debbugs.gnu.org
Subject: Re: bug#24124: emacs terminal escape command error
Date: Wed, 3 Aug 2016 15:21:24 +0200
[Message part 1 (text/plain, inline)]
> [Please keep the bug address on the CC list.]
>
>> Thanks you for your advises.
>> 
>> My terminfo: "echo $TERM" return "screen". Is that it ?
> 
> Probably.
> 
>> I recompiled emacs after commenting a few optimization in src/cm.c (cmgoto).
>> Unfortunately I can still reproduce the bug with this binary.
>> 
>> I am attaching you the patch I did.
> 
> I think you disabled the wrong code.  What you need is force Emacs to
> always do this:
> 
>       if (cost <= relcost)œ
> 	{	/* really is cheaper */
> 	  emacs_tputs (tty, p, 1, cmputc);
> 	  curY (tty) = row, curX (tty) = col;
> 	  return;
> 	}

Hi Eli,

Thanks a lot. So I did another patch and another try. I can still
reproduce the bug.

Any more advices on stuff I should try are welcomed ;-)


Here is the patch:

--- emacs24-24.4+1.orig/src/cm.c        2014-10-21 23:45:42.000000000 +0200
+++ /dev/shm/cm.c       2016-08-03 15:10:55.803193217 +0200
@@ -327,10 +327,12 @@
     char *p;
     const char *dcm;

+#if 0
   /* First the degenerate case */
     if (row == curY (tty) && col == curX (tty)) /* already there */
     return;
-
+#endif // XXX MODEM
+
     if (curY (tty) >= 0 && curX (tty) >= 0)
     {
       /* We may have quick ways to go to the upper-left, bottom-left,
@@ -375,7 +377,7 @@
    * In the following comparison, the = in <= is because when the costs
    * are the same, it looks nicer (I think) to move directly there.
    */
-  if (directcost <= relcost)
+    if (directcost <= relcost || 1) // XXX MODEM
     {
       /* compute REAL direct cost */
       cost = 0;
@@ -383,14 +385,14 @@
            ? tgoto (dcm, row, col)
            : tgoto (dcm, col, row));
       emacs_tputs (tty, p, 1, evalcost);
-      if (cost <= relcost)
+      if (cost <= relcost || 1) // XXX MODEM
        {       /* really is cheaper */
          emacs_tputs (tty, p, 1, cmputc);
          curY (tty) = row, curX (tty) = col;
          return;
        }
     }
-
+
   switch (use)
     {
     case USEHOME:
[second_try.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24124; Package emacs. (Thu, 04 Aug 2016 17:08:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: modem <modem <at> member.fsf.org>
Cc: 24124 <at> debbugs.gnu.org
Subject: Re: bug#24124: emacs terminal escape command error
Date: Thu, 04 Aug 2016 20:07:16 +0300
> From: modem <modem <at> member.fsf.org>
> Date: Wed, 3 Aug 2016 15:21:24 +0200
> 
> > I think you disabled the wrong code.  What you need is force Emacs to
> > always do this:
> > 
> >       if (cost <= relcost)œ
> > 	{	/* really is cheaper */
> > 	  emacs_tputs (tty, p, 1, cmputc);
> > 	  curY (tty) = row, curX (tty) = col;
> > 	  return;
> > 	}
> 
> Hi Eli,
> 
> Thanks a lot. So I did another patch and another try. I can still
> reproduce the bug.
> 
> Any more advices on stuff I should try are welcomed ;-)

I'm stumped.  It could be some problem with some other piece of
software, not with Emacs.

Is there someone you could ask to produce a human-readable description
of the command Emacs sent to the terminal driver, both in the "good"
and in the "bad" cases?  I mean this citation which you brought
originally, but without any details:

> I am attaching a snippet of the technical detail about this issue :
> 
> >  When you ^Z, tmux gets 112 bytes in all cases:
> >
> >  input_parse: %0 ground, 40 bytes:
> \n\n\033[K\033[?1l\033>\033[34h\033[?25h\033[?1049l\033[39;49m\r
> >  input_parse: %0 ground, 72 bytes: \r\n[1]+  Stopped
> emacs large_text_file.txt\r\nroot <at> milu:~#
> >
> >  \033[?1049l is rmcup which exits cursor positioning (alternate
> screen) mode.
> >
> >  Then when you type fg, it gets:
> >
> >  input_parse: %0 ground, 694 bytes:
> \033[?1049h\033[34l\033[?1h\033=\033[24;1H\033[K\033[H\033[?25l\033[3mFile
> Edit Options Buffers ...
> >
> >  \033[?1049h is smcup which turns it on again.
> >
> >  But sometimes, it gets:
> >
> >  input_parse: %0 ground, 674 bytes:
> \033[24;1H\033[K\033[H\033[?25l\033[3mFile Edit Options Buffers ...
> >
> >  Where emacs is not sending \033[1049h, or in fact any of the smcup,
> >  cvvis, smkx sequence it normally sends.

It would be nice to be able to understand what was meant by whoever
wrote this, as smcup, cvvis, etc. don't tell me much (I'm not a
terminfo expert).

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24124; Package emacs. (Fri, 08 Nov 2019 03:56:01 GMT) Full text and rfc822 format available.

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

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 24124 <at> debbugs.gnu.org, modem <modem <at> member.fsf.org>
Subject: Re: bug#24124: emacs terminal escape command error
Date: Fri, 08 Nov 2019 04:54:53 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> [Please keep the bug address on the CC list.]
>
>> From: modem <modem <at> member.fsf.org>
>> Date: Tue, 2 Aug 2016 11:47:55 +0200
>> 
>> Thanks you for your advises.
>> 
>> My terminfo: "echo $TERM" return "screen". Is that it ?
>
> Probably.
>
>> I recompiled emacs after commenting a few optimization in src/cm.c (cmgoto).
>> Unfortunately I can still reproduce the bug with this binary.
>> 
>> I am attaching you the patch I did.
>
> I think you disabled the wrong code.  What you need is force Emacs to
> always do this:
>
>       if (cost <= relcost)
> 	{	/* really is cheaper */
> 	  emacs_tputs (tty, p, 1, cmputc);
> 	  curY (tty) = row, curX (tty) = col;
> 	  return;
> 	}

That was 3 years ago.  Did you ever get a chance to try the suggested
fix by Eli above?

Best regards,
Stefan Kangas




Reply sent to Stefan Kangas <stefan <at> marxist.se>:
You have taken responsibility. (Sat, 18 Jan 2020 10:53:01 GMT) Full text and rfc822 format available.

Notification sent to modem <modem <at> member.fsf.org>:
bug acknowledged by developer. (Sat, 18 Jan 2020 10:53:02 GMT) Full text and rfc822 format available.

Message #25 received at 24124-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 24124-done <at> debbugs.gnu.org, modem <modem <at> member.fsf.org>
Subject: Re: bug#24124: emacs terminal escape command error
Date: Sat, 18 Jan 2020 11:51:54 +0100
Stefan Kangas <stefan <at> marxist.se> writes:

> That was 3 years ago.  Did you ever get a chance to try the suggested
> fix by Eli above?

More information was requested, but none was given within 10 weeks, so
I'm closing this bug.  If this is still an issue, please reply to this
email (use "Reply to all" in your email client) and we can reopen the
bug report.

Best regards,
Stefan Kangas




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 15 Feb 2020 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 128 days ago.

Previous Next


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