helpful

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

commit 73436111c0db6d8eedabc7fb4752ba7a4a7039b1
parent ab93fa3e23ce3bc58ec1ffaaede3efc4faa7721f
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sun, 27 Aug 2017 13:56:43 +0100

Convert closures to equivalent defun forms

Diffstat:
ACHANGELOG.md | 12++++++++++++
Mhelpful.el | 31++++++++++++++++++++++++++-----
2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -0,0 +1,12 @@ +# v0.2 + +Fixed an issue where we didn't find the path for functions defined +interactively using `cl-defstruct`. + +Interactively defined functions (e.g. try re-evaluating package.el.gz +and looking at `package-desc-name`) are converted from raw closures to +equivalent defun forms. + +# v0.1 + +First release. diff --git a/helpful.el b/helpful.el @@ -63,6 +63,21 @@ "Propertize TEXT as a heading." (propertize text 'face 'bold)) +(defun helpful--format-closure (sym form) + "Given a closure, return an equivalent defun form." + (-let (((_keyword _env args . body) form) + (docstring nil)) + (when (stringp (car body)) + (setq docstring (car body)) + (setq body (cdr body)) + ;; Ensure that the docstring doesn't have lines starting with (, + ;; or it breaks indentation. + (setq docstring + (s-replace "\n(" "\n\\(" docstring))) + (if docstring + `(defun ,sym ,args ,docstring ,@body) + `(defun ,sym ,args ,@body)))) + (defun helpful--pretty-print (value) "Pretty-print VALUE. This allows us to distinguish strings from symbols." @@ -585,11 +600,17 @@ state of the current symbol." (format ";; Source file is unknown\n"))))) (when source (insert - (if (stringp source) - (helpful--syntax-highlight - source - (if primitive-p 'c-mode)) - (helpful--syntax-highlight (helpful--pretty-print source))))) + (cond + ((stringp source) + (helpful--syntax-highlight source (if primitive-p 'c-mode))) + ((and (consp source) (eq (car source) 'closure)) + (helpful--syntax-highlight + (concat ";; Closure converted to defun by helpful.\n" + (helpful--pretty-print + (helpful--format-closure helpful--sym source))))) + (t + (helpful--syntax-highlight + (helpful--pretty-print source)))))) (goto-char start-pos))) (defun helpful--skip-advice (docstring)