unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Text property searching
@ 2018-04-15 22:56 Lars Ingebrigtsen
  2018-04-16  0:00 ` T.V Raman
                   ` (3 more replies)
  0 siblings, 4 replies; 52+ messages in thread
From: Lars Ingebrigtsen @ 2018-04-15 22:56 UTC (permalink / raw)
  To: emacs-devel

I've suggested a few times before that it would be nice to have search
functions that are... nicer... than the ones we have now
(`text-property-any' and `next-single-property-change'), and the
maintainer(s) at the time said "sure".  I think.

But I never implemented that wonderful function, because I could never
decide what it would look like.

But last night I think I got it: It should be just like search-forward,
only not.  (Hm.  I'm feeling a slight sense of deja vu while typing
this -- have I had this revelation before but forgotten about it?)

Anyway:

Let's say you have a region in the buffer that has the text property
`shr-url' with the value "http://fsf.org/", then:

(text-property-search-forward 'shr-url "http://fsf.org/" t)

would place point at the end of that region, and `match-beginning' and
`match-end' would point to the start and end.

The `t' there is the predicate: `t' means "equal", `nil' means "not
equal", and then you can write your own predicates for other uses.

So, to collect all urls from text properties, you'd write:

(while (text-property-search-forward 'shr-url nil nil)
  (push (get-text-property (match-beginning 0) 'shr-url) urls))

and that's it.  Or to collect all images:

(while (text-property-search-forward 'display 'image
                                     (lambda (elem val)
                                       (and (consp elem)
                                            (eq (car elem) val))))
  (push (plist-get (cdr (get-text-property (match-beginning 0) 'display)) :data)
        images))

Does this look OK to everybody?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

end of thread, other threads:[~2018-04-17 20:42 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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