From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.devel Subject: RE: Text property searching Date: Mon, 16 Apr 2018 07:30:26 -0700 (PDT) Message-ID: <9df73117-d5f2-4be2-a053-59d0eb5fe6c9@default> References: <87lgdo5bb3.fsf@mouse.gnus.org> <87y3hn2wdo.fsf@mouse.gnus.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1523889013 23201 195.159.176.226 (16 Apr 2018 14:30:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 16 Apr 2018 14:30:13 +0000 (UTC) Cc: emacs-devel@gnu.org To: Lars Ingebrigtsen , Dmitry Gutov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 16 16:30:09 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f858y-0005vr-UM for ged-emacs-devel@m.gmane.org; Mon, 16 Apr 2018 16:30:09 +0200 Original-Received: from localhost ([::1]:49970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f85B5-0006ZJ-Ga for ged-emacs-devel@m.gmane.org; Mon, 16 Apr 2018 10:32:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f859R-0005LF-6L for emacs-devel@gnu.org; Mon, 16 Apr 2018 10:30:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f859M-0006P2-5Z for emacs-devel@gnu.org; Mon, 16 Apr 2018 10:30:37 -0400 Original-Received: from userp2120.oracle.com ([156.151.31.85]:44830) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f859L-0006NF-Sa for emacs-devel@gnu.org; Mon, 16 Apr 2018 10:30:32 -0400 Original-Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w3GEQc8m090087; Mon, 16 Apr 2018 14:30:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=HxOcPwPzyAE9W8s29eakZlFI+pq5lfmqbJrLgUPDPmc=; b=oHZCrRCu1egGPceeMTmkiyshmaxgiuTyculkKxCFbr8vE0lwLIv2nXnvUdmx89q7BQI/ YIjB33RYZ6uAUMrOEiHiRo+Rp/fiLQlZ7A2OgkCMp6Mx/nAOmD0BWLUqybtSr9EACVFM F9d6TQJo7wYlmv2L3QAX05HoFIKbbAIC2/aDpTYfSmQoTYweaUuCG51njcr+wDdAWgkF lnMTJCS2FhtqzCV1uNdbv1NsfZ0+33Hhk1vE3OrULfYpNMpMNEDPMomZGg1Fql4vql2p FACYrm3pqOLWovgxmlYOGkFLcX92koeY9fcDjsDg3UlnUOiGZ/egfPXFioSRpc5oMh45 NQ== Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2hbam55cm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Apr 2018 14:30:29 +0000 Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w3GEUSmV017228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Apr 2018 14:30:28 GMT Original-Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w3GEURbq000670; Mon, 16 Apr 2018 14:30:27 GMT In-Reply-To: <87y3hn2wdo.fsf@mouse.gnus.org> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4678.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8864 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=17 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1804160136 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224643 Archived-At: > >> 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). >=20 > 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) (>=3D 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)))))