以下代码
;;;use (define-key state (kbd "xxx") (kbd "yyy")) style map
(macrolet ((keymap (state &rest groups)
(if (symbolp state)
(let ((res '(progn)))
(dolist (group groups)
(setq res (append res (list `(define-key ,(make-symbol (concatenate 'string "evil-" (symbol-name state) "-state-map"))
(kbd ,(car group))
(kbd ,(cadr group)))))))
res)
(let ((res '(progn)))
(dolist (a-state state)
(setq res (append res (list `(keymap ,a-state ,@groups)))))
res))))
(keymap (normal visual) ("H" "8h")
("L" "8l")
("J" "5j")
("K" "5k")))
我希望它展开成类似如下的代码
(progn
(progn
(define-key evil-normal-state-map (kbd "H") (kbd "8h"))
(define-key evil-normal-state-map (kbd "L") (kbd "8l"))
(define-key evil-normal-state-map (kbd "J") (kbd "8j"))
(define-key evil-normal-state-map (kbd "K") (kbd "8k")))
(progn
(define-key evil-normal-state-map (kbd "H") (kbd "8h"))
(define-key evil-normal-state-map (kbd "L") (kbd "8l"))
(define-key evil-normal-state-map (kbd "J") (kbd "8j"))
(define-key evil-normal-state-map (kbd "K") (kbd "8k"))))
但是在IELM中总是报错说 Symbol’s value as variable is void: evil-normal-state-map
猜想是
`(define-key ,(make-symbol (concatenate 'string "evil-" (symbol-name state) "-state-map"))
(kbd ,(car group))
(kbd ,(cadr group)))
这段代码中,make-symbol的结果被当成全局变量了。
请问是这样吗?该如何解决呢?这个宏还有没有别的问题呢?