Subject: bug#8667: closed (RE: bug#8667: 24.0.50; `bounds-of-thing-at-point' returns (N . N) for `comment')

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 19 May 2011 17:13:02 +0000

Your bug report

#8667: 24.0.50; `bounds-of-thing-at-point' returns (N . N) for `comment'

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
8667: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8667
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: RE: bug#8667: 24.0.50; `bounds-of-thing-at-point' returns (N . N) for `comment'
From: "Drew Adams" <[email-masked]>
To: "'Stefan Monnier'" <[email-masked]>
Cc: [email-masked]
Date: Thu, 19 May 2011 10:12:22 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

> Installed a patch along the lines of what you suggested.

No, I don't think you did.  I just downloaded the latest thingatpt.el.  There is
no fix AFAICT.

There are still the two problems reported for `bounds-of-thing-at-point' in this
bug report: (1) it can return a cons with equal car and cdr (representing an
empty thing), (2) it can return a cons representing only whitespace, instead of
returning nil when there is no comment at point.

1. You did not filter out the case where (= beg real-end) or
(= real-beg end), so `bounds-of-thing-at-point' can still return a cons with
equal car and cdr.

You need to add these conditions to the tests:

(and beg real-end (<= beg orig) (<= orig real-end)
                  (/= beg real-end) ; <===== NEEDED
                  (cons beg real-end))
...

(and real-beg end (<= real-beg orig) (<= orig end)
                  (/= real-beg end) ; <===== NEEDED
                  (cons real-beg end))

2. It is still the case that (bounds-of-thing-at-point 'comment) can return a
cons representing only whitespace, when called outside a comment.  Put point
here, for instance:

(defun bounds-of-thing-at-point...
       ^

It should always return nil, never return a cons, when there is no comment at
point.  This is a `b-o-t-a-p' bug (not a `forward-comment' bug).  In turn, this
bug causes (thing-at-point 'comment) to return " " at such a location.

Subject: 24.0.50; `bounds-of-thing-at-point' returns (N . N) for `comment'
From: "Drew Adams" <[email-masked]>
To: <[email-masked]>
Date: Thu, 12 May 2011 17:46:33 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

emacs -Q
 
Put point at position 3061 in file thingatpt.el (i.e., just before the
`a' of `condition-case').
 
M-: (bounds-of-thing-at-point 'comment)
returns (3061 . 3061), which represents an empty thing, "".
 
This happens at most positions, probably all positions outside a comment.
 
The code should handle this kind of case correctly (in other respects it
seems to work OK for comments).
 
The problem is that there is no `beginning-op' or `end-op' and all of
the calls to `forward-thing' (with 1 and -1) do not move point at all,
and return nil.  So the code falls through to the end:
 
(let ((end (point))
      (real-beg
       (progn
        (funcall
         (or (get thing 'beginning-op)
             (lambda () (forward-thing thing -1))))
        (point))))
  ;; real-beg = end = (point).  Result is (cons 3061 . 3061).
  (if (and real-beg end (<= real-beg orig) (<= orig end))
      (cons real-beg end)))

`bounds-of-thing-at-point' should foresee such a case (that `forward-THING' does
nothing).  IOW, it should of course be fixed for this problem.

But it sounds like `forward-comment' should also be fixed so that it acts like
other `forward-THING' functions, and not just be a no-op when outside a comment.
 
In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
 of 2011-05-10 on 3249CTO
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.5) --no-opt --cflags
-Ic:/build/include'