Emacs lisp,简洁的键盘图

时间:2012-08-08 00:23:47

标签: emacs elisp

在emacs的邪恶模式之上,我编写了一个扩展模式,允许我在一个按键中插入数学和希腊语unicode字符。但是代码看起来像这样(数百行):

(define-key evil-unicode-state-map "a" "α")
(define-key evil-unicode-state-map "b" "β")
(define-key evil-unicode-state-map "g" "γ")

我想知道是否有一种切断所有样板的首选方法? 理想情况下,我可以编写如下内容:

(setq evil-unicode-state-map
  {"a" "α"
   "b" "β"
   "g" "γ"})

1 个答案:

答案 0 :(得分:7)

一种方法是:

(setq my-evil-unicode-state-map
  '(("a" . "α")
    ("b" . "β")
    ("g" . "γ")))

(dolist (key-def my-evil-unicode-state-map)
  (let ((key (car key-def)) (def (cdr key-def)))
    (define-key evil-unicode-state-map key def)))

编辑:(反映Ivan Andrus的评论)

如果其他地方未使用my-evil-unicode-state-map

(dolist (key-def
         '(("a" . "α")
           ("b" . "β")
           ("g" . "γ"))))
  (define-key evil-unicode-state-map (car key-def) (cdr key-def)))