diff --git a/README.md b/README.md index c241c5b..4cb459b 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,9 @@ Helpful will try really hard to show the source code. It shows the source code for interactively defined functions (unlike the built-in Help) and falls back to the raw sexp if no source is available. +Set `helpful-hide-docstring-in-source` to hide the docstring in source +code. + ### View Callers ![screenshot](screenshots/helpful_refs.png) diff --git a/helpful.el b/helpful.el index b9ee878..6ac9526 100644 --- a/helpful.el +++ b/helpful.el @@ -98,6 +98,16 @@ To disable cleanup entirely, set this variable to nil. See also :type 'function :group 'helpful) + +(defcustom helpful-hide-docstring-in-source nil + "If t, hide the the docstring source code header. + +This is useful because the formated documentation is already +displayed in it's own header, and you may not want to display it +twice." + :type 'boolean + :group 'helpful) + (defcustom helpful-set-variable-function (if (< 29 emacs-major-version) #'setopt #'setq) "Function used by `helpful--set' to interactively set variables." @@ -1195,6 +1205,14 @@ hooks.") (defun helpful--syntax-highlight (source &optional mode) "Return a propertized version of SOURCE in MODE." (unless mode + (when helpful-hide-docstring-in-source + (let ((doc-string (ignore-errors + (nth 3 (read source))))) + (when (stringp doc-string) + (setq source + (replace-regexp-in-string + (regexp-quote (prin1-to-string doc-string)) + "\"...DOCSTRING...\"" source t t))))) (setq mode #'emacs-lisp-mode)) (if (or (< (length source) helpful-max-highlight)