Skip to content

Commit 3e7b55e

Browse files
CeleritasCeleryslotThe
authored andcommitted
Add hide docstring functionality
NOTE: This is part of Wilfred#217
1 parent 2bc6038 commit 3e7b55e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Helpful will try really hard to show the source code. It shows the
6464
source code for interactively defined functions (unlike the built-in
6565
Help) and falls back to the raw sexp if no source is available.
6666

67+
Set `helpful-hide-docstring-in-source` to hide the docstring in source
68+
code.
69+
6770
### View Callers
6871

6972
![screenshot](screenshots/helpful_refs.png)

helpful.el

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ To disable cleanup entirely, set this variable to nil. See also
9898
:type 'function
9999
:group 'helpful)
100100

101+
(defcustom helpful-hide-docstring-in-source nil
102+
"If t, hide the the docstring source code header.
103+
104+
This is useful because the formated documentation is already
105+
displayed in it's own header, and you may not want to display it
106+
twice."
107+
:type 'boolean
108+
:group 'helpful)
109+
101110
;; TODO: explore whether more basic highlighting is fast enough to
102111
;; handle larger functions. See `c-font-lock-init' and its use of
103112
;; font-lock-keywords-1.
@@ -1187,6 +1196,14 @@ hooks.")
11871196
(defun helpful--syntax-highlight (source &optional mode)
11881197
"Return a propertized version of SOURCE in MODE."
11891198
(unless mode
1199+
(when helpful-hide-docstring-in-source
1200+
(let ((doc-string (nth 3 (ignore-errors
1201+
(read source)))))
1202+
(when (stringp doc-string)
1203+
(setq source
1204+
(replace-regexp-in-string
1205+
(regexp-quote (prin1-to-string doc-string))
1206+
"\"...DOCSTRING...\"" source t t)))))
11901207
(setq mode #'emacs-lisp-mode))
11911208
(if (or
11921209
(< (length source) helpful-max-highlight)

0 commit comments

Comments
 (0)