helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit a1b86c21ac421105be96aa2666ec5bec723ce51b
parent 4a508ff1755fce4e1697a215d8b9f2e5ad7bb78b
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sun,  2 Apr 2017 12:17:22 +0100

Handle function not having a docstring.

Diffstat:
Mhelpful.el | 10+++++-----
Mtest/unit-test.el | 6++++++
2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/helpful.el b/helpful.el @@ -99,7 +99,8 @@ state of the current symbol." (insert (format "Symbol: %s\n\n" helpful--sym) (helpful--heading "Documentation\n") - (helpful--docstring helpful--sym) + (or (helpful--docstring helpful--sym) + "No docstring.") (helpful--heading "\n\nSymbol Properties\n") (helpful--format-properties helpful--sym) (helpful--heading "\n\nTools\n") @@ -115,13 +116,12 @@ state of the current symbol." (defun helpful--docstring (sym) "Get the docstring for SYM." - (let* ((docstring (documentation sym)) - (docstring-with-usage (help-split-fundoc docstring sym))) - (when docstring-with-usage + (-when-let (docstring (documentation sym)) + (-when-let (docstring-with-usage (help-split-fundoc docstring sym)) (setq docstring (cdr docstring-with-usage)) ;; Advice mutates the docstring, see ;; `advice--make-docstring'. Undo that. - ;; TODO: Only do this if the function is adviced. + ;; TODO: Only do this if the function is advised. (setq docstring (helpful--skip-advice docstring))) docstring)) diff --git a/test/unit-test.el b/test/unit-test.el @@ -31,3 +31,9 @@ (helpful--docstring #'test-foo-advised) "Docstring here too."))) +(defun test-foo-no-docstring () + nil) + +(ert-deftest helpful--no-docstring () + "We should not crash on a function without a docstring." + (should (null (helpful--docstring #'test-foo-no-docstring))))