all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Howard Melman <hmelman@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 48317@debbugs.gnu.org
Subject: bug#48317: 27.1; text-property-search-forward moves point to end when not found
Date: Wed, 12 May 2021 12:29:10 -0400	[thread overview]
Message-ID: <1A7FC13A-A462-4D59-A0C1-64761BDE12A5@gmail.com> (raw)
In-Reply-To: <878s4kjaug.fsf@gnus.org>



On May 12, 2021, at 10:16 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:

> Howard Melman <hmelman@gmail.com> writes:
> 
>>    ;; a region with the specfied face is found,
>>    ;; point is moved to the beginning of it
>>    (text-property-search-forward 'face 'font-lock-function-name-face)
>> 
> No, here you're looking for regions where `face' is not
> `font-lock-function-name-face' -- which will indeed leave you at the
> start of the region where `face' is `font-lock-function-name-face', but
> that's not really what the function matched.

I have read the above a dozen times and still am not sure I follow
it. AIUI since predicate is nil this is looking for regions where face
is not font-lock-function-name-face.  But how does that leave you at
the start of a region where face is indeed
font-lock-function-name-face?  

Is what it's doing leaving you at the end of a region where face isn't
font-lock-function-name-face? (Which thanks to Stephen Berman I
realize that the function leaving you at the beginning or end of a
match was very significant to understanding what was happening).  If
so I think that is not at all intuitive from reading the above line of
code.

> But I understand your confusion now.  

Thank you, I thought I was going crazy.

> The function searches for areas where a text property is matching
> something (according to PREDICATE), and leaves point at the end of the
> match.  You, instead, expect it to leave point at the start of the
> match, which is the opposite of what it does.

I want to be more explicit here.  I do expect it to search for areas
where a text property is matching something.  It of course is
dependent on the value of all of its arguments including PREDICATE,
though I'd expect the default value of PREDICATE to DTRT in the common
case.  I know that common can be misunderstood but for a search
function I thought I was on strong ground that "find the thing I
specify" is the common case.  I don't much care whether this function
leaves you at the start or end of the match, I'd expect to find out
that specific detail from the docstring or observed behavior.  And
usually if I'm lucky I find in the docstring, manual or code some
convenient idiom like your while loop example that makes this choice
very convenient in actual use.

AIUI, all of this confusion is because "leaves you at the end of a not
matching area" and "leaves you at the beginning of a matching area"
happen to be the same place if such an area exists, but is quite
different if it doesn't.

Or could have been avoided if the function was named 
goto-end-of-region-not-matching-text-property
which I *think* is an accurate (though horrible) name?

> Hm...  Oh!  That's wrong in the doc string, too -- it says that it moves
> point to the start of the region, which it certainly doesn't.  I've now
> fixed this in the two doc strings.

It's probably impossible to change in the signature because of
compatibility but perhaps this could inform the docstring.  AIUI if
this function is not passed a VALUE or PREDICATE it searches for
regions that contain PROPERTY (a "trick" because a property having a
nil value is the same as not being present).  But with just a VALUE it
searches for areas that don't have the PROPERTY/VALUE combo because
PREDICATE is nil.  And if PREDICATE is t it searches for areas that do
have that combo.

Since in lisp a default optional argument is nil, I think the behavior
with the default value of PREDICATE is reversed from what it should be
for a function named "search". Particularly since it changes the sense
of the function from when just PROPERTY is passed as opposed to when
PROPERTY and VALUE are passed (right?).

Your example of using this function with a while loop definitely helps
reveal its intended use.  Perhaps including one when passing VALUE to
the function would help?

I will happily commented on a proposed docstring if you post it here.
I've not signed papers but do I have to for docstring contributions?

Thanks.

Howard





  reply	other threads:[~2021-05-12 16:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-09 16:41 bug#48317: 27.1; text-property-search-forward moves point to end when not found Howard Melman
2021-05-09 17:07 ` Eli Zaretskii
     [not found]   ` <616F7732-ED83-40F0-A460-9298608EAD91@gmail.com>
2021-05-09 17:48     ` Eli Zaretskii
     [not found]       ` <8877DDB9-7D2B-4DCC-8374-EB8391134EAC@gmail.com>
2021-05-09 18:33         ` Eli Zaretskii
2021-05-09 19:48           ` Howard Melman
2021-05-10  9:05           ` Lars Ingebrigtsen
2021-05-10 13:06             ` Howard Melman
2021-05-11 12:32               ` Lars Ingebrigtsen
2021-05-11 12:48                 ` Eli Zaretskii
2021-05-11 13:14                   ` Lars Ingebrigtsen
2021-05-11 14:20                 ` Howard Melman
2021-05-11 16:36                   ` Lars Ingebrigtsen
2021-05-11 19:28                     ` Howard Melman
2021-05-11 23:18                       ` Stephen Berman
2021-05-12 14:16                       ` Lars Ingebrigtsen
2021-05-12 16:29                         ` Howard Melman [this message]
2021-05-12 16:55                           ` Lars Ingebrigtsen
     [not found]                             ` <5AA9C2CD-D20B-4B9D-83D6-9002E9396558@gmail.com>
2022-05-13 18:32                               ` Howard Melman
2022-05-14  2:19                                 ` 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

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

  git send-email \
    --in-reply-to=1A7FC13A-A462-4D59-A0C1-64761BDE12A5@gmail.com \
    --to=hmelman@gmail.com \
    --cc=48317@debbugs.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 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.