From 8d7c9a63a28eb28acbef2d0b98e06338e9749ba1 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 27 Nov 2013 21:04:26 -0500 Subject: [PATCH 1/3] retrieve function documentation correctly --- doc/yas-doc-helper.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/yas-doc-helper.el b/doc/yas-doc-helper.el index 67e5986..e4d2857 100755 --- a/doc/yas-doc-helper.el +++ b/doc/yas-doc-helper.el @@ -49,7 +49,7 @@ (body (or (cond ((boundp symbol) (documentation-property symbol 'variable-documentation t)) ((fboundp symbol) - (documentation-property symbol 'function-documentation t)) + (documentation symbol t)) (t (format "*WARNING*: no symbol named =%s=" symbol))) (format "*WARNING*: no doc for symbol =%s=" symbol))) From eaa3141402832903715b7d478e028d69d9d3ed0f Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 27 Nov 2013 21:34:29 -0500 Subject: [PATCH 2/3] fix docstring extraction for "fancy" docs The docstrings for yas-expand and yas-expand-from-keymap are generated on the fly, depending on how they are called ("context"). Add a context argument to the synthesizing functions and pass it nil when extracting docstrings for the manual. --- doc/yas-doc-helper.el | 5 ++++- yasnippet.el | 34 ++++++++++++++++++---------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/doc/yas-doc-helper.el b/doc/yas-doc-helper.el index e4d2857..f9e0f69 100755 --- a/doc/yas-doc-helper.el +++ b/doc/yas-doc-helper.el @@ -49,7 +49,10 @@ (body (or (cond ((boundp symbol) (documentation-property symbol 'variable-documentation t)) ((fboundp symbol) - (documentation symbol t)) + (let ((doc-synth (car-safe (get symbol 'function-documentation)))) + (if (functionp doc-synth) + (funcall doc-synth nil) + (documentation symbol t)))) (t (format "*WARNING*: no symbol named =%s=" symbol))) (format "*WARNING*: no doc for symbol =%s=" symbol))) diff --git a/yasnippet.el b/yasnippet.el index eb7afc6..6c95978 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -4298,31 +4298,33 @@ When multiple expressions are found, only the last one counts." ;; depending on the context. ;; (put 'yas-expand 'function-documentation - '(yas--expand-from-trigger-key-doc)) -(defun yas--expand-from-trigger-key-doc () + '(yas--expand-from-trigger-key-doc t)) +(defun yas--expand-from-trigger-key-doc (context) "A doc synthesizer for `yas--expand-from-trigger-key-doc'." - (let ((fallback-description - (cond ((eq yas-fallback-behavior 'call-other-command) - (let* ((fallback (yas--keybinding-beyond-yasnippet))) - (or (and fallback - (format " call command `%s'." (pp-to-string fallback))) - " do nothing (`yas-expand' doesn't shadow\nanything)"))) - ((eq yas-fallback-behavior 'return-nil) - ", do nothing.") - (t - ", defer to `yas-fallback-behaviour' (which see)")))) + (let* ((yas-fallback-behavior (and context yas-fallback-behavior)) + (fallback-description + (cond ((eq yas-fallback-behavior 'call-other-command) + (let* ((fallback (yas--keybinding-beyond-yasnippet))) + (or (and fallback + (format "call command `%s'." + (pp-to-string fallback))) + "do nothing (`yas-expand' doesn't shadow\nanything)."))) + ((eq yas-fallback-behavior 'return-nil) + "do nothing.") + (t "defer to `yas-fallback-behaviour' (which see).")))) (concat "Expand a snippet before point. If no snippet -expansion is possible," +expansion is possible, " fallback-description "\n\nOptional argument FIELD is for non-interactive use and is an object satisfying `yas--field-p' to restrict the expansion to."))) -(put 'yas-expand-from-keymap 'function-documentation '(yas--expand-from-keymap-doc)) -(defun yas--expand-from-keymap-doc () +(put 'yas-expand-from-keymap 'function-documentation + '(yas--expand-from-keymap-doc t)) +(defun yas--expand-from-keymap-doc (context) "A doc synthesizer for `yas--expand-from-keymap-doc'." (add-hook 'temp-buffer-show-hook 'yas--snippet-description-finish-runonce) (concat "Expand/run snippets from keymaps, possibly falling back to original binding.\n" - (when (eq this-command 'describe-key) + (when (and context (eq this-command 'describe-key)) (let* ((vec (this-single-command-keys)) (templates (mapcan #'(lambda (table) (yas--fetch table vec)) From 2c237cc311a7e84c5c61b99a8e263d312ea145d6 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 27 Nov 2013 21:44:18 -0500 Subject: [PATCH 3/3] check function doc before variable doc This means functions shadow variables with the same name, but at least that's better than listing functions with the documentation from the variable! (That happened because the call to yas--document-symbols in snippet-reference.org was prefering function values to variables, while the yas--document-symbol was prefering variable doc to function doc). --- doc/yas-doc-helper.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/yas-doc-helper.el b/doc/yas-doc-helper.el index f9e0f69..c940b20 100755 --- a/doc/yas-doc-helper.el +++ b/doc/yas-doc-helper.el @@ -46,13 +46,13 @@ (concat-lines ":PROPERTIES:" (format ":CUSTOM_ID: %s" symbol) ":END:")) - (body (or (cond ((boundp symbol) - (documentation-property symbol 'variable-documentation t)) - ((fboundp symbol) + (body (or (cond ((fboundp symbol) (let ((doc-synth (car-safe (get symbol 'function-documentation)))) (if (functionp doc-synth) (funcall doc-synth nil) (documentation symbol t)))) + ((boundp symbol) + (documentation-property symbol 'variable-documentation t)) (t (format "*WARNING*: no symbol named =%s=" symbol))) (format "*WARNING*: no doc for symbol =%s=" symbol)))