]> git.eshelyaron.com Git - emacs.git/commitdiff
Pretty-print keys without <> around modifiers (bug#45536)
authorMattias Engdegård <mattiase@acm.org>
Tue, 29 Dec 2020 15:55:06 +0000 (16:55 +0100)
committerMattias Engdegård <mattiase@acm.org>
Tue, 5 Jan 2021 10:28:58 +0000 (11:28 +0100)
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.

doc/lispref/debugging.texi
doc/lispref/help.texi
doc/lispref/minibuf.texi
etc/NEWS
src/keymap.c
test/lisp/subr-tests.el
test/src/keymap-tests.el

index 1e779ac705448bb0c179f95b934e8aee0441413a..8e4b0ebfe961f034424749e640215719b004ebc9 100644 (file)
@@ -424,7 +424,7 @@ move to it and type @key{RET}, to visit the source code.  You can also
 type @key{RET} while point is on any name of a function or variable
 which is not underlined, to see help information for that symbol in a
 help buffer, if any exists.  The @code{xref-find-definitions} command,
-bound to @key{M-.}, can also be used on any identifier in a backtrace
+bound to @kbd{M-.}, can also be used on any identifier in a backtrace
 (@pxref{Looking Up Identifiers,,,emacs, The GNU Emacs Manual}).
 
 In backtraces, the tails of long lists and the ends of long strings,
index 2fd05b73917845ce1548acb3483e7b1f556c784f..298bec5230c11c86fa1ffe4baeeb4d7e4bf446a4 100644 (file)
@@ -545,7 +545,7 @@ brackets.
 @end group
 @group
 (single-key-description 'C-mouse-1)
-     @result{} "<C-mouse-1>"
+     @result{} "C-<mouse-1>"
 @end group
 @group
 (single-key-description 'C-mouse-1 t)
index 81139b9e746953006b91f42566e911c42d8a5a06..f0036f0ccfcfb9566b47fe27d572f6f4e6e7f449 100644 (file)
@@ -348,7 +348,7 @@ default, it makes the following bindings:
 @item @key{RET}
 @code{exit-minibuffer}
 
-@item @key{M-<}
+@item @kbd{M-<}
 @code{minibuffer-beginning-of-buffer}
 
 @item @kbd{C-g}
index ef1c4b39a6fb60b2c095f7c30e0198733a1abf98..d1cc422e9f7da0abea82a51ec445b29009cefd44 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -218,6 +218,13 @@ and other "slow scrolling" situations.  It is hoped it behaves better
 than 'fast-but-imprecise-scrolling' and 'jit-lock-defer-time'.
 It is not enabled by default.
 
++++
+** Modifiers now go outside angle brackets in pretty-printed key bindings.
+For example, <return> with Control and Meta modifiers is now shown as
+C-M-<return> instead of <C-M-return>.  Either variant can be used as
+input; functions such as 'kbd' and 'read-kbd-macro' accept both styles
+as equivalent (they have done so for a long time).
+
 \f
 * Editing Changes in Emacs 28.1
 
index 37270f5782b7328f14f3411cb16cd2894b360836..3d1993869bc9a97e2e6e7e8a90043aa631adb459 100644 (file)
@@ -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;
        }
index 2f5b38d05d9a0da51efcb84bbac4da4c30f184e7..8d19a2687738ea90faaf4bb96b4c1b48a11e97c2 100644 (file)
@@ -630,5 +630,13 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
   (should (>= (length (apropos-internal "^help" #'commandp)) 15))
   (should-not (apropos-internal "^next-line$" #'keymapp)))
 
+(ert-deftest subr--kbd ()
+  ;; Check that kbd handles both new and old style key descriptions
+  ;; (bug#45536).
+  (should (equal (kbd "s-<return>") [s-return]))
+  (should (equal (kbd "<s-return>") [s-return]))
+  (should (equal (kbd "C-M-<return>") [C-M-return]))
+  (should (equal (kbd "<C-M-return>") [C-M-return])))
+
 (provide 'subr-tests)
 ;;; subr-tests.el ends here
index 74fb3c892dbf76088c8d6b6c0905aceb48eb5b54..d4f5fc3f190ff9009ed9f7d15a327828d3c00805 100644 (file)
@@ -248,6 +248,18 @@ g .. h             foo
 0 .. 3         foo
 ")))))
 
+(ert-deftest keymap--key-description ()
+  (should (equal (key-description [right] [?\C-x])
+                 "C-x <right>"))
+  (should (equal (key-description [M-H-right] [?\C-x])
+                 "C-x M-H-<right>"))
+  (should (equal (single-key-description 'home)
+                 "<home>"))
+  (should (equal (single-key-description 'home t)
+                 "home"))
+  (should (equal (single-key-description 'C-s-home)
+                 "C-s-<home>")))
+
 (provide 'keymap-tests)
 
 ;;; keymap-tests.el ends here