比如我想把outline-hide-entry
和outline-show-entry
组合成一个函数,然后给这个函数绑定快捷键(或某个hdyra的 key),然后每次按就是轮流调用这两个函数,像hydra wiki里自带的outline
的例子,显示和隐藏的分别绑在不同的键上,实在不好记。。而且像这种成对出现的函数,除了outline
以外也有不少。不知道是否有包已经实现了类似的功能(org-cycle
与org-shifttab
也是类似的?)?
(defun make-toggle-function (name &rest funs)
(lexical-let ((function-name name)
(functions funs))
(defalias name
(function
(lambda ()
(interactive)
(let* ((index (mod (1+ (or (get function-name 'index) -1)) (length functions)))
(next-function (nth index functions)))
(call-interactively next-function)
(put function-name 'index index)))))))
(make-toggle-function
'outline-toggle-subtree
'outline-hide-subtree 'outline-show-subtree)
(make-toggle-function
'outline-cycle
'outline-hide-leaves 'outline-hide-subtree 'outline-show-children 'outline-show-subtree)
一个肤浅的实现。。抛砖引玉。
;; -*- lexical-binding: t; -*-
比lexical-let不知高到哪里去了
1 个赞