* display just defuns and doc-strings of elisp
@ 2014-05-11 21:40 Joe Riel
2014-05-12 5:16 ` Thien-Thi Nguyen
0 siblings, 1 reply; 2+ messages in thread
From: Joe Riel @ 2014-05-11 21:40 UTC (permalink / raw)
To: Help GNU Emacs
Is there an existing elisp function that displays
just the defs [first line] and doc-strings in an elisp source buffer?
So, with it enabled, a source might appear as
(defun func1 (foo bar)
"This does nothing useful" ... )
(defun func2 ()
"This does something else" ... )
...
--
Joe Riel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: display just defuns and doc-strings of elisp
2014-05-11 21:40 display just defuns and doc-strings of elisp Joe Riel
@ 2014-05-12 5:16 ` Thien-Thi Nguyen
0 siblings, 0 replies; 2+ messages in thread
From: Thien-Thi Nguyen @ 2014-05-12 5:16 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 2197 bytes --]
() Joe Riel <joer@san.rr.com>
() Sun, 11 May 2014 14:40:13 -0700
Is there an existing elisp function that displays just the defs
[first line] and doc-strings in an elisp source buffer?
I don't think so. However, you can use hideshow like so:
(defun display-docstring-and-code-line-counts (ov)
(when (eq 'code (overlay-get ov 'hs))
(let ((beg (overlay-start ov))
(end (overlay-end ov)))
(save-excursion
(goto-char (overlay-start ov))
(forward-line 1)
(when (looking-at "\\s-*\"")
(forward-sexp 1)
(cond ((eolp)
;; purposeful
(forward-line 1)
(skip-chars-forward "[:space:]")
(move-overlay ov (setq beg (point)) end))
(t
;; unbearable lightness
(delete-overlay ov)
(setq ov nil)))))
(when ov
(overlay-put
ov 'display (propertize
(format " ... / %d"
(count-lines beg end))
'face 'font-lock-warning-face))))))
(setq hs-set-up-overlay
'display-docstring-and-code-line-counts)
The line-count stuff is because this code is dervived from the
example given in `C-h v hs-set-up-overlay'. The important part is
the call to ‘move-overlay’. Readers of source code (src/buffer.c)
will note that ‘delete-overlay’ returns nil, but that is not
documented. Had it been, i would have reversed the sense of the
innermost COND and used IF:
(if (not (eolp))
;; unbearable lightness
(setq ov (delete-overlay ov))
;; purposeful
(forward-line 1)
(skip-chars-forward "[:space:]")
(move-overlay ov (setq beg (point)) end))
But that's just a question of style. Mogrify at will, YMMV, etc...
--
Thien-Thi Nguyen
GPG key: 4C807502
(if you're human and you know it)
read my lisp: (responsep (questions 'technical)
(not (via 'mailing-list)))
=> nil
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-12 5:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-11 21:40 display just defuns and doc-strings of elisp Joe Riel
2014-05-12 5:16 ` Thien-Thi Nguyen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).