Refactor map! macro
This commit is contained in:
parent
a55b3c599b
commit
71061aefa1
1 changed files with 10 additions and 12 deletions
|
@ -179,7 +179,6 @@ Examples:
|
||||||
|
|
||||||
(defmacro map! (&rest rest)
|
(defmacro map! (&rest rest)
|
||||||
(let ((i 0)
|
(let ((i 0)
|
||||||
(forms '())
|
|
||||||
(keymaps (if (boundp 'keymaps) keymaps))
|
(keymaps (if (boundp 'keymaps) keymaps))
|
||||||
(default-keymaps '((current-global-map)))
|
(default-keymaps '((current-global-map)))
|
||||||
(state-map '(("n" . normal)
|
(state-map '(("n" . normal)
|
||||||
|
@ -190,13 +189,12 @@ Examples:
|
||||||
("m" . motion)
|
("m" . motion)
|
||||||
("r" . replace)))
|
("r" . replace)))
|
||||||
(prefix (if (boundp 'prefix) prefix))
|
(prefix (if (boundp 'prefix) prefix))
|
||||||
key def states)
|
key def states forms)
|
||||||
(unless keymaps
|
(unless keymaps
|
||||||
(setq keymaps default-keymaps))
|
(setq keymaps default-keymaps))
|
||||||
(while rest
|
(while rest
|
||||||
(setq key (pop rest))
|
(setq key (pop rest))
|
||||||
(add-to-list
|
(push
|
||||||
'forms
|
|
||||||
(cond ((listp key) ; it's a sub exp
|
(cond ((listp key) ; it's a sub exp
|
||||||
`(,(macroexpand `(map! ,@key))))
|
`(,(macroexpand `(map! ,@key))))
|
||||||
|
|
||||||
|
@ -209,12 +207,12 @@ Examples:
|
||||||
(setq key :prefix))
|
(setq key :prefix))
|
||||||
(pcase key
|
(pcase key
|
||||||
;; TODO: Data checks
|
;; TODO: Data checks
|
||||||
(:prefix (setq prefix (concat prefix (kbd (pop rest)))) nil)
|
(:prefix (setq prefix (concat prefix (kbd (pop rest)))) nil)
|
||||||
(:map (setq keymaps (-list (pop rest))) nil)
|
(:map (setq keymaps (-list (pop rest))) nil)
|
||||||
(:unset `(,(macroexpand `(map! ,(kbd (pop rest)) nil))))
|
(:unset `(,(macroexpand `(map! ,(kbd (pop rest)) nil))))
|
||||||
(:after (prog1 `((after! ,(pop rest) ,(macroexpand `(map! ,@rest)))) (setq rest '())))
|
(:after (prog1 `((after! ,(pop rest) ,(macroexpand `(map! ,@rest)))) (setq rest '())))
|
||||||
(:when (prog1 `((if ,(pop rest) ,(macroexpand `(map! ,@rest)))) (setq rest '())))
|
(:when (prog1 `((if ,(pop rest) ,(macroexpand `(map! ,@rest)))) (setq rest '())))
|
||||||
(:unless (prog1 `((if (not ,(pop rest)) ,(macroexpand `(map! ,@rest)))) (setq rest '())))
|
(:unless (prog1 `((if (not ,(pop rest)) ,(macroexpand `(map! ,@rest)))) (setq rest '())))
|
||||||
(otherwise ; might be a state prefix
|
(otherwise ; might be a state prefix
|
||||||
(mapc (lambda (letter)
|
(mapc (lambda (letter)
|
||||||
(if (assoc letter state-map)
|
(if (assoc letter state-map)
|
||||||
|
@ -246,9 +244,9 @@ Examples:
|
||||||
out-forms))
|
out-forms))
|
||||||
|
|
||||||
(t (user-error "Invalid key %s" key)))
|
(t (user-error "Invalid key %s" key)))
|
||||||
t)
|
forms)
|
||||||
(cl-incf i))
|
(cl-incf i))
|
||||||
`(progn ,@(apply #'nconc (delete nil (delete (list nil) forms)))))))
|
`(progn ,@(apply #'nconc (delete nil (delete (list nil) (reverse forms))))))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue