[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: display just defuns and doc-strings of elisp
From: |
Thien-Thi Nguyen |
Subject: |
Re: display just defuns and doc-strings of elisp |
Date: |
Mon, 12 May 2014 07:16:05 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
() 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
pgpHZ0AvqcE3s.pgp
Description: PGP signature