all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "David Vanderschel" <DJV4@Austin.RR.com>
Subject: Re: Hiding lines based on a regexp
Date: Mon, 30 May 2005 04:57:03 GMT	[thread overview]
Message-ID: <z2xme.23768$6g3.10577@tornado.texas.rr.com> (raw)
In-Reply-To: IVMle.6528$j51.1551@tornado.texas.rr.com

"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.

  parent reply	other threads:[~2005-05-30  4:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2005-05-30  7:11 ` Mathias Dahl
2005-05-31  0:52   ` David Vanderschel
2005-05-31  8:07     ` Thien-Thi Nguyen

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

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

  git send-email \
    --in-reply-to='z2xme.23768$6g3.10577@tornado.texas.rr.com' \
    --to=djv4@austin.rr.com \
    /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.
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.