3

在 emacs 中的 evil-mode 之上,我编写了一个扩展模式,它允许我在单个按键中插入数学和希腊语 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" "γ"})
4

1 回答 1

7

One way to do it will be:

(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)))

EDIT: (reflecting Ivan Andrus's comment)

If my-evil-unicode-state-map is not used elsewhere,

(dolist (key-def
         '(("a" . "α")
           ("b" . "β")
           ("g" . "γ"))))
  (define-key evil-unicode-state-map (car key-def) (cdr key-def)))
于 2012-08-08T00:57:11.340 回答