Subject: bug#22756: closed (Re: bug#22756: 25.1.50; thing-at-point-looking-at endless loop)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 27 Feb 2016 11:30:02 +0000

Your bug report

#22756: 25.1.50; thing-at-point-looking-at endless loop

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].

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

Subject: Re: bug#22756: 25.1.50; thing-at-point-looking-at endless loop
From: Eli Zaretskii <[email-masked]>
To: Tino Calancha <[email-masked]>
Cc: [email-masked]
Date: Sat, 27 Feb 2016 13:28:57 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Mon, 22 Feb 2016 00:06:27 +0900 (JST)
> From: Tino Calancha <[email-masked]>
> 
> ;; Bad: endless loop
> (with-temp-buffer
>    (require 'thingatpt)
>    (thing-at-point-looking-at "^"))

Thanks, fixed on the emacs-25 branch.

Subject: 25.1.50; thing-at-point-looking-at endless loop
From: Tino Calancha <[email-masked]>
To: [email-masked]
Date: Mon, 22 Feb 2016 00:06:27 +0900 (JST)
List-Id: <debbugs-submit.debbugs.gnu.org>

Good (or morning afternoon evening night)

emacs -Q:

;; OK
(with-temp-buffer
   (looking-at "^"))
t
;; OK
(with-temp-buffer
   (looking-back "^"))
t
;; Bad: endless loop
(with-temp-buffer
   (require 'thingatpt)
   (thing-at-point-looking-at "^"))

In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.29)
Repository revision: 27d343070d02210316e69e4f7da1faeea2d87608

diff --git a/thingatpt.el b/thingatpt.el
index 1686c02..1040f15 100644
--- a/thingatpt.el
+++ b/thingatpt.el
@@ -501,11 +501,14 @@ point."
       ;; Search back repeatedly from end of next match.
       ;; This may fail if next match ends before this match does.
       (re-search-forward regexp forward-bound 'limit)
-      (while (and (re-search-backward regexp backward-bound t)
-		  (or (> (match-beginning 0) old-point)
-		      (and (looking-at regexp)	; Extend match-end past search start
-			   (>= (match-end 0) old-point)
-			   (setq match (point))))))
+	  (let (old-match)
+		(while (and (re-search-backward regexp backward-bound t)
+					(setq old-match (point))
+					(not (equal old-match match))
+			(or (> (match-beginning 0) old-point)
+				(and (looking-at regexp)	; Extend match-end past search start
+				 (>= (match-end 0) old-point)
+				 (setq old-match match match (point)))))))
       (if (not match) nil
 	(goto-char match)
 	;; Back up a char at a time in case search skipped