all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Dmitry Gutov <dgutov@yandex.ru>, 9300@debbugs.gnu.org
Subject: bug#9300: 24.0.50; `bounds-of-thing-at-point' does not return nil when just after THING
Date: Tue, 23 Feb 2016 08:15:23 -0800 (PST)	[thread overview]
Message-ID: <e57a89a3-4fda-4cb7-91c2-646aee0cbd22@default> (raw)
In-Reply-To: <56CC32CD.5050906@yandex.ru>

> Tried it, and yes it does. Otherwise, I wouldn't understand what
> this bug is about.

Sorry, my bad (it's been several years since I filed this).
Yes, it should return nil, as there is NO symbol at point.

> Your reasoning seems valid, however by now this behavior is
> ingrained into my expectations of how thing-at-point should behave.

It is your expectation that is wrong.  There are plenty of uses
of thing-at-point that go far beyond just looking for a default
value of a name near point or trying to complete a name before
(not at) point.

Those other uses include the need to test whether or not there
IS a given THING at point.  The design itself depends on this
difference: Is there a THING at point or not?  The purpose of
thingatpt.el is not only to maximize finding a THING that is
_near_ point.  One purpose is to test whether there IS a THING
AT point.

If your code wants _only_ to complete a name (or other THING)
that is at or _near_ point, then it should temporarily move to
where it really wants to pick up the name (or other THING).
Your code should not depend on an off-by-one bug, however
longstanding.

I am well aware of how useful picking up a name at or _near_
point can be, either to complete it or to use it as a default
value. I see (in emacs-devel) that you are now looking into
picking up a name near point - but you are limiting that to the
same line.

I'm glad someone is finally getting around to this.  FWIW, I
did it in 1996 and have been using it ever since (I proposed
it for Emacs).

But my code does not limit looking to the current line.
Users can control what "near" means using these variables,
which are the max number of chars and lines to search from
point, left-and-right and up-and-down, respectively:

 (tap-)near-point-x-distance - default 50 chars
 (tap-)near-point-y-distance - default 50 lines

These variables are used typically by functions that invoke
`tap-thing/form-nearest-point-with-bounds', and that provide
default text for minibuffer input or text to complete.

`thingatpt+.el' includes these "nearest-point" functions
(with library prefix `tap-'):

 bounds-of-form-nearest-point
 bounds-of-list-nearest-point
 bounds-of-sexp-nearest-point
 bounds-of-symbol-nearest-point
 bounds-of-thing-nearest-point
 color-nearest-point
 color-nearest-point-with-bounds
 find-fn-or-var-nearest-point  (a command)
 form-nearest-point
 form-nearest-point-with-bounds
 list-contents-nearest-point
 list-nearest-point
 list-nearest-point-with-bounds
 list-nearest-point-as-string
 non-nil-symbol-name-nearest-point
 non-nil-symbol-nearest-point
 number-nearest-point
 region-or-word-nearest-point
 region-or-non-nil-symbol-name-nearest-point
 sentence-nearest-point
 sexp-nearest-point
 sexp-nearest-point-with-bounds
 string-contents-nearest-point
 string-nearest-point
 symbol-name-nearest-point
 symbol-nearest-point
 symbol-nearest-point-with-bounds
 thing-nearest-point
 thing-nearest-point-with-bounds
 unquoted-list-nearest-point
 unquoted-list-nearest-point-as-string
 word-nearest-point

So I do have some experience with the kinds of uses of
thing-at-point that you are interested in.  But there are
lots of other uses, as well, which rely on its behavior
being usable in repetitive (iterative, recursive) contexts.

And that means relying on its treating the position after
a thing differently from the position before the thing, wrt
whether or not there is a THING at that position.

If you never make use of thing-at-point, beyond wanting to
pick up a thing at or near point, and you don't care much
about exactly where point is in relation to the thing, then
you won't understand the importance of this bug.

My code that does use thing-at-point repetitively needs the
basic code to distinguish whether there is a thing at point
in a precise way.  It is not enough to just maximize the
possibility of obtaining a thing near point.  The point of
such code is instead to perform operations on occurrences
of a specific THING over a given region of text.

One example is `isearchp-thing', which does incremental
search within THING search contexts.  The contexts are
determined by scanning a region/buffer progressively, and
this depends on basic thing-at-point functions doing the
right thing wrt whether there is a THING at a given point.

The scanning function is `isearchp-thing-scan', and it is
in its code that you will find the comment included in this
bug report:

;; The correct code here is (setq beg thg-end).  However,
;; unless you use my library `thingatpt+.el' or unless Emacs
;; bug #9300 is fixed that will loop forever.  In that case
;; we move forward a char to prevent looping, but that means
;; that the position just after a THING is considered to be
;; covered by the THING (which is incorrect).

(setq beg (if (featurep 'thingatpt+) thg-end (1+ thg-end)))

> This would be a breaking change. For instance, it will make
> (bounds-of-thing-at-point 'symbol) unsuitable for use in a
> completion-at-point-functions element, to compute the first
> two values of the returned list, because during completion 
> you're most often "after" the symbol. And I do use it for
> that purpose in one third-party package.

See previous.  It is the calling code that is wrong, here (and
no need for quoting "after" - you are after, not on, the symbol).
The calling code should instead check `bounds-of-thing-at-point'
at the right position.

There has to be a difference between there being a THING at
point and there not being a THING at point.  And thingatpt.el
is  designed for there not being at THING at point when, well,
there is no THING at point.  At point is not the same as before
point.

(Yes, point is _between_ characters.  But one or the other,
but not both, positions wrt a char that is part of THING needs
to be picked as its start or end.

Especially for uses of thing-at-point that are iterative or
recursive, it is important that either the position after the
last char or the position before the first char not be included
in the THING "at" that position.  This should be obvious, but
is not paid attention to if one's only interest is in grabbing
some text that is _near_ point but might not be exactly _at_
point.

> At the very least, this will change the existing behavior.

Yes - it is a bug fix.  The current behavior is bugged.

> > This is the design of the thingatpt code, and the reason why
> > `<=' instead of `<' is a bug:
> >
> >    the function that is (get THING 'end-op) moves PAST the THING,
> >    so that point is not on the THING.  This is true generally, no
> >    matter the type of THING.
> 
> That's not a quote from thingatpt.el.

It is nevertheless the design (intention), clear from the code.





  reply	other threads:[~2016-02-23 16:15 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <<B1052724B2D446C59E233FC1BD437723@us.oracle.com>
2015-07-29  1:44 ` bug#9300: 24.0.50; `bounds-of-thing-at-point' does not return nil when just after THING Drew Adams
2016-01-15 13:33   ` Drew Adams
2016-02-23  1:01     ` Dmitry Gutov
2016-02-23  6:37       ` Drew Adams
2016-02-23  7:59         ` Andreas Röhler
2016-02-23 10:22         ` Dmitry Gutov
2016-02-23 16:15           ` Drew Adams [this message]
2016-02-24  0:52             ` Dmitry Gutov
2016-02-24  1:31               ` Drew Adams
2016-02-26  1:03                 ` Dmitry Gutov
2016-02-26  1:44                   ` Drew Adams
2016-02-26 10:15                     ` Dmitry Gutov
2016-02-26 14:39                       ` Drew Adams
2016-02-26 15:25                         ` Dmitry Gutov
2016-02-26 17:00                           ` Drew Adams
2022-04-28 11:24       ` Lars Ingebrigtsen
2022-04-28 15:49         ` Drew Adams
2011-08-14 22:36 Drew Adams
2016-06-20  9:21 ` Tino Calancha
2016-06-20 12:53   ` Dmitry Gutov
2016-06-20 13:11     ` Tino Calancha
2016-06-20 14:48   ` Eli Zaretskii
2016-06-21  3:01     ` Tino Calancha
     [not found]   ` <<8337o79arh.fsf@gnu.org>
2016-06-20 17:50     ` Drew Adams
2016-06-20 18:38       ` Andreas Röhler
2016-06-20 20:04       ` Eli Zaretskii
2016-06-21  6:14         ` Andreas Röhler
2016-06-21 12:50           ` Eli Zaretskii
2016-06-21 13:07             ` Andreas Röhler
2016-06-21 15:13               ` Eli Zaretskii
2016-06-21 13:31             ` Drew Adams
2016-06-21 15:16               ` Eli Zaretskii
2016-06-22  5:23             ` Fwd: " Andreas Röhler
2016-07-06 21:21               ` John Wiegley
2016-07-06 21:51                 ` Dmitry Gutov
2016-07-06 23:31                   ` Drew Adams
2016-07-07  8:00                     ` Andreas Röhler
2016-06-21 13:25           ` Drew Adams
     [not found]   ` <<<8337o79arh.fsf@gnu.org>
     [not found]     ` <<0e2c9c67-12a2-4712-92d2-e3c204f46838@default>
     [not found]       ` <<83twgn7hjx.fsf@gnu.org>
2016-06-20 23:34         ` Drew Adams
2016-06-20 23:59           ` Noam Postavsky
2016-06-21  0:47             ` Drew Adams

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=e57a89a3-4fda-4cb7-91c2-646aee0cbd22@default \
    --to=drew.adams@oracle.com \
    --cc=9300@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    /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.