Add support for global documentation in define-micro-state macro

This commit is contained in:
syl20bnr 2015-02-10 22:08:50 -05:00
parent 0cb16a8381
commit a9f8e07a29
1 changed files with 10 additions and 4 deletions

View File

@ -24,6 +24,9 @@ Available PROPS:
`:on-exit BODY'
Evaluate BODDY when leaving the micro-state.
`:documentation STRING'
A documentation STRING displayed in the minibuffer
`:bindings EXPRESSIONS'
One or several EXPRESSIONS with the form
(STRING1 SYMBOL1 :documentation STRING :exit SYMBOL)
@ -34,14 +37,16 @@ Available PROPS:
pressing this key will leave the micro-state (default is nil)."
(declare (indent 1))
(let* ((func (spacemacs//micro-state-func-name name))
(doc (plist-get props :documentation))
(on-enter (spacemacs/mplist-get props :on-enter))
(on-exit (spacemacs/mplist-get props :on-exit))
(bindings (spacemacs/mplist-get props :bindings))
(wrappers (spacemacs//micro-state-create-wrappers name bindings))
(wrappers (spacemacs//micro-state-create-wrappers name doc bindings))
(keymap-body (spacemacs//micro-state-fill-map-sexps wrappers)))
`(defun ,func ()
,(format "%s micro-state." (symbol-name name))
(interactive)
(when ,doc (echo ,doc))
,@on-enter
(,(if (version< emacs-version "24.4")
'set-temporary-overlay-map
@ -54,12 +59,12 @@ Available PROPS:
"Return the name of the micro-state function."
(intern (format "spacemacs/%s-micro-state" (symbol-name name))))
(defun spacemacs//micro-state-create-wrappers (name bindings)
(defun spacemacs//micro-state-create-wrappers (name doc bindings)
"Return an alist (key wrapper) for each binding in BINDINGS."
(mapcar (lambda (x) (spacemacs//micro-state-create-wrapper name x))
(mapcar (lambda (x) (spacemacs//micro-state-create-wrapper name doc x))
bindings))
(defun spacemacs//micro-state-create-wrapper (name binding)
(defun spacemacs//micro-state-create-wrapper (name doc binding)
"Create a wrapper of FUNC and return a tuple (key wrapper BINDING)."
(let* ((wrapped (cadr binding))
(wrapper-name (intern (format "spacemacs//%s-%s" (symbol-name name)
@ -67,6 +72,7 @@ Available PROPS:
(wrapper-func (eval `(defun ,wrapper-name ()
"Auto-generated function"
(interactive)
(echo ,doc)
(when ',wrapped
(call-interactively ',wrapped))))))
(append (list (car binding) wrapper-func) binding)))