GNU bug report logs - #62265
Underline does not work in Terminal Emacs

Previous Next

Package: emacs;

Reported by: Mohsin Kaleem <mohkale <at> kisara.moe>

Date: Sat, 18 Mar 2023 17:49:02 UTC

Severity: normal

Merged with 62876

Found in version 28.2

Done: Eli Zaretskii <eliz <at> gnu.org>

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 62265 in the body.
You can then email your comments to 62265 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#62265; Package emacs. (Sat, 18 Mar 2023 17:49:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mohsin Kaleem <mohkale <at> kisara.moe>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 18 Mar 2023 17:49:02 GMT) Full text and rfc822 format available.

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

From: Mohsin Kaleem <mohkale <at> kisara.moe>
To: bug-gnu-emacs <at> gnu.org
Subject: Underline does not work in Terminal Emacs
Date: Sat, 18 Mar 2023 17:40:51 +0000
[Message part 1 (text/plain, inline)]
Hi,

Underline support for tty frames was added to Emacs back in the Emacs
28.0.90 release. It hasn't worked for me since. Today I tried
investigating why. I tracked it down ncurses and discovered the tgetstr
function to retrieve the escape sequence for underline support doesn't
fetch the value configured in the terminfo database for my Terminal
(st). I can reproduce this function failing to fetch the entry in a
minimal sample program (code attached).

[reproduce-smxx-failure.c (text/plain, attachment)]
[Message part 3 (text/plain, inline)]
The cause for this seems to be in ncurses directly. In the definition of
tgetstr in lib_termcap.c there's a check for ValidExt for any
non-standard terminfo entries. This macro fails when fetching an entry
that is longer than 2 characters, meaning tgetstr for "smxx" fails and I
get no underlines. I've managed to fix this by using tigetstr in-place
of tgetstr (this variant is also used for querying the setf24 and setb24
termcaps already in "term.c" so I suspect this is a known issue). I'm
not sure what the termcap library does but I'm guessing it doesn't have
this restriction.

Please fix this by switching to tigetstr instead of tgetstr for this
record when building with terminfo. I've got a sample patch for this
attached.

[fix-underline.patch (text/x-patch, inline)]
diff --git a/src/term.c b/src/term.c
index d881dee39fe..a2d1743bdad 100644
--- a/src/term.c
+++ b/src/term.c
@@ -4163,7 +4163,11 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\
   tty->TS_enter_alt_charset_mode = tgetstr ("as", address);
   tty->TS_exit_alt_charset_mode = tgetstr ("ae", address);
   tty->TS_exit_attribute_mode = tgetstr ("me", address);
+#ifdef TERMINFO
+  tty->TS_enter_strike_through_mode = tigetstr ("smxx");
+#else
   tty->TS_enter_strike_through_mode = tgetstr ("smxx", address);
+#end
 
   MultiUp (tty) = tgetstr ("UP", address);
   MultiDown (tty) = tgetstr ("DO", address);
[Message part 5 (text/plain, inline)]
-- 
Mohsin Kaleem

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sat, 18 Mar 2023 17:52:02 GMT) Full text and rfc822 format available.

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

From: Mohsin Kaleem <mohkale <at> kisara.moe>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: Underline does not work in Terminal Emacs
Date: Sat, 18 Mar 2023 17:51:36 +0000
S.N. Sorry, smxx is the code for strike-through. The error description
should be strikethrough doesn't work in terminal emacs. Not underline.

-- 
Mohsin Kaleem




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sat, 18 Mar 2023 17:56:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mohsin Kaleem <mohkale <at> kisara.moe>
Cc: 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sat, 18 Mar 2023 19:55:03 +0200
> From: Mohsin Kaleem <mohkale <at> kisara.moe>
> Date: Sat, 18 Mar 2023 17:40:51 +0000
> 
> Underline support for tty frames was added to Emacs back in the Emacs
> 28.0.90 release. It hasn't worked for me since. Today I tried
> investigating why. I tracked it down ncurses and discovered the tgetstr
> function to retrieve the escape sequence for underline support doesn't
> fetch the value configured in the terminfo database for my Terminal
> (st). I can reproduce this function failing to fetch the entry in a
> minimal sample program (code attached).
> 
> The cause for this seems to be in ncurses directly. In the definition of
> tgetstr in lib_termcap.c there's a check for ValidExt for any
> non-standard terminfo entries. This macro fails when fetching an entry
> that is longer than 2 characters, meaning tgetstr for "smxx" fails and I
> get no underlines. I've managed to fix this by using tigetstr in-place
> of tgetstr (this variant is also used for querying the setf24 and setb24
> termcaps already in "term.c" so I suspect this is a known issue). I'm
> not sure what the termcap library does but I'm guessing it doesn't have
> this restriction.
> 
> Please fix this by switching to tigetstr instead of tgetstr for this
> record when building with terminfo. I've got a sample patch for this
> attached.

Thanks.  Can someone with access to such a terminal please verify the
issue with ncurses, and also verify the proposed change?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sat, 18 Mar 2023 18:02:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mohsin Kaleem <mohkale <at> kisara.moe>
Cc: 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sat, 18 Mar 2023 20:01:42 +0200
> From: Mohsin Kaleem <mohkale <at> kisara.moe>
> Date: Sat, 18 Mar 2023 17:40:51 +0000
> 
> Underline support for tty frames was added to Emacs back in the Emacs
> 28.0.90 release. It hasn't worked for me since. Today I tried
> investigating why. I tracked it down ncurses and discovered the tgetstr
> function to retrieve the escape sequence for underline support doesn't
> fetch the value configured in the terminfo database for my Terminal
> (st). I can reproduce this function failing to fetch the entry in a
> minimal sample program (code attached).
> [...]
> --- a/src/term.c
> +++ b/src/term.c
> @@ -4163,7 +4163,11 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\
>    tty->TS_enter_alt_charset_mode = tgetstr ("as", address);
>    tty->TS_exit_alt_charset_mode = tgetstr ("ae", address);
>    tty->TS_exit_attribute_mode = tgetstr ("me", address);
> +#ifdef TERMINFO
> +  tty->TS_enter_strike_through_mode = tigetstr ("smxx");
> +#else
>    tty->TS_enter_strike_through_mode = tgetstr ("smxx", address);
> +#end

There's something I don't understand here: you are talking about
underline support, but the proposed patch affects the support for
strike-through, not underline.  What am I missing here?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sat, 18 Mar 2023 18:08:01 GMT) Full text and rfc822 format available.

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

From: Mohsin Kaleem <mohkale <at> kisara.moe>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sat, 18 Mar 2023 18:07:07 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

> There's something I don't understand here: you are talking about
> underline support, but the proposed patch affects the support for
> strike-through, not underline.  What am I missing here?

Hi, yes, I sent a follow up message clarifying my mistake. Just
re-sharing it again:

S.N. Sorry, smxx is the code for strike-through. The error description
should be strikethrough doesn't work in terminal emacs. Not underline.

-- 
Mohsin Kaleem




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sat, 18 Mar 2023 18:51:02 GMT) Full text and rfc822 format available.

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

From: Jim Porter <jporterbugs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>, Mohsin Kaleem <mohkale <at> kisara.moe>
Cc: 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sat, 18 Mar 2023 11:50:35 -0700
On 3/18/2023 10:55 AM, Eli Zaretskii wrote:
> Thanks.  Can someone with access to such a terminal please verify the
> issue with ncurses, and also verify the proposed change?

I'm not sure about the issue with ncurses or this specific terminal, but 
the patch does seem to make strike-through work on the Gnome Terminal. 
Previously, I wasn't able to get strike-through to work, but with this 
patch, it works correctly in Gnome Terminal.

(One easy way to see what happens is to use Org mode and type "+text+" 
into the buffer. That's Org markup for strike-through, and you should 
get a line through "text".)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sun, 19 Mar 2023 10:08:01 GMT) Full text and rfc822 format available.

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

From: Mohsin Kaleem <mohkale <at> kisara.moe>
To: Jim Porter <jporterbugs <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sun, 19 Mar 2023 10:07:14 +0000
[Message part 1 (text/plain, inline)]
Jim Porter <jporterbugs <at> gmail.com> writes:

Hi, so turns out terminfo returns a max-ptr for tigetstr when the
terminfo definition is missing. There's checks for this for setb24 and
setf24 but not in the patch I supplied. Updated to check this and added
a macro definition to avoid repeating the same condition logic 3 times.

[01-fix-terminfo-strikethrough.patch (text/x-patch, inline)]
diff --git a/src/term.c b/src/term.c
index d881dee39fe..c47cdc8bb8a 100644
--- a/src/term.c
+++ b/src/term.c
@@ -95,6 +95,8 @@ #define OUTPUT_IF(tty, a)                                               \
 
 #define OUTPUT1_IF(tty, a) do { if (a) emacs_tputs ((tty), a, 1, cmputc); } while (0)
 
+#define TERMINFO_NON_STRING_CAP_P(cap) ((cap) == (char *) (intptr_t) -1)
+
 /* Display space properties.  */
 
 /* Chain of all tty device parameters.  */
@@ -4163,7 +4165,14 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
   tty->TS_enter_alt_charset_mode = tgetstr ("as", address);
   tty->TS_exit_alt_charset_mode = tgetstr ("ae", address);
   tty->TS_exit_attribute_mode = tgetstr ("me", address);
+#ifdef TERMINFO
+  tty->TS_enter_strike_through_mode = tigetstr ("smxx");
+  if (TERMINFO_NON_STRING_CAP_P (tty->TS_enter_strike_through_mode)) {
+    tty->TS_enter_strike_through_mode = NULL;
+  }
+#else
   tty->TS_enter_strike_through_mode = tgetstr ("smxx", address);
+#endif
 
   MultiUp (tty) = tgetstr ("UP", address);
   MultiDown (tty) = tgetstr ("DO", address);
@@ -4193,8 +4202,8 @@ init_tty (const char *name, const char *terminal_type, bool must_succeed)
 	const char *bg = tigetstr ("setb24");
 	/* Non-standard support for 24-bit colors. */
 	if (fg && bg
-	    && fg != (char *) (intptr_t) -1
-	    && bg != (char *) (intptr_t) -1)
+	    && !TERMINFO_NON_STRING_CAP_P (fg)
+	    && !TERMINFO_NON_STRING_CAP_P (bg))
 	  {
 	    tty->TS_set_foreground = fg;
 	    tty->TS_set_background = bg;
[Message part 3 (text/plain, inline)]
-- 
Mohsin Kaleem

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sun, 19 Mar 2023 11:38:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mohsin Kaleem <mohkale <at> kisara.moe>
Cc: jporterbugs <at> gmail.com, 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sun, 19 Mar 2023 13:37:14 +0200
> From: Mohsin Kaleem <mohkale <at> kisara.moe>
> Cc: 62265 <at> debbugs.gnu.org
> Date: Sun, 19 Mar 2023 10:07:14 +0000
> 
> Hi, so turns out terminfo returns a max-ptr for tigetstr when the
> terminfo definition is missing. There's checks for this for setb24 and
> setf24 but not in the patch I supplied. Updated to check this and added
> a macro definition to avoid repeating the same condition logic 3 times.

Thanks.

However, what about the non-TERMINFO branch?  Do termcap databases
support this capability and tigetstr?  I wonder whether we should do
one of the following:

  . support "smxx" only when TERMINFO is defined
  . support "smxx" regardless of whether TERMINFO is defined

With your patch, it's neither here nor there.  tgetstr is documented
to pay attention only to the first 2 characters of the capability's
name, at least in the ncurses documentation.  If this is generally so
in other curses libraries, then leaving the tgetstr call intact in the
non-TERMINFO case makes no sense.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sun, 19 Mar 2023 11:52:02 GMT) Full text and rfc822 format available.

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

From: Mohsin Kaleem <mohkale <at> kisara.moe>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: jporterbugs <at> gmail.com, 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sun, 19 Mar 2023 11:51:45 +0000
Eli Zaretskii <eliz <at> gnu.org> writes:

> However, what about the non-TERMINFO branch?  Do termcap databases
> support this capability and tigetstr?  I wonder whether we should do
> one of the following:
>
>   . support "smxx" only when TERMINFO is defined
>   . support "smxx" regardless of whether TERMINFO is defined

The latter wouldn't be possible for those using terminfo because of the
issue I described before. I'm okay with the former approach but I
imagine the author of the original TTY strikethrough patch was building
Emacs without terminfo and they described the patch as working for them
so I'd have to conclude termcap does support this (in a non-compliant
ncurses way). Switching to the former approach might break their
workflow since if they build without terminfo they'd lose strikethrough
altogether. I'm happy to test whether this would be the case but not
sure how to. The difference between termcap and terminfo seem kinda
arbitrary to me and I can't find any documentation describing the exact
difference (except this sort of 2 letter restriction in termcap
extensions).

-- 
Mohsin Kaleem




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#62265; Package emacs. (Sun, 19 Mar 2023 12:25:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Mohsin Kaleem <mohkale <at> kisara.moe>, Mike Hamrick <mikeh <at> muppetlabs.com>
Cc: jporterbugs <at> gmail.com, 62265 <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sun, 19 Mar 2023 14:24:19 +0200
> From: Mohsin Kaleem <mohkale <at> kisara.moe>
> Cc: jporterbugs <at> gmail.com, 62265 <at> debbugs.gnu.org
> Date: Sun, 19 Mar 2023 11:51:45 +0000
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > However, what about the non-TERMINFO branch?  Do termcap databases
> > support this capability and tigetstr?  I wonder whether we should do
> > one of the following:
> >
> >   . support "smxx" only when TERMINFO is defined
> >   . support "smxx" regardless of whether TERMINFO is defined
> 
> The latter wouldn't be possible for those using terminfo because of the
> issue I described before. I'm okay with the former approach but I
> imagine the author of the original TTY strikethrough patch was building
> Emacs without terminfo and they described the patch as working for them
> so I'd have to conclude termcap does support this (in a non-compliant
> ncurses way). Switching to the former approach might break their
> workflow since if they build without terminfo they'd lose strikethrough
> altogether. I'm happy to test whether this would be the case but not
> sure how to. The difference between termcap and terminfo seem kinda
> arbitrary to me and I can't find any documentation describing the exact
> difference (except this sort of 2 letter restriction in termcap
> extensions).

If your hypothesis is correct, I'm fine with leaving the non-TERMINFO
branch using tgetstr.  But is it indeed correct?

Let's ask the author of that strikethrough patch.  Mike, can you tell
whether you tested the patch on a system with or without terminfo?
And what, if anything, can you tell about using tgetstr for
capabilities whose names are more than 2 characters -- is that
supported with the curses library you were using at the time?

Thanks.




Merged 62265 62876. Request was from Eli Zaretskii <eliz <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 16 Apr 2023 06:20:02 GMT) Full text and rfc822 format available.

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sun, 16 Apr 2023 06:23:02 GMT) Full text and rfc822 format available.

Notification sent to Mohsin Kaleem <mohkale <at> kisara.moe>:
bug acknowledged by developer. (Sun, 16 Apr 2023 06:23:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: mohkale <at> kisara.moe, mikeh <at> muppetlabs.com
Cc: jporterbugs <at> gmail.com, 62265-done <at> debbugs.gnu.org
Subject: Re: bug#62265: Underline does not work in Terminal Emacs
Date: Sun, 16 Apr 2023 09:22:53 +0300
> Cc: jporterbugs <at> gmail.com, 62265 <at> debbugs.gnu.org
> Date: Sun, 19 Mar 2023 14:24:19 +0200
> From: Eli Zaretskii <eliz <at> gnu.org>
> 
> > From: Mohsin Kaleem <mohkale <at> kisara.moe>
> > Cc: jporterbugs <at> gmail.com, 62265 <at> debbugs.gnu.org
> > Date: Sun, 19 Mar 2023 11:51:45 +0000
> > 
> > Eli Zaretskii <eliz <at> gnu.org> writes:
> > 
> > > However, what about the non-TERMINFO branch?  Do termcap databases
> > > support this capability and tigetstr?  I wonder whether we should do
> > > one of the following:
> > >
> > >   . support "smxx" only when TERMINFO is defined
> > >   . support "smxx" regardless of whether TERMINFO is defined
> > 
> > The latter wouldn't be possible for those using terminfo because of the
> > issue I described before. I'm okay with the former approach but I
> > imagine the author of the original TTY strikethrough patch was building
> > Emacs without terminfo and they described the patch as working for them
> > so I'd have to conclude termcap does support this (in a non-compliant
> > ncurses way). Switching to the former approach might break their
> > workflow since if they build without terminfo they'd lose strikethrough
> > altogether. I'm happy to test whether this would be the case but not
> > sure how to. The difference between termcap and terminfo seem kinda
> > arbitrary to me and I can't find any documentation describing the exact
> > difference (except this sort of 2 letter restriction in termcap
> > extensions).
> 
> If your hypothesis is correct, I'm fine with leaving the non-TERMINFO
> branch using tgetstr.  But is it indeed correct?
> 
> Let's ask the author of that strikethrough patch.  Mike, can you tell
> whether you tested the patch on a system with or without terminfo?
> And what, if anything, can you tell about using tgetstr for
> capabilities whose names are more than 2 characters -- is that
> supported with the curses library you were using at the time?

No further comments, so I've installed a fix for this along the lines
we discussed, and I'm closing this bug.




Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sun, 16 Apr 2023 06:23:02 GMT) Full text and rfc822 format available.

Notification sent to Ivan Kuraj <ivanko <at> csail.mit.edu>:
bug acknowledged by developer. (Sun, 16 Apr 2023 06:23: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. (Mon, 15 May 2023 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 340 days ago.

Previous Next


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