]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/keymap.el (define-keymap): Demote "duplicate def" to a warning
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 12 Jan 2024 23:05:14 +0000 (18:05 -0500)
committerEshel Yaron <me@eshelyaron.com>
Sun, 21 Jan 2024 07:30:15 +0000 (08:30 +0100)
* test/src/keymap-tests.el (keymap-test-duplicate-definitions):
Adjust accordingly.

(cherry picked from commit eb779ae64677e643d2d78cfc2b016088e8d7ff98)

lisp/keymap.el
test/src/keymap-tests.el

index 065c59da74c930718be9a001b834b8ae76717642..d2544e30ce0f57253c30677f0aed0972d0af3740 100644 (file)
@@ -577,9 +577,15 @@ should be a MENU form as accepted by `easy-menu-define'.
           (let ((def (pop definitions)))
             (if (eq key :menu)
                 (easy-menu-define nil keymap "" def)
-              (if (member key seen-keys)
-                  (error "Duplicate definition for key: %S %s" key keymap)
-                (push key seen-keys))
+              (when (member key seen-keys)
+                ;; Since the keys can be computed dynamically, it can
+                ;; very well happen that we get duplicate definitions
+                ;; due to some unfortunate configuration rather than
+                ;; due to an actual bug.  While such duplicates are
+                ;; not desirable, they shouldn't prevent the users
+                ;; from getting their job done.
+                (message "Duplicate definition for key: %S %s" key keymap))
+              (push key seen-keys)
               (keymap-set keymap key def)))))
       keymap)))
 
index bc9977f31bf2f167d3026ac791927530e40fac6d..04b897045dbb2f91de73cba83027a9dcf92df2d4 100644 (file)
@@ -23,6 +23,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'cl-lib)
 
 (defun keymap-tests--make-keymap-test (fun)
   (should (eq (car (funcall fun)) 'keymap))
@@ -470,10 +471,18 @@ g .. h            foo
        ert-keymap-duplicate
        "a" #'next-line
        "a" #'previous-line))
-  (should-error
-   (define-keymap
-       "a" #'next-line
-       "a" #'previous-line)))
+  (let ((msg ""))
+    ;; FIXME: It would be nicer to use `current-message' rather than override
+    ;; `message', but `current-message' returns always nil in batch mode :-(
+    (cl-letf (((symbol-function 'message)
+               (lambda (fmt &rest args) (setq msg (apply #'format fmt args)))))
+      (should
+       (string-match "duplicate"
+                     (progn
+                       (define-keymap
+                         "a" #'next-line
+                         "a" #'previous-line)
+                       msg))))))
 
 (ert-deftest keymap-unset-test-remove-and-inheritance ()
   "Check various behaviors of keymap-unset.  (Bug#62207)"