How to hide comment lines?

  • Follow


I'd like to quickly toggle between displaying and hiding all lines in
the current buffer that start with my comment symbol (';' in this
case).  How do I do this?

0
Reply charlesfox357 (36) 5/25/2005 3:46:24 PM

On 25 May 2005 08:46:24 -0700, <charlesfox357@hotmail.com> wrote:
>
> I'd like to quickly toggle between displaying and hiding all lines in
> the current buffer that start with my comment symbol (';' in this
> case).  How do I do this?

Use color-theme.
The different colors make it simple to pick out desired content.


I stick

(require 'color-theme)

into default.el

and

(eval-after-load "color-theme" '(color-theme-marquardt))

in an user .emacs



-- 
With sufficient thrust, pigs fly fine.
0
Reply GP 5/25/2005 4:05:38 PM


"foxx" <charlesfox357@hotmail.com> writes:

> I'd like to quickly toggle between displaying and hiding all lines in
> the current buffer that start with my comment symbol (';' in this
> case).  How do I do this?
> 
Have a look at the various 'folding' modes which are available. These
allow you to hide blocks of your file based on certain markes. There
is also hide-show mode, which allows you to hide blocks as well and
doesn't require special characters - a multi-line comment is
recognised as a block.

HTH

Tim

-- 
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you 
really need to send mail, you should be able to work it out!
0
Reply Tim 5/25/2005 10:31:01 PM

"foxx" <charlesfox357@hotmail.com> writes:

> I'd like to quickly toggle between displaying and hiding all lines in
> the current buffer that start with my comment symbol (';' in this
> case).  How do I do this?

I wrote the following a few years ago for use with C++, but it should
work for any mode that defines comment syntax.

(defun overlay-comments(beg end attrs)
  (save-excursion
    (goto-char beg)
    (let (state comment-start comment-end overlay)
      (while (nth 4 (setq state
                          (parse-partial-sexp (point) end nil nil nil t)))
        (goto-char (nth 8 state))
        (setq comment-start (point))
        (forward-comment 1)
        (setq comment-end (point))
        (while (= (char-before comment-end) ?\n)
          (setq comment-end (1- comment-end)))
        (setq overlay (make-overlay comment-start comment-end))
        (mapc #'(lambda (attr)
                (overlay-put overlay (car attr) (cdr attr)))
              attrs)))))

(defun hide-comments()
  (interactive)
  (overlay-comments (point-min)
                    (point-max)
                    '((category . comment) (invisible . comment))))

(defun show-comments()
  (interactive)
  (dolist (ov (overlays-in (point-min) (point-max)))
    (if (eq (overlay-get ov 'category) 'comment)
        (delete-overlay ov))))

-- 
Jim Janney
0
Reply Jim 6/2/2005 8:01:31 PM

This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig42CDDDFF175069A3358D5982
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Jim Janney wrote:
> "foxx" <charlesfox357@hotmail.com> writes:
>
>
>>I'd like to quickly toggle between displaying and hiding all lines in
>>the current buffer that start with my comment symbol (';' in this
>>case).  How do I do this?
>
>
> I wrote the following a few years ago for use with C++, but it should
> work for any mode that defines comment syntax.
>
I've just added that to my elisp includes etc. and tried it out and it's
great, but is there a way to convince it to eat comment lines in their
entirety? - I tried it out in a lisp file with a couple of lines
starting with ';' and although the comments disappear, the lines aren't
folded.

Is this possible to do?

Rupert

--------------enig42CDDDFF175069A3358D5982
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iQCVAwUBQp+OSEbXf6SW2FaGAQHULgQAt0+S8e+/nwBHtTp/d8FX5KKc4yhCQM+A
KzeQQPB9lmTmvQulI+n3+KlP73inu7rc7/6kT1lUcPpI+aVPH28PrDj6G43CQFCk
svRMWYXGiD3ZX/vX3GcYR/8gx2r7Ssjr2faqcQWTpEZSURicxn7bmQ2+3sMYhGbn
26Ms8dJdudw=
=CGMN
-----END PGP SIGNATURE-----

--------------enig42CDDDFF175069A3358D5982--
0
Reply Rupert 6/2/2005 10:55:03 PM

Rupert Swarbrick <rupert.swarbrick@lineone.net> writes:

> Jim Janney wrote:
> > "foxx" <charlesfox357@hotmail.com> writes:
> >
> >
> >>I'd like to quickly toggle between displaying and hiding all lines in
> >>the current buffer that start with my comment symbol (';' in this
> >>case).  How do I do this?
> >
> >
> > I wrote the following a few years ago for use with C++, but it should
> > work for any mode that defines comment syntax.
> >
> I've just added that to my elisp includes etc. and tried it out and it's
> great, but is there a way to convince it to eat comment lines in their
> entirety? - I tried it out in a lisp file with a couple of lines
> starting with ';' and although the comments disappear, the lines aren't
> folded.
> 
> Is this possible to do?

Removing the lines

        (while (= (char-before comment-end) ?\n)
          (setq comment-end (1- comment-end)))

in overlay-comments seems to have that effect.  It's been long enough
since I wrote this that I don't remember exactly how it works.

-- 
Jim Janney
0
Reply Jim 6/3/2005 6:55:11 PM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jim Janney wrote:
|
| Removing the lines
|
|         (while (= (char-before comment-end) ?\n)
|           (setq comment-end (1- comment-end)))
|
| in overlay-comments seems to have that effect.  It's been long enough
| since I wrote this that I don't remember exactly how it works.
|
Finally gotten round to testing it and it works fabulously. Thanks!

Rupert
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iQCVAwUBQqNwm0bXf6SW2FaGAQLA1AQAn8i01JZwMwsrta1RoKK33pWc3dtraVAQ
u7do0sw7uEQs9S7NaevB9xuYV6nriKZXd7HNStmLTTrBSKL10lTIL0WNcGQSHTRG
GaULl6W7S4vs5K1wFHbo/K+z4RVSRYo6YlPK3RN2r/2Hs4dr396ZB5ijMYryXsH6
RgMltl7MWdU=
=b/yK
-----END PGP SIGNATURE-----
0
Reply Rupert 6/5/2005 9:37:32 PM

Thanks a lot for the code -- that just what I wanted.

just one problem though, when I do it on somethign like this:


(defun myfun ()
   (for (a '(1 2 3))
       ;here is a comment
       (print a)
       (print "hello")))

it messes up some of the indentation like this:

(defun myfun ()
   (for (a '(1 2 3))
           (print a)              <---line after comment is too
indented
       (print "hello")))

any idea whats going on?  (Thats with those 2 lines removed as
discussed in previous posts)

0
Reply foxx 6/8/2005 2:38:38 PM

7 Replies
440 Views

(page loaded in 0.111 seconds)

Similiar Articles:













7/21/2012 12:21:32 AM


Reply: