Ensure gerneral-implicit-kbd=t in map!

Also updates map! tests (TODO: abstract all those cdr-caddr's!)
This commit is contained in:
Henrik Lissner 2018-12-22 17:11:20 -05:00
parent 954b0f9c5d
commit 4383531b32
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 67 additions and 67 deletions

View file

@ -324,7 +324,8 @@ Example
(:when IS-MAC (:when IS-MAC
:n \"M-s\" 'some-fn :n \"M-s\" 'some-fn
:i \"M-o\" (lambda (interactive) (message \"Hi\"))))" :i \"M-o\" (lambda (interactive) (message \"Hi\"))))"
(doom--map-process rest)) `(let ((general-implicit-kbd t))
,(doom--map-process rest)))
(provide 'core-keybinds) (provide 'core-keybinds)
;;; core-keybinds.el ends here ;;; core-keybinds.el ends here

View file

@ -1,7 +1,6 @@
;; -*- no-byte-compile: t; -*- ;; -*- no-byte-compile: t; -*-
;;; core/test/test-core-keybinds.el ;;; core/test/test-core-keybinds.el
(describe "core/keybinds" (describe "core/keybinds"
(describe "map!" (describe "map!"
:var (doom--map-evil-p doom-map-states) :var (doom--map-evil-p doom-map-states)
@ -17,23 +16,23 @@
(describe "Single keybinds" (describe "Single keybinds"
(it "binds a global key" (it "binds a global key"
(expect (macroexpand '(map! "C-." #'a)) (expect (caddr (macroexpand '(map! "C-." #'a)))
:to-equal '(general-define-key "C-." #'a))) :to-equal '(general-define-key "C-." #'a)))
(it "binds a key in one evil state" (it "binds a key in one evil state"
(dolist (state doom-map-states) (dolist (state doom-map-states)
(expect (macroexpand `(map! ,(car state) "C-." #'a)) (expect (caddr (macroexpand `(map! ,(car state) "C-." #'a)))
:to-equal `(general-define-key :states ',(cdr state) "C-." #'a)))) :to-equal `(general-define-key :states ',(cdr state) "C-." #'a))))
(it "binds a key in multiple evil states" (it "binds a key in multiple evil states"
(expect (cdr (macroexpand `(map! :nvi "C-." #'a))) (expect (cdr (caddr (macroexpand `(map! :nvi "C-." #'a))))
:to-have-same-items-as :to-have-same-items-as
'((general-define-key :states 'normal "C-." #'a) '((general-define-key :states 'normal "C-." #'a)
(general-define-key :states 'visual "C-." #'a) (general-define-key :states 'visual "C-." #'a)
(general-define-key :states 'insert "C-." #'a)))) (general-define-key :states 'insert "C-." #'a))))
(it "binds evil keybinds together with global keybinds" (it "binds evil keybinds together with global keybinds"
(expect (macroexpand '(map! :ng "C-." #'a)) (expect (caddr (macroexpand '(map! :ng "C-." #'a)))
:to-equal :to-equal
'(progn '(progn
(general-define-key :states 'normal "C-." #'a) (general-define-key :states 'normal "C-." #'a)
@ -41,18 +40,18 @@
(describe "Multiple keybinds" (describe "Multiple keybinds"
(it "binds global keys and preserves order" (it "binds global keys and preserves order"
(expect (macroexpand '(map! "C-." #'a (expect (caddr (macroexpand '(map! "C-." #'a
"C-," #'b "C-," #'b
"C-/" #'c)) "C-/" #'c)))
:to-equal '(general-define-key "C-." #'a :to-equal '(general-define-key "C-." #'a
"C-," #'b "C-," #'b
"C-/" #'c))) "C-/" #'c)))
(it "binds multiple keybinds in an evil state and preserve order" (it "binds multiple keybinds in an evil state and preserve order"
(dolist (state doom-map-states) (dolist (state doom-map-states)
(expect (macroexpand `(map! ,(car state) "a" #'a (expect (caddr (macroexpand `(map! ,(car state) "a" #'a
,(car state) "b" #'b ,(car state) "b" #'b
,(car state) "c" #'c)) ,(car state) "c" #'c)))
:to-equal :to-equal
`(general-define-key :states ',(cdr state) `(general-define-key :states ',(cdr state)
"a" #'a "a" #'a
@ -60,31 +59,31 @@
"c" #'c)))) "c" #'c))))
(it "binds multiple keybinds in different evil states" (it "binds multiple keybinds in different evil states"
(expect (cdr (macroexpand `(map! :n "a" #'a (expect (cdr (caddr (macroexpand `(map! :n "a" #'a
:n "b" #'b :n "b" #'b
:n "e" #'e :n "e" #'e
:v "c" #'c :v "c" #'c
:i "d" #'d))) :i "d" #'d))))
:to-have-same-items-as :to-have-same-items-as
`((general-define-key :states 'insert "d" #'d) `((general-define-key :states 'insert "d" #'d)
(general-define-key :states 'visual "c" #'c) (general-define-key :states 'visual "c" #'c)
(general-define-key :states 'normal "a" #'a "b" #'b "e" #'e)))) (general-define-key :states 'normal "a" #'a "b" #'b "e" #'e))))
(it "groups multi-state keybinds while preserving same-group key order" (it "groups multi-state keybinds while preserving same-group key order"
(expect (cdr (macroexpand `(map! :n "a" #'a (expect (cdr (caddr (macroexpand `(map! :n "a" #'a
:v "c" #'c :v "c" #'c
:n "b" #'b :n "b" #'b
:i "d" #'d :i "d" #'d
:n "e" #'e))) :n "e" #'e))))
:to-have-same-items-as :to-have-same-items-as
`((general-define-key :states 'insert "d" #'d) `((general-define-key :states 'insert "d" #'d)
(general-define-key :states 'visual "c" #'c) (general-define-key :states 'visual "c" #'c)
(general-define-key :states 'normal "a" #'a "b" #'b "e" #'e)))) (general-define-key :states 'normal "a" #'a "b" #'b "e" #'e))))
(it "binds multiple keybinds in multiple evil states" (it "binds multiple keybinds in multiple evil states"
(expect (cdr (macroexpand `(map! :nvi "a" #'a (expect (cdr (caddr (macroexpand `(map! :nvi "a" #'a
:nvi "b" #'b :nvi "b" #'b
:nvi "c" #'c))) :nvi "c" #'c))))
:to-have-same-items-as :to-have-same-items-as
'((general-define-key :states 'normal "a" #'a "b" #'b "c" #'c) '((general-define-key :states 'normal "a" #'a "b" #'b "c" #'c)
(general-define-key :states 'visual "a" #'a "b" #'b "c" #'c) (general-define-key :states 'visual "a" #'a "b" #'b "c" #'c)
@ -92,18 +91,18 @@
(describe "Nested keybinds" (describe "Nested keybinds"
(it "binds global keys" (it "binds global keys"
(expect (macroexpand '(map! "C-." #'a (expect (caddr (macroexpand '(map! "C-." #'a
("C-a" #'b) ("C-a" #'b)
("C-x" #'c))) ("C-x" #'c))))
:to-equal '(progn :to-equal '(progn
(general-define-key "C-." #'a) (general-define-key "C-." #'a)
(general-define-key "C-a" #'b) (general-define-key "C-a" #'b)
(general-define-key "C-x" #'c)))) (general-define-key "C-x" #'c))))
(it "binds nested evil keybinds" (it "binds nested evil keybinds"
(expect (macroexpand '(map! :n "C-." #'a (expect (caddr (macroexpand '(map! :n "C-." #'a
(:n "C-a" #'b) (:n "C-a" #'b)
(:n "C-x" #'c))) (:n "C-x" #'c))))
:to-equal :to-equal
'(progn '(progn
(general-define-key :states 'normal "C-." #'a) (general-define-key :states 'normal "C-." #'a)
@ -111,9 +110,9 @@
(general-define-key :states 'normal "C-x" #'c)))) (general-define-key :states 'normal "C-x" #'c))))
(it "binds global keybinds in between evil keybinds" (it "binds global keybinds in between evil keybinds"
(expect (cdr (macroexpand-1 '(map! :n "a" #'a (expect (cdr (caddr (macroexpand-1 '(map! :n "a" #'a
"b" #'b "b" #'b
:i "c" #'c))) :i "c" #'c))))
:to-have-same-items-as :to-have-same-items-as
'((general-define-key :states 'insert "c" #'c) '((general-define-key :states 'insert "c" #'c)
(general-define-key "b" #'b) (general-define-key "b" #'b)
@ -125,16 +124,16 @@
(it "wraps `general-define-key' in a `after!' block" (it "wraps `general-define-key' in a `after!' block"
(dolist (form '((map! :after helm "a" #'a "b" #'b) (dolist (form '((map! :after helm "a" #'a "b" #'b)
(map! (:after helm "a" #'a "b" #'b)))) (map! (:after helm "a" #'a "b" #'b))))
(expect (macroexpand-1 form) (expect (caddr (macroexpand-1 form))
:to-equal :to-equal
'(after! helm (general-define-key "a" #'a "b" #'b)))) '(after! helm (general-define-key "a" #'a "b" #'b))))
(expect (macroexpand-1 '(map! "a" #'a (:after helm "b" #'b "c" #'c))) (expect (caddr (macroexpand-1 '(map! "a" #'a (:after helm "b" #'b "c" #'c))))
:to-equal :to-equal
'(progn '(progn
(general-define-key "a" #'a) (general-define-key "a" #'a)
(after! helm (after! helm
(general-define-key "b" #'b "c" #'c)))) (general-define-key "b" #'b "c" #'c))))
(expect (macroexpand-1 '(map! (:after helm "b" #'b "c" #'c) "a" #'a)) (expect (caddr (macroexpand-1 '(map! (:after helm "b" #'b "c" #'c) "a" #'a)))
:to-equal :to-equal
'(progn '(progn
(after! helm (after! helm
@ -142,18 +141,18 @@
(general-define-key "a" #'a)))) (general-define-key "a" #'a))))
(it "nests `after!' blocks" (it "nests `after!' blocks"
(expect (macroexpand-1 '(map! :after x "a" #'a (expect (caddr (macroexpand-1 '(map! :after x "a" #'a
(:after y "b" #'b (:after y "b" #'b
(:after z "c" #'c)))) (:after z "c" #'c)))))
:to-equal :to-equal
'(after! x (progn (general-define-key "a" #'a) '(after! x (progn (general-define-key "a" #'a)
(after! y (progn (general-define-key "b" #'b) (after! y (progn (general-define-key "b" #'b)
(after! z (general-define-key "c" #'c)))))))) (after! z (general-define-key "c" #'c))))))))
(it "nests `after!' blocks in other nested blocks" (it "nests `after!' blocks in other nested blocks"
(expect (macroexpand-1 '(map! :after x "a" #'a (expect (caddr (macroexpand-1 '(map! :after x "a" #'a
(:when t "b" #'b (:when t "b" #'b
(:after z "c" #'c)))) (:after z "c" #'c)))))
:to-equal :to-equal
'(after! x '(after! x
(progn (progn
@ -165,75 +164,75 @@
(describe ":desc" (describe ":desc"
(it "add a :which-key property to a keybind's DEF" (it "add a :which-key property to a keybind's DEF"
(expect (macroexpand-1 '(map! :desc "A" "a" #'a)) (expect (caddr (macroexpand-1 '(map! :desc "A" "a" #'a)))
:to-equal `(general-define-key "a" (list :def #'a :which-key "A"))))) :to-equal `(general-define-key "a" (list :def #'a :which-key "A")))))
(describe ":if/:when/:unless" (describe ":if/:when/:unless"
(it "wraps keys in a conditional block" (it "wraps keys in a conditional block"
(dolist (prop '(:if :when :unless)) (dolist (prop '(:if :when :unless))
(let ((prop-fn (intern (doom-keyword-name prop)))) (let ((prop-fn (intern (doom-keyword-name prop))))
(expect (macroexpand-1 `(map! ,prop t "a" #'a "b" #'b)) (expect (caddr (macroexpand-1 `(map! ,prop t "a" #'a "b" #'b)))
:to-equal `(,prop-fn t (general-define-key "a" #'a "b" #'b))) :to-equal `(,prop-fn t (general-define-key "a" #'a "b" #'b)))
(expect (macroexpand-1 `(map! (,prop t "a" #'a "b" #'b))) (expect (caddr (macroexpand-1 `(map! (,prop t "a" #'a "b" #'b))))
:to-equal `(,prop-fn t (general-define-key "a" #'a "b" #'b)))))) :to-equal `(,prop-fn t (general-define-key "a" #'a "b" #'b))))))
(it "nests conditional blocks" (it "nests conditional blocks"
(expect (macroexpand-1 '(map! (:when t "a" #'a (:when t "b" #'b)))) (expect (caddr (macroexpand-1 '(map! (:when t "a" #'a (:when t "b" #'b)))))
:to-equal '(when t :to-equal '(when t
(progn (general-define-key "a" #'a) (progn (general-define-key "a" #'a)
(when t (general-define-key "b" #'b))))))) (when t (general-define-key "b" #'b)))))))
(describe ":leader" (describe ":leader"
(it "uses leader definer" (it "uses leader definer"
(expect (macroexpand-1 '(map! :leader "a" #'a "b" #'b)) (expect (caddr (macroexpand-1 '(map! :leader "a" #'a "b" #'b)))
:to-equal '(general-define-key :definer 'leader "a" #'a "b" #'b))) :to-equal '(define-leader-key! "a" #'a "b" #'b)))
(it "it persists for nested keys" (it "it persists for nested keys"
(expect (cdr (macroexpand-1 '(map! :leader "a" #'a ("b" #'b)))) (expect (cdr (caddr (macroexpand-1 '(map! :leader "a" #'a ("b" #'b)))))
:to-equal '((general-define-key :definer 'leader "a" #'a) :to-equal '((define-leader-key! "a" #'a)
(general-define-key :definer 'leader "b" #'b))))) (define-leader-key! "b" #'b)))))
(describe ":localleader" (describe ":localleader"
(it "uses localleader definer" (it "uses localleader definer"
(expect (macroexpand-1 '(map! :localleader "a" #'a "b" #'b)) (expect (caddr (macroexpand-1 '(map! :localleader "a" #'a "b" #'b)))
:to-equal '(general-define-key :definer 'localleader "a" #'a "b" #'b))) :to-equal '(define-localleader-key! "a" #'a "b" #'b)))
(it "it persists for nested keys" (it "it persists for nested keys"
(expect (cdr (macroexpand-1 '(map! :localleader "a" #'a ("b" #'b)))) (expect (cdr (caddr (macroexpand-1 '(map! :localleader "a" #'a ("b" #'b)))))
:to-equal '((general-define-key :definer 'localleader "a" #'a) :to-equal '((define-localleader-key! "a" #'a)
(general-define-key :definer 'localleader "b" #'b))))) (define-localleader-key! "b" #'b)))))
(describe ":map/:keymap" (describe ":map/:keymap"
(it "specifies a single keymap for keys" (it "specifies a single keymap for keys"
(expect (macroexpand-1 '(map! :map emacs-lisp-mode-map "a" #'a)) (expect (caddr (macroexpand-1 '(map! :map emacs-lisp-mode-map "a" #'a)))
:to-equal :to-equal
'(general-define-key :keymaps '(emacs-lisp-mode-map) "a" #'a))) '(general-define-key :keymaps '(emacs-lisp-mode-map) "a" #'a)))
(it "specifies multiple keymap for keys" (it "specifies multiple keymap for keys"
(expect (macroexpand-1 '(map! :map (lisp-mode-map emacs-lisp-mode-map) "a" #'a)) (expect (caddr (macroexpand-1 '(map! :map (lisp-mode-map emacs-lisp-mode-map) "a" #'a)))
:to-equal :to-equal
'(general-define-key :keymaps '(lisp-mode-map emacs-lisp-mode-map) "a" #'a)))) '(general-define-key :keymaps '(lisp-mode-map emacs-lisp-mode-map) "a" #'a))))
(describe ":mode" (describe ":mode"
(it "appends -map to MODE" (it "appends -map to MODE"
(expect (macroexpand-1 '(map! :mode emacs-lisp-mode "a" #'a)) (expect (caddr (macroexpand-1 '(map! :mode emacs-lisp-mode "a" #'a)))
:to-equal :to-equal
'(general-define-key :keymaps '(emacs-lisp-mode-map) "a" #'a)))) '(general-define-key :keymaps '(emacs-lisp-mode-map) "a" #'a))))
(describe ":prefix" (describe ":prefix"
(it "specifies a prefix for all keys" (it "specifies a prefix for all keys"
(expect (macroexpand-1 '(map! :prefix "a" "x" #'x "y" #'y "z" #'z)) (expect (caddr (macroexpand-1 '(map! :prefix "a" "x" #'x "y" #'y "z" #'z)))
:to-equal :to-equal
'(general-define-key :prefix "a" "x" #'x "y" #'y "z" #'z))) '(general-define-key :prefix "a" "x" #'x "y" #'y "z" #'z)))
(it "overwrites previous inline :prefix properties" (it "overwrites previous inline :prefix properties"
(expect (cdr (macroexpand-1 '(map! :prefix "a" "x" #'x "y" #'y :prefix "b" "z" #'z))) (expect (cdr (caddr (macroexpand-1 '(map! :prefix "a" "x" #'x "y" #'y :prefix "b" "z" #'z))))
:to-equal :to-equal
'((general-define-key :prefix "a" "x" #'x "y" #'y) '((general-define-key :prefix "a" "x" #'x "y" #'y)
(general-define-key :prefix "b" "z" #'z)))) (general-define-key :prefix "b" "z" #'z))))
(it "accumulates keys when nested" (it "accumulates keys when nested"
(expect (cdr (macroexpand-1 '(map! (:prefix "a" "x" #'x (:prefix "b" "x" #'x))))) (expect (cdr (caddr (macroexpand-1 '(map! (:prefix "a" "x" #'x (:prefix "b" "x" #'x))))))
:to-equal :to-equal
`((general-define-key :prefix "a" "x" #'x) `((general-define-key :prefix "a" "x" #'x)
(general-define-key :prefix (general--concat t "a" "b") (general-define-key :prefix (general--concat t "a" "b")
@ -241,18 +240,18 @@
(describe ":alt-prefix" (describe ":alt-prefix"
(it "specifies a prefix for all keys" (it "specifies a prefix for all keys"
(expect (macroexpand-1 '(map! :alt-prefix "a" "x" #'x "y" #'y "z" #'z)) (expect (caddr (macroexpand-1 '(map! :alt-prefix "a" "x" #'x "y" #'y "z" #'z)))
:to-equal :to-equal
'(general-define-key :non-normal-prefix "a" "x" #'x "y" #'y "z" #'z))) '(general-define-key :non-normal-prefix "a" "x" #'x "y" #'y "z" #'z)))
(it "overwrites previous inline :alt-prefix properties" (it "overwrites previous inline :alt-prefix properties"
(expect (cdr (macroexpand-1 '(map! :alt-prefix "a" "x" #'x "y" #'y :alt-prefix "b" "z" #'z))) (expect (cdr (caddr (macroexpand-1 '(map! :alt-prefix "a" "x" #'x "y" #'y :alt-prefix "b" "z" #'z))))
:to-equal :to-equal
'((general-define-key :non-normal-prefix "a" "x" #'x "y" #'y) '((general-define-key :non-normal-prefix "a" "x" #'x "y" #'y)
(general-define-key :non-normal-prefix "b" "z" #'z)))) (general-define-key :non-normal-prefix "b" "z" #'z))))
(it "accumulates keys when nested" (it "accumulates keys when nested"
(expect (cdr (macroexpand-1 '(map! (:alt-prefix "a" "x" #'x (:alt-prefix "b" "x" #'x))))) (expect (cdr (caddr (macroexpand-1 '(map! (:alt-prefix "a" "x" #'x (:alt-prefix "b" "x" #'x))))))
:to-equal :to-equal
`((general-define-key :non-normal-prefix "a" "x" #'x) `((general-define-key :non-normal-prefix "a" "x" #'x)
(general-define-key :non-normal-prefix (general--concat t "a" "b") (general-define-key :non-normal-prefix (general--concat t "a" "b")
@ -260,7 +259,7 @@
(describe ":textobj" (describe ":textobj"
(it "defines keys in evil-{inner,outer}-text-objects-map" (it "defines keys in evil-{inner,outer}-text-objects-map"
(expect (macroexpand-1 '(map! :textobj "a" #'inner #'outer)) (expect (caddr (macroexpand-1 '(map! :textobj "a" #'inner #'outer)))
:to-equal :to-equal
'(map! (:map evil-inner-text-objects-map "a" #'inner) '(map! (:map evil-inner-text-objects-map "a" #'inner)
(:map evil-outer-text-objects-map "a" #'outer)))))))) (:map evil-outer-text-objects-map "a" #'outer))))))))