emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 99ed1d9b67 2/3: compat-29: Add keymap--check hel


From: ELPA Syncer
Subject: [elpa] externals/compat 99ed1d9b67 2/3: compat-29: Add keymap--check helper, add test
Date: Sun, 8 Jan 2023 08:57:26 -0500 (EST)

branch: externals/compat
commit 99ed1d9b674fd62d20a89758face35d281997dc7
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-29: Add keymap--check helper, add test
---
 compat-29.el    | 25 +++++++++++--------------
 compat-tests.el |  5 +++++
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/compat-29.el b/compat-29.el
index 9d6c68f101..ff99e176ec 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -479,6 +479,11 @@ which is
                (throw 'exit nil)))
            t))))))
 
+(compat-defun keymap--check (key) ;; <OK>
+  "Signal an error if KEY doesn't have a valid syntax."
+  (unless (key-valid-p key)
+    (error "%S is not a valid key definition; see `key-valid-p'" key)))
+
 (compat-defun key-parse (keys) ;; <OK>
   "Convert KEYS to the internal Emacs key representation.
 See `kbd' for a descripion of KEYS."
@@ -590,13 +595,9 @@ DEFINITION is anything that can be a key's definition:
  or a cons (MAP . CHAR), meaning use definition of CHAR in keymap MAP,
  or an extended menu item definition.
  (See info node `(elisp)Extended Menu Items'.)"
-  (unless (key-valid-p key)
-    (error "%S is not a valid key definition; see `key-valid-p'" key))
-  ;; If we're binding this key to another key, then parse that other
-  ;; key, too.
+  (keymap--check key)
   (when (stringp definition)
-    (unless (key-valid-p key)
-      (error "%S is not a valid key definition; see `key-valid-p'" key))
+    (keymap--check definition)
     (setq definition (key-parse definition)))
   (define-key keymap (key-parse key) definition))
 
@@ -609,8 +610,7 @@ makes a difference when there's a parent keymap.  When 
unsetting
 a key in a child map, it will still shadow the same key in the
 parent keymap.  Removing the binding will allow the key in the
 parent keymap to be used."
-  (unless (key-valid-p key)
-    (error "%S is not a valid key definition; see `key-valid-p'" key))
+  (keymap--check key)
   (compat--define-key keymap (key-parse key) nil remove))
 
 (compat-defun keymap-global-set (key command) ;; <UNTESTED>
@@ -709,11 +709,9 @@ Bindings are always added before any inherited map.
 
 The order of bindings in a keymap matters only when it is used as
 a menu, so this function is not useful for non-menu keymaps."
-  (unless (key-valid-p key)
-    (error "%S is not a valid key definition; see `key-valid-p'" key))
+  (keymap--check key)
   (when after
-    (unless (key-valid-p key)
-      (error "%S is not a valid key definition; see `key-valid-p'" key)))
+    (keymap--check after))
   (define-key-after keymap (key-parse key) definition
     (and after (key-parse after))))
 
@@ -750,8 +748,7 @@ position as returned by `event-start' and `event-end', and 
the lookup
 occurs in the keymaps associated with it instead of KEY.  It can also
 be a number or marker, in which case the keymap properties at the
 specified buffer position instead of point are used."
-  (unless (key-valid-p key)
-    (error "%S is not a valid key definition; see `key-valid-p'" key))
+  (keymap--check key)
   (when (and keymap position)
     (error "Can't pass in both keymap and position"))
   (if keymap
diff --git a/compat-tests.el b/compat-tests.el
index 69684582db..e3856dc280 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -316,6 +316,11 @@
   (should-equal (key-parse "<mouse-1>") [mouse-1])
   (should-equal (key-parse "<Scroll_Lock>") [Scroll_Lock]))
 
+(ert-deftest keymap--check ()
+  (keymap--check "X")
+  (should-error (keymap--check ""))
+  (should-error (keymap--check " X")))
+
 (ert-deftest key-valid-p ()
   (should-not (key-valid-p ""))
   (should (key-valid-p "f"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]