unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Thien-Thi Nguyen <ttn@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: display just defuns and doc-strings of elisp
Date: Mon, 12 May 2014 07:16:05 +0200	[thread overview]
Message-ID: <87siofvap6.fsf@zigzag.favinet> (raw)
In-Reply-To: <20140511144013.517b5ccd@gauss> (Joe Riel's message of "Sun, 11 May 2014 14:40:13 -0700")

[-- 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 --]

      reply	other threads:[~2014-05-12  5:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-11 21:40 display just defuns and doc-strings of elisp Joe Riel
2014-05-12  5:16 ` Thien-Thi Nguyen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87siofvap6.fsf@zigzag.favinet \
    --to=ttn@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).