unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Lars Ingebrigtsen <larsi@gnus.org>, Dmitry Gutov <dgutov@yandex.ru>
Cc: emacs-devel@gnu.org
Subject: RE: Text property searching
Date: Mon, 16 Apr 2018 07:30:26 -0700 (PDT)	[thread overview]
Message-ID: <9df73117-d5f2-4be2-a053-59d0eb5fe6c9@default> (raw)
In-Reply-To: <87y3hn2wdo.fsf@mouse.gnus.org>

> >> The `t' there is the predicate: `t' means "equal", `nil' means "not
> >> equal", and then you can write your own predicates for other uses.
> >
> > "Equals or includes" should be another popular predicate (think faces).
> 
> Yes, that's true...  We could have a special symbol for that, or would
> it be confusing?

FWIW -

My library `isearch-prop.el' has long let you Isearch zones
that have arbitrary text-property or overlay-property values.

I agree that an eq/equal-or-memq/member predicate can be
useful.  But it's not really enough when it comes to dealing
with properties, including but not limited to `face' and
similar (whose values can combine for an accumulated effect).

Like what you propose, the code I use lets you use an
arbitrary predicate, but matching allows for matches that
involve overlap of property values, in this sense: If the
PROPERTY value is an atom then it must be a member of the
set of test VALUES, but if the PROPERTY value is a list,
then at least one of its elements must be a member of VALUES.

https://www.emacswiki.org/emacs/download/isearch-prop.el

---

This is the crux of the property-matching & predicate code:

(defun isearchp-property-matches-p (type property values
                                    match-fn position)
  "Return non-nil if POSITION has PROPERTY with a value matching VALUES.
TYPE is `overlay', `text', or nil, and specifies the type of property.
TYPE nil means look for both overlay and text properties.  Return
 non-nil if either matches.

Matching means finding text with a PROPERTY value that overlaps with
VALUES: If the value of PROPERTY is an atom, then it must be a member
of VALUES.  If it is a list, then at least one list element must be a
member of VALUES.

MATCH-FN is a binary predicate that is applied to each item of VALUES
and a zone of text with property PROP.  If it returns non-nil then the
zone is a search hit."
  (let* ((ov-matches-p   nil)
         (txt-matches-p  nil)
         (ovchk-p        (and (or (not type)  (eq type 'overlay))))
         (ovs            (and ovchk-p  (overlays-at position))))
    (when ovchk-p
      (setq ov-matches-p
            (catch 'i-p-m-p
              (dolist (ov  ovs)
                (when (isearchp-some
                       values (overlay-get ov property) match-fn)
                  (throw 'i-p-m-p t)))
              nil)))
    (when (and (or (not type)  (eq type 'text)))
      (setq txt-matches-p
            (isearchp-some
             values (get-text-property position property) match-fn)))
    (or ov-matches-p  txt-matches-p)))

(defun isearchp-property-filter-pred (type property values)
  "Return a predicate that uses `isearchp-property-matches-p'.
TYPE, PROPERTY, and VALUES are used by that function.
The predicate is suitable as a value of `isearch-filter-predicate'."
  (let ((tag  (make-symbol "isearchp-property-filter-pred")))
    `(lambda (beg end)
       (and (or (not (boundp 'isearchp-reg-beg))
                (not isearchp-reg-beg)
                (>= beg isearchp-reg-beg))
            (or (not (boundp 'isearchp-reg-end))
                (not isearchp-reg-end)
                (< end isearchp-reg-end))
            (or (isearch-filter-visible beg end)
                (not (or (eq search-invisible t)
                         (not (isearch-range-invisible beg end)))))
            (catch ',tag
              (while (< beg end)
                (let ((matches-p
                       (isearchp-property-matches-p
                        ',type ',property
                        ',values
                        (isearchp-property-default-match-fn ',property)
                        beg)))
                  (unless (if matches-p
                              (not isearchp-complement-domain-p)
                            isearchp-complement-domain-p)
                    (throw ',tag nil)))
                (setq beg  (1+ beg)))
              t)))))



  parent reply	other threads:[~2018-04-16 14:30 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-15 22:56 Text property searching Lars Ingebrigtsen
2018-04-16  0:00 ` T.V Raman
2018-04-16  4:40 ` Dmitry Gutov
2018-04-16 12:01   ` Lars Ingebrigtsen
2018-04-16 13:04     ` Dmitry Gutov
2018-04-16 15:11       ` Lars Ingebrigtsen
2018-04-16 18:06         ` Eli Zaretskii
2018-04-16 18:30           ` Lars Ingebrigtsen
2018-04-16 14:30     ` Drew Adams [this message]
2018-04-16 17:52     ` Eli Zaretskii
2018-04-16 18:31       ` Lars Ingebrigtsen
2018-04-16 15:16 ` João Távora
2018-04-16 16:09   ` Lars Ingebrigtsen
     [not found]     ` <CALDnm52qb5jfjC181pS+UTwfFES95m=EYtyXJzya7pdBMz8rxA@mail.gmail.com>
     [not found]       ` <87d0yz15a3.fsf@mouse.gnus.org>
2018-04-16 16:54         ` João Távora
2018-04-16 16:57           ` Lars Ingebrigtsen
2018-04-16 17:30             ` João Távora
2018-04-16 17:35               ` Lars Ingebrigtsen
2018-04-16 18:26                 ` Lars Ingebrigtsen
2018-04-16 18:52                   ` Eli Zaretskii
2018-04-16 19:01                     ` Lars Ingebrigtsen
2018-04-16 19:48                       ` Eli Zaretskii
2018-04-16 19:53                         ` Lars Ingebrigtsen
2018-04-16 19:59                           ` Eli Zaretskii
2018-04-16 21:56                             ` Clément Pit-Claudel
2018-04-16 21:58                               ` Lars Ingebrigtsen
2018-04-16 22:06                                 ` João Távora
2018-04-16 22:21                                 ` Clément Pit-Claudel
2018-04-16 19:02                     ` Lars Ingebrigtsen
2018-04-16 19:50                       ` Eli Zaretskii
2018-04-16 19:56                         ` Lars Ingebrigtsen
2018-04-16 20:05                   ` Drew Adams
2018-04-16 20:11                     ` Lars Ingebrigtsen
2018-04-16 20:40               ` Lars Ingebrigtsen
2018-04-16 20:48                 ` Stefan Monnier
2018-04-16 21:17                 ` João Távora
2018-04-16 21:21                   ` Lars Ingebrigtsen
     [not found]                     ` <CALDnm51Hgs6b_Q=A0mZ=UMnOeOUX2fGE+dTf2JP4HOMF11-z8A@mail.gmail.com>
2018-04-16 21:32                       ` Lars Ingebrigtsen
2018-04-17 19:10                 ` Alan Mackenzie
2018-04-17 19:16                   ` Lars Ingebrigtsen
2018-04-17 20:31                     ` Alan Mackenzie
2018-04-17 20:42                       ` Lars Ingebrigtsen
2018-04-16 19:40             ` Alan Mackenzie
2018-04-16 19:49               ` Lars Ingebrigtsen
2018-04-16 20:07                 ` Alan Mackenzie
2018-04-16 20:31                   ` Lars Ingebrigtsen
2018-04-16 21:18   ` Lars Ingebrigtsen
2018-04-16 21:28     ` João Távora
2018-04-16 22:09       ` Lars Ingebrigtsen
2018-04-17 13:01         ` Stefan Monnier
2018-04-17 13:04           ` Lars Ingebrigtsen
2018-04-16 16:59 ` Lars Ingebrigtsen
2018-04-16 18:03   ` Lars Ingebrigtsen

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=9df73117-d5f2-4be2-a053-59d0eb5fe6c9@default \
    --to=drew.adams@oracle.com \
    --cc=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.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.
Code repositories for project(s) associated with this public inbox

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

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