all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Hiding lines based on a regexp
@ 2005-05-27 22:10 David Vanderschel
  2005-05-27 23:02 ` Pascal Bourguignon
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: David Vanderschel @ 2005-05-27 22:10 UTC (permalink / raw)


Could someone please point me to a mechanism that
would allow me to temporarily hide from display
certain lines in a file based on a matching regular
expression?  There is somewhat similar functionality
with hide-ifdef-mode.  However, I want something less
clever and more general.

What I have in mind is to suppress lines I have
inserted into a program for debugging purpose, but
which lines can make examining the code more
difficult.  For example, when coding in java, there
are times when I would like to hide lines that match
"assert" or "system.out.println".

Though I usually manage to squeeze my debugging
statements onto a single line, it would be even better
if the mechanism could recognize that a matching
language statement was spread over multiple lines.

Thanks,
  David V.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
  2005-05-27 22:10 Hiding lines based on a regexp David Vanderschel
@ 2005-05-27 23:02 ` Pascal Bourguignon
  2005-05-28  0:04   ` David Vanderschel
  2005-05-28  5:24 ` Travis Spencer
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Pascal Bourguignon @ 2005-05-27 23:02 UTC (permalink / raw)


"David Vanderschel" <DJV4@Austin.RR.com> writes:

> Could someone please point me to a mechanism that
> would allow me to temporarily hide from display
> certain lines in a file based on a matching regular
> expression?  There is somewhat similar functionality
> with hide-ifdef-mode.  However, I want something less
> clever and more general.
>
> What I have in mind is to suppress lines I have
> inserted into a program for debugging purpose, but
> which lines can make examining the code more
> difficult.  For example, when coding in java, there
> are times when I would like to hide lines that match
> "assert" or "system.out.println".
>
> Though I usually manage to squeeze my debugging
> statements onto a single line, it would be even better
> if the mechanism could recognize that a matching
> language statement was spread over multiple lines.

If the parts you want to hide are at the beginning or at the end of a
buffer, you could use narrow-to-region (and then widden).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Cats meow out of angst
"Thumbs! If only we had thumbs!
We could break so much!"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
  2005-05-27 23:02 ` Pascal Bourguignon
@ 2005-05-28  0:04   ` David Vanderschel
  0 siblings, 0 replies; 9+ messages in thread
From: David Vanderschel @ 2005-05-28  0:04 UTC (permalink / raw)


"Pascal Bourguignon" <pjb@informatimago.com> wrote in message
news:<87br6wff2k.fsf@thalassa.informatimago.com>...
> If the parts you want to hide are at the beginning or at the end of a
> buffer, you could use narrow-to-region (and then widden).

This is a silly suggestion.  Clearly anything at
either end of the buffer is not going to make reading
the code any more difficult.  It is the junk that is
scattered through the code that I want to suppress.

I can implement this.  It is just that it is such an
obvious thing to want to have that I assumed that it
must already exist and that I have just been unable to
find it.  It would behave like flush-lines except that
you can get them back later - _even_ if you have
done some editing in the interim.

Regards,
  David V.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
  2005-05-27 22:10 Hiding lines based on a regexp David Vanderschel
  2005-05-27 23:02 ` Pascal Bourguignon
@ 2005-05-28  5:24 ` Travis Spencer
       [not found] ` <mailman.2153.1117258073.25862.help-gnu-emacs@gnu.org>
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Travis Spencer @ 2005-05-28  5:24 UTC (permalink / raw)
  Cc: help-gnu-emacs

On 5/27/05, David Vanderschel <DJV4@austin.rr.com> wrote:
> What I have in mind is to suppress lines I have
> inserted into a program for debugging purpose, but
> which lines can make examining the code more
> difficult.  For example, when coding in java, there
> are times when I would like to hide lines that match
> "assert" or "system.out.println".

Though hs-minor-mode doesn't collapse code based on a regular
expression, you may want to check it out and see if it will meet your
needs.  Its hs-hide-block combined w/ a macro might just work.

-- 

Regards,

Travis Spencer
Portland, OR USA

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
       [not found] ` <mailman.2153.1117258073.25862.help-gnu-emacs@gnu.org>
@ 2005-05-28  9:37   ` Thien-Thi Nguyen
  0 siblings, 0 replies; 9+ messages in thread
From: Thien-Thi Nguyen @ 2005-05-28  9:37 UTC (permalink / raw)


Travis Spencer <travislspencer@gmail.com> writes:

> hs-hide-block combined w/ a macro might just work.

hideshow never hides the block completely -- the first
line is always shown -- so maybe it doesn't fit the OP's
requirements.  on the other hand, if the debugging output
code is isolated in a code block (between curly braces for
java), hideshow can handle that block just like any other.

unfortunately, hideshow is not as general as it could be.
someone needs to pry it away from its regexp dependency,
babysit-with-tlc the inevitable withdrawal symptoms, and
gently detox the design to the point where separation of
definition (of a block) and action (on a block) would allow
easier behavior customization, then finally re-introduce
regexps as a particular flavor of block definition.

the fine hack is to twist and get twisted, be missed but
not misted, make list while unlisted, assist the acysted.

eventually we will see, the blind doctor said to me...

thi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
  2005-05-27 22:10 Hiding lines based on a regexp David Vanderschel
                   ` (2 preceding siblings ...)
       [not found] ` <mailman.2153.1117258073.25862.help-gnu-emacs@gnu.org>
@ 2005-05-30  4:57 ` David Vanderschel
  2005-05-30  7:11 ` Mathias Dahl
  4 siblings, 0 replies; 9+ messages in thread
From: David Vanderschel @ 2005-05-30  4:57 UTC (permalink / raw)


"David Vanderschel" <DJV4@Austin.RR.com> wrote in message
news:IVMle.6528$j51.1551@tornado.texas.rr.com...
> Could someone please point me to a mechanism that
> would allow me to temporarily hide from display
> certain lines in a file based on a matching regular
> expression?  ...

Well, no one did.  Although it is difficult for me to
believe that no one has done anything similar, I went
ahead and rolled my own mechanism.  It is not
particularly robust, but it is adequate for my
purposes:

______________________________________________________________________


(defun dv-mark-lines-invisible ( regexp )
"Set the `invisible' property for characters in matching lines to true.
Argument is a regular expression.  Each invocation marks an additional set
of
lines.  See related function `dv-unmark-lines-invisible'.  See
`dv-toggle-invisibility' for control of actual display.  See
`dv-all-visible' if
you forget any regexps you used to mark lines or if you wish, for any
reason,
to unmark all.  These functions will not play well with other functions
which
manipulate the `invisible' text property."
  (interactive "MMark for possible invisibility lines matching regexp: ")
  (let ( ( did  0 )
         ( nodo 0 )
         ( start-point (point-marker) ) )
    (goto-char (point-min))
    (while (search-forward-regexp regexp (point-max) t)
      (beginning-of-line)
      (let ( ( bol              (point) )
             ( invisiblity-prop (get-text-property (point) 'invisible) ) )
        (forward-line 1)
        (if invisiblity-prop
          (setq nodo (1+ nodo))
          (setq did  (1+ did ))
          (put-text-property bol (point) 'invisible t))))
    (redraw-display)
    (if (and (= did 0) (= nodo 0))
      (message "No matches.")
      (message
        (concat (format "Marked %d lines." did)
          (if (= nodo 0) "" (format "  %d matches were already marked."
nodo))
          (if buffer-invisibility-spec "" "  But all lines visible now."))))
    (goto-char start-point)))
(global-set-key [f6 ?8] 'dv-mark-lines-invisible)

(defun dv-unmark-lines-invisible ( regexp )
"Set the `invisible' property for characters in matching lines to nil.
See related and similar function `dv-mark-lines-invisible'."
  (interactive "MUnmark for possible invisibility lines matching regexp: ")
  (let ( ( did 0 )
         ( start-point (point-marker) ) )
    (goto-char (point-min))
    (while (search-forward-regexp regexp (point-max) t)
      (beginning-of-line)
      (let ( ( bol              (point) )
             ( invisiblity-prop (get-text-property (point) 'invisible) ) )
        (forward-line 1)
        (when invisiblity-prop
          (put-text-property bol (point) 'invisible nil)
          (setq did (1+ did)))))
    (redraw-display)
    (if (= did 0) (message "No matches."))
    (if (> did 0)
      (message
        (concat (format "Unmarked %d lines.  " did)
          (if buffer-invisibility-spec "" "But they were already
displayed."))))
    (goto-char start-point)))
(global-set-key [f6 ?9] 'dv-unmark-lines-invisible)

(defun dv-toggle-visibility ()
"Switch display of characters marked by `dv-mark-lines-invisible' by
toggling
`buffer-invisibility-spec'."
  (interactive)
  (setq buffer-invisibility-spec (not buffer-invisibility-spec))
  (redraw-display)
  (message (if buffer-invisibility-spec
             "Marked lines not visible now." "All lines visible now.")))
(global-set-key [f6 ?0] 'dv-toggle-visibility)

(defun dv-all-visible ()
"Set the `invisible' property for all characters in buffer to nil."
  (interactive)
  (put-text-property (point-min) (point-max) 'invisible nil)
  (redraw-display)
  (message "No lines marked for invisibility now."))
(global-set-key [f6 ?-] 'dv-all-visible)

_____________________________________________________________________


Perhaps someone else will find it useful.

Regards,
  David V.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
  2005-05-27 22:10 Hiding lines based on a regexp David Vanderschel
                   ` (3 preceding siblings ...)
  2005-05-30  4:57 ` David Vanderschel
@ 2005-05-30  7:11 ` Mathias Dahl
  2005-05-31  0:52   ` David Vanderschel
  4 siblings, 1 reply; 9+ messages in thread
From: Mathias Dahl @ 2005-05-30  7:11 UTC (permalink / raw)


"David Vanderschel" <DJV4@Austin.RR.com> writes:

> Could someone please point me to a mechanism that would allow me to
> temporarily hide from display certain lines in a file based on a
> matching regular expression?  There is somewhat similar
> functionality with hide-ifdef-mode.  However, I want something less
> clever and more general.

Have you looked on EmacsWiki?

http://www.emacswiki.org/cgi-bin/wiki/HideLines

and

http://www.emacswiki.org/cgi-bin/wiki/CategoryHideStuff

/Mathias

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
  2005-05-30  7:11 ` Mathias Dahl
@ 2005-05-31  0:52   ` David Vanderschel
  2005-05-31  8:07     ` Thien-Thi Nguyen
  0 siblings, 1 reply; 9+ messages in thread
From: David Vanderschel @ 2005-05-31  0:52 UTC (permalink / raw)


"Mathias Dahl" <brakjoller.rem0veth1s@gmail.com> wrote in message
news:uk6lhxk6u.fsf@gmail.com...
> "David Vanderschel" <DJV4@Austin.RR.com> writes:

> > Could someone please point me to a mechanism that would allow me to
> > temporarily hide from display certain lines in a file based on a
> > matching regular expression?  There is somewhat similar
> > functionality with hide-ifdef-mode.  However, I want something less
> > clever and more general.

> Have you looked on EmacsWiki?

> http://www.emacswiki.org/cgi-bin/wiki/HideLines

Ahhh!  That would have satisfied me.  Too bad I was
not sufficiently patient to wait for Mathias's
response to my query.  (I had really thought that this
was an easy one, and that I would quickly be pointed
in the right direction.  When that did not happen, I
assumed that no one had already implemented the
capability.)  Overlays are probably a better way to
implement it.  However, for my own purposes, the extra
feedback from my own implementation (which I posted
elsewhere in this thread) about how many lines are
affected by commands makes it more useful to me.

Up to now, I had not been regarding EmacsWiki as a
resource for this sort of quest.  I will consult it in
future.  Thanks for the pointer.

Regards,
  David V.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Hiding lines based on a regexp
  2005-05-31  0:52   ` David Vanderschel
@ 2005-05-31  8:07     ` Thien-Thi Nguyen
  0 siblings, 0 replies; 9+ messages in thread
From: Thien-Thi Nguyen @ 2005-05-31  8:07 UTC (permalink / raw)


"David Vanderschel" <DJV4@Austin.RR.com> writes:

> quickly be pointed
> in the right direction

any answer you get in less than two years is "quick", sonny!  two
to twenty years, "forthcoming".  twenty to two-hundred, "off-hand"
[insert yet-uncapped flying-over-palm monkey story here], more
than that, "{de}liberate{d}".  (end curmudgeon mode ;-)

thi

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-05-31  8:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-27 22:10 Hiding lines based on a regexp David Vanderschel
2005-05-27 23:02 ` Pascal Bourguignon
2005-05-28  0:04   ` David Vanderschel
2005-05-28  5:24 ` Travis Spencer
     [not found] ` <mailman.2153.1117258073.25862.help-gnu-emacs@gnu.org>
2005-05-28  9:37   ` Thien-Thi Nguyen
2005-05-30  4:57 ` David Vanderschel
2005-05-30  7:11 ` Mathias Dahl
2005-05-31  0:52   ` David Vanderschel
2005-05-31  8:07     ` Thien-Thi Nguyen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.