GNU bug report logs -
#36486
[PATCH] Add tests for text-property-search to check prop-match-value
Previous Next
Reported by: Stefan Kangas <stefan <at> marxist.se>
Date: Wed, 3 Jul 2019 09:45:01 UTC
Severity: wishlist
Tags: fixed, patch
Fixed in version 27.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 36486 in the body.
You can then email your comments to 36486 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Wed, 03 Jul 2019 09:45:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Kangas <stefan <at> marxist.se>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 03 Jul 2019 09:45:03 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Attached is a patch with additional test cases for
text-property-search which checks the returned match object. Unlike
older test cases, these also check the value of prop-match-value.
Thanks,
Stefan Kangas
[0001-Add-tests-for-text-property-search-to-check-prop-mat.patch (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Sat, 06 Jul 2019 14:26:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 36486 <at> debbugs.gnu.org (full text, mbox):
Stefan Kangas <stefan <at> marxist.se> writes:
> Attached is a patch with additional test cases for
> text-property-search which checks the returned match object. Unlike
> older test cases, these also check the value of prop-match-value.
Looks good; I've now applied them to the trunk.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 06 Jul 2019 14:26:02 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 27.1, send any further explanations to
36486 <at> debbugs.gnu.org and Stefan Kangas <stefan <at> marxist.se>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sat, 06 Jul 2019 14:26:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Sun, 07 Jul 2019 23:03:01 GMT)
Full text and
rfc822 format available.
Message #15 received at 36486 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> Attached is a patch with additional test cases for
>> text-property-search which checks the returned match object. Unlike
>> older test cases, these also check the value of prop-match-value.
>
> Looks good; I've now applied them to the trunk.
BTW, I tried to use text-property-search as a command interactively,
but it lacks support for reading the second argument VALUE.
Here is the patch that implements it:
[text-property-search-value.patch (text/x-diff, inline)]
diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el
index 41ca07057e..5027bc406c 100644
--- a/lisp/emacs-lisp/text-property-search.el
+++ b/lisp/emacs-lisp/text-property-search.el
@@ -54,10 +54,14 @@ text-property-search-forward
that's matching), and `prop-match-value' (the value of PROPERTY
at the start of the region)."
(interactive
- (list
- (let ((string (completing-read "Search for property: " obarray)))
- (when (> (length string) 0)
- (intern string obarray)))))
+ (let* ((property (completing-read "Search for property: " obarray))
+ (property (when (> (length property) 0)
+ (intern property obarray)))
+ (value (when property
+ (completing-read "Search for property value: " obarray)))
+ (value (when (> (length value) 0)
+ (intern value obarray))))
+ (list property value)))
(cond
;; No matches at the end of the buffer.
((eobp)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Mon, 08 Jul 2019 16:19:01 GMT)
Full text and
rfc822 format available.
Message #18 received at 36486 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> + (let* ((property (completing-read "Search for property: " obarray))
> + (property (when (> (length property) 0)
> + (intern property obarray)))
> + (value (when property
> + (completing-read "Search for property value: " obarray)))
> + (value (when (> (length value) 0)
> + (intern value obarray))))
Hm... well, the value doesn't have to be a symbol, so I don't think
this is quite right -- it could be a string, or, well, anything. I
think that's why it doesn't prompt for value in the interactive form,
because it didn't seem useful.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Mon, 08 Jul 2019 21:29:01 GMT)
Full text and
rfc822 format available.
Message #21 received at 36486 <at> debbugs.gnu.org (full text, mbox):
>> + (let* ((property (completing-read "Search for property: " obarray))
>> + (property (when (> (length property) 0)
>> + (intern property obarray)))
>> + (value (when property
>> + (completing-read "Search for property value: " obarray)))
>> + (value (when (> (length value) 0)
>> + (intern value obarray))))
>
> Hm... well, the value doesn't have to be a symbol, so I don't think
> this is quite right -- it could be a string, or, well, anything. I
> think that's why it doesn't prompt for value in the interactive form,
> because it didn't seem useful.
But searching for a certain font-lock face value is the most useful
application of this command. How do you do that?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Mon, 08 Jul 2019 21:55:02 GMT)
Full text and
rfc822 format available.
Message #24 received at 36486 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> But searching for a certain font-lock face value is the most useful
> application of this command. How do you do that?
Non-interactively?
(I've never used it to search for any faces. :-))
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Tue, 09 Jul 2019 20:38:02 GMT)
Full text and
rfc822 format available.
Message #27 received at 36486 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> But searching for a certain font-lock face value is the most useful
>> application of this command. How do you do that?
>
> Non-interactively?
>
> (I've never used it to search for any faces. :-))
It is useful interactively to find errors fontified
with the error face. Here is a better patch that
can read symbols as well as strings:
[text-property-search-value.2.patch (text/x-diff, inline)]
diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el
index 41ca07057e..9c45cee3c1 100644
--- a/lisp/emacs-lisp/text-property-search.el
+++ b/lisp/emacs-lisp/text-property-search.el
@@ -54,10 +54,13 @@ text-property-search-forward
that's matching), and `prop-match-value' (the value of PROPERTY
at the start of the region)."
(interactive
- (list
- (let ((string (completing-read "Search for property: " obarray)))
- (when (> (length string) 0)
- (intern string obarray)))))
+ (let* ((property (completing-read "Search for property: " obarray))
+ (property (when (> (length property) 0)
+ (intern property obarray)))
+ (value (when property
+ (read-from-minibuffer "Search for property value: "
+ nil nil t nil "nil"))))
+ (list property value)))
(cond
;; No matches at the end of the buffer.
((eobp)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Tue, 09 Jul 2019 21:53:01 GMT)
Full text and
rfc822 format available.
Message #30 received at 36486 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> It is useful interactively to find errors fontified
> with the error face. Here is a better patch that
> can read symbols as well as strings:
[...]
> + (value (when property
> + (read-from-minibuffer "Search for property value: "
> + nil nil t nil "nil"))))
> + (list property value)))
I don't understand -- this will still return a symbol. (And error out
if you enter stuff like "foo bar".)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Wed, 10 Jul 2019 22:37:01 GMT)
Full text and
rfc822 format available.
Message #33 received at 36486 <at> debbugs.gnu.org (full text, mbox):
>> It is useful interactively to find errors fontified
>> with the error face. Here is a better patch that
>> can read symbols as well as strings:
>
> [...]
>
>> + (value (when property
>> + (read-from-minibuffer "Search for property value: "
>> + nil nil t nil "nil"))))
>> + (list property value)))
>
> I don't understand -- this will still return a symbol. (And error out
> if you enter stuff like "foo bar".)
Yes, entering a symbol returns a symbol, entering a string
like "foo bar" returns a string "foo bar" literally.
Currently text-property-search-forward has more problems:
today I needed to search the property ‘face’ with the value
‘hi-yellow’ in the buffer with regexps highlighted by hi-lock.el.
Executing interactively:
M-x text-property-search-forward RET face RET hi-yellow RET
failed to find the property because all hi-lock occurrences were
combined with font-lock text properties, i.e. all they had the
property ‘face’ with the value ‘(hi-yellow font-lock-keyword-face)’
and text-property-search-forward fails to find a value in the list
of values.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Thu, 11 Jul 2019 14:18:02 GMT)
Full text and
rfc822 format available.
Message #36 received at 36486 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
>> I don't understand -- this will still return a symbol. (And error out
>> if you enter stuff like "foo bar".)
>
> Yes, entering a symbol returns a symbol, entering a string
> like "foo bar" returns a string "foo bar" literally.
Oh, right. Hm. Well, entering things with "..." is very unusual in
Emacs prompts, so if we want that, the prompt should at least say that
that's what's expected...
> Currently text-property-search-forward has more problems:
> today I needed to search the property ‘face’ with the value
> ‘hi-yellow’ in the buffer with regexps highlighted by hi-lock.el.
> Executing interactively:
>
> M-x text-property-search-forward RET face RET hi-yellow RET
>
> failed to find the property because all hi-lock occurrences were
> combined with font-lock text properties, i.e. all they had the
> property ‘face’ with the value ‘(hi-yellow font-lock-keyword-face)’
> and text-property-search-forward fails to find a value in the list
> of values.
Yes, you can't really use text-property-search-forward to do that in any
meaningful manner, which is why I didn't add that to the interactive
bit. It's a function useful almost only when programming, and the only
useful interactive thing is to vaguely poke around in the buffer.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Thu, 11 Jul 2019 22:09:01 GMT)
Full text and
rfc822 format available.
Message #39 received at 36486 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>>> I don't understand -- this will still return a symbol. (And error out
>>> if you enter stuff like "foo bar".)
>>
>> Yes, entering a symbol returns a symbol, entering a string
>> like "foo bar" returns a string "foo bar" literally.
>
> Oh, right. Hm. Well, entering things with "..." is very unusual in
> Emacs prompts, so if we want that, the prompt should at least say that
> that's what's expected...
Fixed in the following patch.
>> Currently text-property-search-forward has more problems:
>> today I needed to search the property ‘face’ with the value
>> ‘hi-yellow’ in the buffer with regexps highlighted by hi-lock.el.
>> Executing interactively:
>>
>> M-x text-property-search-forward RET face RET hi-yellow RET
>>
>> failed to find the property because all hi-lock occurrences were
>> combined with font-lock text properties, i.e. all they had the
>> property ‘face’ with the value ‘(hi-yellow font-lock-keyword-face)’
>> and text-property-search-forward fails to find a value in the list
>> of values.
>
> Yes, you can't really use text-property-search-forward to do that in any
> meaningful manner, which is why I didn't add that to the interactive
> bit. It's a function useful almost only when programming, and the only
> useful interactive thing is to vaguely poke around in the buffer.
Implemented in this patch:
[text-property-search-value.3.patch (text/x-diff, inline)]
diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el
index 41ca07057e..a44516992a 100644
--- a/lisp/emacs-lisp/text-property-search.el
+++ b/lisp/emacs-lisp/text-property-search.el
@@ -54,10 +54,13 @@ text-property-search-forward
that's matching), and `prop-match-value' (the value of PROPERTY
at the start of the region)."
(interactive
- (list
- (let ((string (completing-read "Search for property: " obarray)))
- (when (> (length string) 0)
- (intern string obarray)))))
+ (let* ((property (completing-read "Search for property: " obarray))
+ (property (when (> (length property) 0)
+ (intern property obarray)))
+ (value (when property
+ (read-from-minibuffer "Search for property value (quote strings): "
+ nil nil t nil "nil"))))
+ (list property value)))
(cond
;; No matches at the end of the buffer.
((eobp)
@@ -200,7 +203,9 @@ text-property--match-p
(setq predicate #'equal))
((eq predicate nil)
(setq predicate (lambda (val p-val)
- (not (equal val p-val))))))
+ (not (if (and (listp p-val) (not (listp val)))
+ (member val p-val)
+ (equal val p-val)))))))
(funcall predicate value prop-value))
(provide 'text-property-search)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Fri, 12 Jul 2019 14:38:02 GMT)
Full text and
rfc822 format available.
Message #42 received at 36486 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> - (not (equal val p-val))))))
> + (not (if (and (listp p-val) (not (listp val)))
> + (member val p-val)
> + (equal val p-val)))))))
No, that's not an acceptable change, I think -- this function is a
search primitive, not a DWIM thing. There's an abundance of things that
can be stored in text properties, to be compared with any number of
predicates. You're trying to special-case it to search for faces, for
some reason, and that's not what it's for.
If you want a function to search for faces, that's something you can
write (based on this function), but that's not what this function is for.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Fri, 12 Jul 2019 18:59:01 GMT)
Full text and
rfc822 format available.
Message #45 received at 36486 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> - (not (equal val p-val))))))
>> + (not (if (and (listp p-val) (not (listp val)))
>> + (member val p-val)
>> + (equal val p-val)))))))
>
> No, that's not an acceptable change, I think -- this function is a
> search primitive, not a DWIM thing. There's an abundance of things that
> can be stored in text properties, to be compared with any number of
> predicates. You're trying to special-case it to search for faces, for
> some reason, and that's not what it's for.
Then it's possible to add lambda to `predicate' arg in interactive spec only
like below.
> If you want a function to search for faces, that's something you can
> write (based on this function), but that's not what this function is for.
Of course, I can write and add it to ~/.emacs. But the question is:
do you think this is generally useful? For example, to search
hi-lock properties, etc.
[text-property-search-value.4.patch (text/x-diff, inline)]
diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el
index 41ca07057e..867094539f 100644
--- a/lisp/emacs-lisp/text-property-search.el
+++ b/lisp/emacs-lisp/text-property-search.el
@@ -54,10 +54,16 @@ text-property-search-forward
that's matching), and `prop-match-value' (the value of PROPERTY
at the start of the region)."
(interactive
- (list
- (let ((string (completing-read "Search for property: " obarray)))
- (when (> (length string) 0)
- (intern string obarray)))))
+ (let* ((property (completing-read "Search for property: " obarray))
+ (property (when (> (length property) 0)
+ (intern property obarray)))
+ (value (when property
+ (read-from-minibuffer "Search for property value (quote strings): "
+ nil nil t nil "nil"))))
+ (list property value (lambda (val p-val)
+ (not (if (and (listp p-val) (not (listp val)))
+ (member val p-val)
+ (equal val p-val)))))))
(cond
;; No matches at the end of the buffer.
((eobp)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#36486
; Package
emacs
.
(Fri, 12 Jul 2019 23:41:02 GMT)
Full text and
rfc822 format available.
Message #48 received at 36486 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> linkov.net> writes:
> Of course, I can write and add it to ~/.emacs. But the question is:
> do you think this is generally useful? For example, to search
> hi-lock properties, etc.
I don't think this code complication belongs in that function. If there
should be a function to search for faces, then face-search-forward
should be written (and it would be a very simple call to
text-property-search-forward with the correct predicate).
But I haven't heard anybody clamouring for such a command, really...
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sat, 10 Aug 2019 11:24:09 GMT)
Full text and
rfc822 format available.
This bug report was last modified 5 years and 264 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.