all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#45536: [PATCH] Pretty-print keys without <> around modifiers
@ 2020-12-29 16:21 Mattias Engdegård
  2020-12-29 18:31 ` Drew Adams
  2020-12-29 20:01 ` Eli Zaretskii
  0 siblings, 2 replies; 27+ messages in thread
From: Mattias Engdegård @ 2020-12-29 16:21 UTC (permalink / raw)
  To: 45536

[-- Attachment #1: Type: text/plain, Size: 607 bytes --]

It is a bit inconsistent that keys are described as C-x and <return> but <C-return>. It would be more logical to write C-<return>. The key parser will happily accept either, but descriptions without modifiers in <> brackets are more legible, and the result is easier to understand and explain.

Attached is a patch which adapts the code that pretty-prints keys. This is a change for human consumption only; it seems unlikely to affect compatibility. With the patch, <C-M-backspace> is now printed as C-M-<backspace>.

I'd be happy to update the manuals accordingly, and add a NEWS entry if required.


[-- Attachment #2: 0001-Pretty-print-keys-without-around-modifiers.patch --]
[-- Type: application/octet-stream, Size: 1702 bytes --]

From 18c9fc433f75a286abcd459abb77b2667d650021 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Tue, 29 Dec 2020 16:55:06 +0100
Subject: [PATCH] Pretty-print keys without <> around modifiers

Be consistent when pretty-printing keys: put modifiers outside <>,
thus the more logical C-M-<return> instead of <C-M-return>.

* src/keymap.c (Fsingle_key_description):
Skip modifier prefix before adding <>.
---
 src/keymap.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/keymap.c b/src/keymap.c
index ca2d33dba4..d3cde8e7ab 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2260,11 +2260,21 @@ DEFUN ("single-key-description", Fsingle_key_description,
     {
       if (NILP (no_angles))
 	{
-	  Lisp_Object result;
-	  char *buffer = SAFE_ALLOCA (sizeof "<>"
-				      + SBYTES (SYMBOL_NAME (key)));
-	  esprintf (buffer, "<%s>", SDATA (SYMBOL_NAME (key)));
-	  result = build_string (buffer);
+	  Lisp_Object namestr = SYMBOL_NAME (key);
+	  const char *sym = SSDATA (namestr);
+	  ptrdiff_t len = SBYTES (namestr);
+	  /* Find the extent of the modifier prefix, like "C-M-". */
+	  int i = 0;
+	  while (i < len - 3 && sym[i + 1] == '-' && strchr ("CMSsHA", sym[i]))
+	    i += 2;
+	  /* First I bytes of SYM are modifiers; put <> around the rest. */
+	  char *buffer = SAFE_ALLOCA (len + 3);
+	  memcpy (buffer, sym, i);
+	  buffer[i] = '<';
+	  memcpy (buffer + i + 1, sym + i, len - i);
+	  buffer [len + 1] = '>';
+	  buffer [len + 2] = '\0';
+	  Lisp_Object result = build_string (buffer);
 	  SAFE_FREE ();
 	  return result;
 	}
-- 
2.21.1 (Apple Git-122.3)


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2021-05-17 15:11 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-29 16:21 bug#45536: [PATCH] Pretty-print keys without <> around modifiers Mattias Engdegård
2020-12-29 18:31 ` Drew Adams
2020-12-29 19:50   ` Mattias Engdegård
2020-12-29 20:14     ` Drew Adams
2020-12-29 20:01 ` Eli Zaretskii
2020-12-29 22:27   ` Mattias Engdegård
2020-12-30  3:54   ` Lars Ingebrigtsen
2020-12-30  9:52     ` Mattias Engdegård
2020-12-31  4:35       ` Lars Ingebrigtsen
2020-12-31  9:59         ` Mattias Engdegård
2020-12-31 12:29           ` Mattias Engdegård
2021-01-01 10:46             ` Lars Ingebrigtsen
2021-01-01 11:51               ` Mattias Engdegård
2021-01-01 11:54                 ` Lars Ingebrigtsen
2021-01-02 17:20                   ` Mattias Engdegård
2021-01-02 18:25                     ` Drew Adams
2021-01-05 10:52                       ` Mattias Engdegård
2021-01-05 10:47                     ` Mattias Engdegård
2021-05-17 15:11                       ` Lars Ingebrigtsen
2021-01-01 12:00               ` Eli Zaretskii
2021-01-01 12:10                 ` Mattias Engdegård
2021-01-01 12:28                   ` Eli Zaretskii
2021-01-01 12:43                     ` Mattias Engdegård
2021-01-01 12:54                       ` Eli Zaretskii
2021-01-01 13:29                         ` Mattias Engdegård
2021-01-01 13:34                           ` Eli Zaretskii
2021-01-01 19:41               ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.