]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow <mouse-1> in kbd-valid-p
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 17 Oct 2021 19:49:43 +0000 (21:49 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 17 Oct 2021 19:49:43 +0000 (21:49 +0200)
* lisp/subr.el (kbd-valid-p): Allow (kbd-valid-p "<mouse-1>").

lisp/subr.el
test/lisp/subr-tests.el

index 635942205b4c29caf31e4e918dad79af232e6910..1da453b30f5763129e8b82e9fbcd4e70dce9ab0c 100644 (file)
@@ -940,26 +940,32 @@ which is
        (string-match-p "\\`[^ ]+\\( [^ ]+\\)*\\'" keys)
        (save-match-data
          (catch 'exit
-           (dolist (key (split-string keys " "))
-             ;; Every key might have these modifiers, and they should be
-             ;; in this order.
-             (when (string-match
-                    "\\`\\(A-\\)?\\(C-\\)?\\(H-\\)?\\(M-\\)?\\(S-\\)?\\(s-\\)?"
-                    key)
-               (setq key (substring key (match-end 0))))
-             (unless (or (and (= (length key) 1)
-                              ;; Don't accept control characters as keys.
-                              (not (< (aref key 0) ?\s))
-                              ;; Don't accept Meta'd characters as keys.
-                              (or (multibyte-string-p key)
-                                  (not (<= 127 (aref key 0) 255))))
-                         (string-match-p "\\`<[A-Za-z0-9]+>\\'" key)
-                         (string-match-p
-                          "\\`\\(NUL\\|RET\\|TAB\\|LFD\\|ESC\\|SPC\\|DEL\\)\\'"
-                          key))
-               ;; Invalid.
-               (throw 'exit nil)))
-           t))))
+           (let ((prefixes
+                  "\\(A-\\)?\\(C-\\)?\\(H-\\)?\\(M-\\)?\\(S-\\)?\\(s-\\)?"))
+             (dolist (key (split-string keys " "))
+               ;; Every key might have these modifiers, and they should be
+               ;; in this order.
+               (when (string-match (concat "\\`" prefixes) key)
+                 (setq key (substring key (match-end 0))))
+               (unless (or (and (= (length key) 1)
+                                ;; Don't accept control characters as keys.
+                                (not (< (aref key 0) ?\s))
+                                ;; Don't accept Meta'd characters as keys.
+                                (or (multibyte-string-p key)
+                                    (not (<= 127 (aref key 0) 255))))
+                           (and (string-match-p "\\`<[-_A-Za-z0-9]+>\\'" key)
+                                ;; Don't allow <M-C-down>.
+                                (= (progn
+                                     (string-match
+                                      (concat "\\`<" prefixes) key)
+                                     (match-end 0))
+                                   1))
+                           (string-match-p
+                            "\\`\\(NUL\\|RET\\|TAB\\|LFD\\|ESC\\|SPC\\|DEL\\)\\'"
+                            key))
+                 ;; Invalid.
+                 (throw 'exit nil)))
+             t)))))
 
 (defun kbd (keys &optional need-vector)
   "Convert KEYS to the internal Emacs key representation.
index 8380e8abfd3a7d6286c043f7a8f3e20121af962e..3e6a7a8bd880ae1a476c5ffb301fe1cceed0aa3b 100644 (file)
   (should (kbd-valid-p "C-M-<return>"))
   (should (not (kbd-valid-p "<C-M-return>")))
 
+  (should (kbd-valid-p "<mouse-1>"))
+  (should (kbd-valid-p "<Scroll_Lock>"))
+
   (should (not (kbd-valid-p "C-xx")))
   (should (not (kbd-valid-p "M-xx")))
   (should (not (kbd-valid-p "M-x<TAB>"))))