summaryrefslogtreecommitdiff
path: root/src/keymap.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2020-12-29 16:55:06 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2021-01-05 11:28:58 +0100
commit7f16f177270e8e69cb8b78fb502caae3653a32cf (patch)
tree457b69dbfefe25efde1217b8432ac882986b65c7 /src/keymap.c
parente6617f0dffbb1ca7a72287621c9c38c8a72145aa (diff)
downloademacs-7f16f177270e8e69cb8b78fb502caae3653a32cf.tar.gz
Pretty-print keys without <> around modifiers (bug#45536)
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 <>. * doc/lispref/help.texi (Describing Characters): Update example. * doc/lispref/debugging.texi (Backtraces): * doc/lispref/minibuf.texi (Text from Minibuffer): Use @kbd instead of @key. * etc/NEWS: Announce the change. * test/src/keymap-tests.el (keymap--key-description): * test/lisp/subr-tests.el (subr--kbd): New tests.
Diffstat (limited to 'src/keymap.c')
-rw-r--r--src/keymap.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/keymap.c b/src/keymap.c
index 37270f5782b..3d1993869bc 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2188,11 +2188,21 @@ See `text-char-description' for describing character codes. */)
{
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;
}