From e52bab706d667e1da003cf971d50bbca3f06f2a4 Mon Sep 17 00:00:00 2001 From: Troy Hinckley Date: Wed, 31 Jul 2019 22:21:21 -0700 Subject: [PATCH 1/2] Add hide docstring functionality --- README.md | 3 +++ helpful.el | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 4944c07..0efd98b 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,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 01054f0..347960b 100644 --- a/helpful.el +++ b/helpful.el @@ -94,6 +94,15 @@ 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) + ;; TODO: explore whether more basic highlighting is fast enough to ;; handle larger functions. See `c-font-lock-init' and its use of ;; font-lock-keywords-1. @@ -1118,6 +1127,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 (nth 3 (ignore-errors + (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) From 8b98b817613a914f1b66f4efd82b73bc6d544836 Mon Sep 17 00:00:00 2001 From: Troy Hinckley Date: Tue, 13 Aug 2019 12:34:53 -0700 Subject: [PATCH 2/2] Handle additional errors --- helpful.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpful.el b/helpful.el index 347960b..370d1f9 100644 --- a/helpful.el +++ b/helpful.el @@ -1128,8 +1128,8 @@ hooks.") "Return a propertized version of SOURCE in MODE." (unless mode (when helpful-hide-docstring-in-source - (let ((doc-string (nth 3 (ignore-errors - (read source))))) + (let ((doc-string (ignore-errors + (nth 3 (read source))))) (when (stringp doc-string) (setq source (replace-regexp-in-string