* bug#74854: [PATCH] Improve menu separator display on ttys slightly
@ 2024-12-13 15:09 Gerd Möllmann
2024-12-13 16:16 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Gerd Möllmann @ 2024-12-13 15:09 UTC (permalink / raw)
To: 74854
[-- Attachment #1: Type: text/plain, Size: 1030 bytes --]
Tags: patch
Improvements:
1. Separators are displayed as lines over the whole menu, not
only as "--".
2. Support for 3 types of separators: --space -> line
of spaces, --double-line -> line of '=', others -> line of '-'
In GNU Emacs 31.0.50 (build 15, aarch64-apple-darwin24.2.0) of
2024-12-13 built on pro2
Repository revision: 7bf7e339a4ae5b253623ee62b71ba50786339490
Repository branch: cl-packages
System Description: macOS 15.2
Configured using:
'configure --without-ns --cache-file
/var/folders/1d/k_6t25f94sl83szqbf8gpkrh0000gn/T//config.cache.cl-packages
--with-native-compilation --with-mps=yes CC=clang
'CFLAGS=-Wgnu-imaginary-constant -Wunused-result -g
-fno-omit-frame-pointer -F
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
-Wno-ignored-attributes -Wno-flag-enum -Wno-missing-method-return-type
-Wno-variadic-macros -Wno-strict-prototypes -Wno-availability
-Wno-nullability-completeness' --prefix=/Users/gerd/.local'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-menu-separator-display-on-ttys-slightly.patch --]
[-- Type: text/patch, Size: 3432 bytes --]
From 18e01b73e72b8aa36bd995d29317e9834c53f868 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd@gnu.org>
Date: Fri, 13 Dec 2024 15:54:21 +0100
Subject: [PATCH] Improve menu separator display on ttys slightly
* src/xdisp.c (display_tty_menu_separator): New function displaying
separators with '-', '=', or ' '.
(display_tty_menu_item): Use it.
---
src/xdisp.c | 44 +++++++++++++++++++++++++++++++++-----------
1 file changed, 33 insertions(+), 11 deletions(-)
diff --git a/src/xdisp.c b/src/xdisp.c
index 1bfc4bb1797..e9f9fcc16f6 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -27249,6 +27249,34 @@ deep_copy_glyph_row (struct frame *f, struct glyph_row *to, struct glyph_row *fr
fill_up_frame_row_with_spaces (f, to, to_used);
}
+/* Produce glyphs for a menu separator on a tty.
+
+ FIXME: This is only a "good enough for now" implementation of
+ menu separators as described in the Elisp info manual. We
+ should probably ignore menu separators when computing the width
+ of a menu. Secondly, we could draw actual horizontal lines of
+ different styles on ttys, maybe optionally using Unicode
+ characters via display table entries. Patches very welcome. */
+
+static void
+display_tty_menu_separator (struct it *it, const char *label, int width)
+{
+ static char sep[200];
+ char c;
+ if (strcmp (label, "--space") == 0)
+ c = ' ';
+ else if (strcmp (label, "--double-line") == 0)
+ c = '=';
+ else
+ c = '-';
+ memset (sep, c, sizeof sep);
+ sep[sizeof sep - 1] = 0;
+ display_string (sep, Qnil, Qnil, 0, 0, it, width - 1, width - 1,
+ FRAME_COLS (it->f) - 1, -1);
+ display_string (" ", Qnil, Qnil, 0, 0, it, 1, 0,
+ FRAME_COLS (it->f) - 1, -1);
+}
+
/* Display one menu item on a TTY, by overwriting the glyphs in the
frame F's desired glyph matrix with glyphs produced from the menu
item text. Called from term.c to display TTY drop-down menus one
@@ -27323,6 +27351,7 @@ display_tty_menu_item (const char *item_text, int width, int face_id,
/* Pad with a space on the left. */
display_string (" ", Qnil, Qnil, 0, 0, &it, 1, 0, FRAME_COLS (f) - 1, -1);
width--;
+
/* Display the menu item, pad with spaces to WIDTH. */
if (submenu)
{
@@ -27333,20 +27362,13 @@ display_tty_menu_item (const char *item_text, int width, int face_id,
display_string (" >", Qnil, Qnil, 0, 0, &it, width, 0,
FRAME_COLS (f) - 1, -1);
}
- else if (menu_separator_name_p (item_text))
+ else if (menu_separator_name_p (item_text))
{
- /* FIXME: This is only a "good enough for now" implementation of
- menu separators as described in the Elisp info manual. We
- should probably ignore menu separators when computing the width
- of a menu. Secondly, we could draw actual horizontal lines of
- different styles on ttys, maybe optionally using Unicode
- characters via display table entries. Patches very welcome. */
- display_string ("--", Qnil, Qnil, 0, 0, &it, width, 0,
- FRAME_COLS (f) - 1, -1);
+ display_tty_menu_separator (&it, item_text, width);
}
else
- display_string (item_text, Qnil, Qnil, 0, 0, &it,
- width, 0, FRAME_COLS (f) - 1, -1);
+ display_string (item_text, Qnil, Qnil, 0, 0, &it, width, 0,
+ FRAME_COLS (f) - 1, -1);
row->used[TEXT_AREA] = max (saved_used, row->used[TEXT_AREA]);
row->truncated_on_right_p = saved_truncated;
--
2.47.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#74854: [PATCH] Improve menu separator display on ttys slightly
2024-12-13 15:09 bug#74854: [PATCH] Improve menu separator display on ttys slightly Gerd Möllmann
@ 2024-12-13 16:16 ` Eli Zaretskii
2024-12-13 17:24 ` Gerd Möllmann
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-12-13 16:16 UTC (permalink / raw)
To: Gerd Möllmann; +Cc: 74854
> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> Date: Fri, 13 Dec 2024 16:09:30 +0100
>
> Improvements:
>
> 1. Separators are displayed as lines over the whole menu, not
> only as "--".
>
> 2. Support for 3 types of separators: --space -> line
> of spaces, --double-line -> line of '=', others -> line of '-'
Thanks.
> +static void
> +display_tty_menu_separator (struct it *it, const char *label, int width)
> +{
> + static char sep[200];
Why 200? GNU Coding Standards frown on arbitrary limits.
How about using alloca with 'width' as its argument?
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#74854: [PATCH] Improve menu separator display on ttys slightly
2024-12-13 16:16 ` Eli Zaretskii
@ 2024-12-13 17:24 ` Gerd Möllmann
2024-12-14 7:15 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Gerd Möllmann @ 2024-12-13 17:24 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 74854
[-- Attachment #1: Type: text/plain, Size: 127 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
> How about using alloca with 'width' as its argument?
Good point, new patch attached.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-menu-separator-display-on-ttys-slightly-bug-.patch --]
[-- Type: text/x-patch, Size: 3424 bytes --]
From 6c7c4623674646c33a7b4738de3533ccaa65c9ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <gerd@gnu.org>
Date: Fri, 13 Dec 2024 15:54:21 +0100
Subject: [PATCH] Improve menu separator display on ttys slightly (bug#74854)
* src/xdisp.c (display_tty_menu_separator): New function displaying
separators with '-', '=', or ' '.
(display_tty_menu_item): Use it.
---
src/xdisp.c | 45 ++++++++++++++++++++++++++++++++++-----------
1 file changed, 34 insertions(+), 11 deletions(-)
diff --git a/src/xdisp.c b/src/xdisp.c
index 1bfc4bb1797..bbe4210d734 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -27249,6 +27249,35 @@ deep_copy_glyph_row (struct frame *f, struct glyph_row *to, struct glyph_row *fr
fill_up_frame_row_with_spaces (f, to, to_used);
}
+/* Produce glyphs for a menu separator on a tty.
+
+ FIXME: This is only a "good enough for now" implementation of menu
+ separators as described in the Elisp info manual. We should probably
+ ignore menu separators when computing the width of a menu. Secondly,
+ optionally using Unicode characters via display table entries would
+ be nice. Patches very welcome. */
+
+static void
+display_tty_menu_separator (struct it *it, const char *label, int width)
+{
+ USE_SAFE_ALLOCA;
+ char c;
+ if (strcmp (label, "--space") == 0)
+ c = ' ';
+ else if (strcmp (label, "--double-line") == 0)
+ c = '=';
+ else
+ c = '-';
+ char *sep = SAFE_ALLOCA (width);
+ memset (sep, c, width - 1);
+ sep[width - 1] = 0;
+ display_string (sep, Qnil, Qnil, 0, 0, it, width - 1, width - 1,
+ FRAME_COLS (it->f) - 1, -1);
+ display_string (" ", Qnil, Qnil, 0, 0, it, 1, 0,
+ FRAME_COLS (it->f) - 1, -1);
+ SAFE_FREE ();
+}
+
/* Display one menu item on a TTY, by overwriting the glyphs in the
frame F's desired glyph matrix with glyphs produced from the menu
item text. Called from term.c to display TTY drop-down menus one
@@ -27323,6 +27352,7 @@ display_tty_menu_item (const char *item_text, int width, int face_id,
/* Pad with a space on the left. */
display_string (" ", Qnil, Qnil, 0, 0, &it, 1, 0, FRAME_COLS (f) - 1, -1);
width--;
+
/* Display the menu item, pad with spaces to WIDTH. */
if (submenu)
{
@@ -27333,20 +27363,13 @@ display_tty_menu_item (const char *item_text, int width, int face_id,
display_string (" >", Qnil, Qnil, 0, 0, &it, width, 0,
FRAME_COLS (f) - 1, -1);
}
- else if (menu_separator_name_p (item_text))
+ else if (menu_separator_name_p (item_text))
{
- /* FIXME: This is only a "good enough for now" implementation of
- menu separators as described in the Elisp info manual. We
- should probably ignore menu separators when computing the width
- of a menu. Secondly, we could draw actual horizontal lines of
- different styles on ttys, maybe optionally using Unicode
- characters via display table entries. Patches very welcome. */
- display_string ("--", Qnil, Qnil, 0, 0, &it, width, 0,
- FRAME_COLS (f) - 1, -1);
+ display_tty_menu_separator (&it, item_text, width);
}
else
- display_string (item_text, Qnil, Qnil, 0, 0, &it,
- width, 0, FRAME_COLS (f) - 1, -1);
+ display_string (item_text, Qnil, Qnil, 0, 0, &it, width, 0,
+ FRAME_COLS (f) - 1, -1);
row->used[TEXT_AREA] = max (saved_used, row->used[TEXT_AREA]);
row->truncated_on_right_p = saved_truncated;
--
2.47.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* bug#74854: [PATCH] Improve menu separator display on ttys slightly
2024-12-13 17:24 ` Gerd Möllmann
@ 2024-12-14 7:15 ` Eli Zaretskii
2024-12-14 7:25 ` Gerd Möllmann
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-12-14 7:15 UTC (permalink / raw)
To: Gerd Möllmann; +Cc: 74854
> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> Cc: 74854@debbugs.gnu.org
> Date: Fri, 13 Dec 2024 18:24:24 +0100
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > How about using alloca with 'width' as its argument?
>
> Good point, new patch attached.
Thanks, this LGTM. Feel free to install on master.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#74854: [PATCH] Improve menu separator display on ttys slightly
2024-12-14 7:15 ` Eli Zaretskii
@ 2024-12-14 7:25 ` Gerd Möllmann
0 siblings, 0 replies; 5+ messages in thread
From: Gerd Möllmann @ 2024-12-14 7:25 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 74854
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Gerd Möllmann <gerd.moellmann@gmail.com>
>> Cc: 74854@debbugs.gnu.org
>> Date: Fri, 13 Dec 2024 18:24:24 +0100
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> > How about using alloca with 'width' as its argument?
>>
>> Good point, new patch attached.
>
> Thanks, this LGTM. Feel free to install on master.
Thanks for the review! Pushed, and closing.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-12-14 7:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-13 15:09 bug#74854: [PATCH] Improve menu separator display on ttys slightly Gerd Möllmann
2024-12-13 16:16 ` Eli Zaretskii
2024-12-13 17:24 ` Gerd Möllmann
2024-12-14 7:15 ` Eli Zaretskii
2024-12-14 7:25 ` Gerd Möllmann
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).