用 ivy 自定义一个中文的 M-x,绑定在 M-z 按键上,pyim 提供了函数可以只输入首字母就可以找到指定命令,甚至比 hydra, which-key 快,没有记忆负担,代码如下:
(require 'ht)
(require 'pyim)
(setq ivy-re-builders-alist
'((t . pyim-ivy-cregexp)))
(setq my-hash
(ht ("重启" 'restart-emacs)
("单窗口" 'delete-other-windows)
("安装包" 'list-packages)
("配置" 'crux-find-user-init-file)
("最大化切换" 'toggle-frame-maximized)
;; ...
("全屏切换" 'toggle-frame-fullscreen)))
(defun zh-mx ()
(interactive)
(ivy-read "输入命令: "
(ht-keys my-hash)
:require-match t
:action (lambda (x)
(funcall (ht-get my-hash x)))))
(global-set-key [remap zap-to-char] 'zh-mx)