(compiler-macro (lambda (form) (keymap--compile-check key) form)))
(keymap--check key)
(when (eq after t) (setq after nil)) ; nil and t are treated the same
- (when after
- (keymap--check after))
+ (when (stringp after)
+ (keymap--check after)
+ (setq after (key-parse after)))
+ ;; If we're binding this key to another key, then parse that other
+ ;; key, too.
+ (when (stringp definition)
+ (keymap--check definition)
+ (setq definition (key-parse definition)))
(define-key-after keymap (key-parse key) definition
- (and after (key-parse after))))
+ after))
(defun key-parse (keys)
"Convert KEYS to the internal Emacs key representation.
(defun keymap-tests--command-1 () (interactive) nil)
(defun keymap-tests--command-2 () (interactive) nil)
+(defun keymap-tests--command-3 () (interactive) nil)
(put 'keymap-tests--command-1 :advertised-binding [?y])
(ert-deftest keymap-where-is-internal ()
(should-not (keymap-set-after k "f" "f" "a"))
(should (equal (keymap-lookup k "f") (key-parse "f")))))
+(ert-deftest keymap-set-after-menus ()
+ (let ((map (make-sparse-keymap)))
+ (keymap-set map "<cmd1>"
+ '(menu-item "Run Command 1" keymap-tests--command-1
+ :help "Command 1 Help"))
+ (keymap-set-after map "<cmd2>"
+ '(menu-item "Run Command 2" keymap-tests--command-2
+ :help "Command 2 Help"))
+ (keymap-set-after map "<cmd3>"
+ '(menu-item "Run Command 3" keymap-tests--command-3
+ :help "Command 3 Help")
+ 'cmd1)
+ (should (equal (caadr map) 'cmd1))
+ (should (equal (caaddr map) 'cmd3))
+ (should (equal (caar (last map)) 'cmd2))))
+
(ert-deftest keymap-test-duplicate-definitions ()
"Check that defvar-keymap rejects duplicate key definitions."
(should-error