summaryrefslogtreecommitdiff
path: root/lisp/help.el
diff options
context:
space:
mode:
authorJuanma Barranquero <lekktu@gmail.com>2019-11-23 23:29:53 +0100
committerJuanma Barranquero <lekktu@gmail.com>2019-11-23 23:29:53 +0100
commit6f3ff47c521a41f3eab3efd1f6126f06f4171478 (patch)
tree3dc30a4fa7a2d75cfaf0702c3a6dc6520ead0726 /lisp/help.el
parent4b5d04be44af36cb2faccd368de063cf376282ca (diff)
downloademacs-6f3ff47c521a41f3eab3efd1f6126f06f4171478.tar.gz
Make help-split-fundoc more flexible about what returns
* lisp/help.el (help-split-fundoc): New arg SECTION to return only the usage or doc parts of the docstring, or both even if there is no usage. * test/lisp/help-tests.el: New file.
Diffstat (limited to 'lisp/help.el')
-rw-r--r--lisp/help.el44
1 files changed, 28 insertions, 16 deletions
diff --git a/lisp/help.el b/lisp/help.el
index 22f35df1de1..06264ae2f32 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -1380,27 +1380,39 @@ The result, when formatted by `substitute-command-keys', should equal STRING."
;; But for various reasons, they are more widely needed, so they were
;; moved to this file, which is preloaded. https://debbugs.gnu.org/17001
-(defun help-split-fundoc (docstring def)
+(defun help-split-fundoc (docstring def &optional section)
"Split a function DOCSTRING into the actual doc and the usage info.
-Return (USAGE . DOC) or nil if there's no usage info, where USAGE info
-is a string describing the argument list of DEF, such as
-\"(apply FUNCTION &rest ARGUMENTS)\".
-DEF is the function whose usage we're looking for in DOCSTRING."
+Return (USAGE . DOC), where USAGE is a string describing the argument
+list of DEF, such as \"(apply FUNCTION &rest ARGUMENTS)\".
+DEF is the function whose usage we're looking for in DOCSTRING.
+With SECTION nil, return nil if there is no usage info; conversely,
+SECTION t means to return (USAGE . DOC) even if there's no usage info.
+When SECTION is \\='usage or \\='doc, return only that part."
;; Functions can get the calling sequence at the end of the doc string.
;; In cases where `function' has been fset to a subr we can't search for
;; function's name in the doc string so we use `fn' as the anonymous
;; function name instead.
- (when (and docstring (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring))
- (let ((doc (unless (zerop (match-beginning 0))
- (substring docstring 0 (match-beginning 0))))
- (usage-tail (match-string 1 docstring)))
- (cons (format "(%s%s"
- ;; Replace `fn' with the actual function name.
- (if (symbolp def)
- (help--docstring-quote (format "%S" def))
- 'anonymous)
- usage-tail)
- doc))))
+ (let* ((found (and docstring
+ (string-match "\n\n(fn\\(\\( .*\\)?)\\)\\'" docstring)))
+ (doc (if found
+ (and (memq section '(t nil doc))
+ (not (zerop (match-beginning 0)))
+ (substring docstring 0 (match-beginning 0)))
+ docstring))
+ (usage (and found
+ (memq section '(t nil usage))
+ (let ((tail (match-string 1 docstring)))
+ (format "(%s%s"
+ ;; Replace `fn' with the actual function name.
+ (if (and (symbolp def) def)
+ (help--docstring-quote (format "%S" def))
+ 'anonymous)
+ tail)))))
+ (pcase section
+ (`nil (and usage (cons usage doc)))
+ (`t (cons usage doc))
+ (`usage usage)
+ (`doc doc))))
(defun help-add-fundoc-usage (docstring arglist)
"Add the usage info to DOCSTRING.