Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hide docstring functionality #217

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions helpful.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 (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)
Expand Down