Subject: bug#15580: closed (Re: bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning)

From: [email-masked] (GNU bug Tracking System)
Date: Tue, 15 Oct 2013 12:35:04 +0000

Your bug report

#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning

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

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

Subject: Re: bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning
From: Stefan Monnier <[email-masked]>
To: Dima Kogan <[email-masked]>
Cc: [email-masked]
Date: Mon, 14 Oct 2013 15:25:17 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

> and uses the results of this search even if it failed. The attached
> patch explicitly checks for search failure and exits the function in
> that case.

Thanks.  I slightly simplified your patch (since re-search-forward
already signal search-failed if the 3rd arg is nil) and installed it.

        Stefan

PS: This is at least the second "tiny" patch you contributed, so you're
on course to hit the limit of what we can accept without
copyright paperwork.  If you'd like to sign this paperwork already to
avoid future delays, I can send you the needed forms.

Subject: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning
From: Dima Kogan <[email-masked]>
To: [email-masked]
Date: Thu, 10 Oct 2013 00:01:22 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi.

I'm observing subword-capitalize get confused when called near the end
of a buffer. Instead of doing nothing like capitalize-word does,
subword-capitalize jumps to around the beginning of the buffer and
capitalizes something there.

The cause is simple. subword-capitalize does

(re-search-forward "[[:alpha:]]" ....)

and uses the results of this search even if it failed. The attached
patch explicitly checks for search failure and exits the function in
that case.

>From 3329a22e633ce345d727ebceb81d3183bd74372f Mon Sep 17 00:00:00 2001
From: Dima Kogan <[email-masked]>
Date: Wed, 9 Oct 2013 23:57:25 -0700
Subject: [PATCH] subword-capitalize now fails gracefully at end-of-buffer

---
 lisp/progmodes/subword.el | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/subword.el b/lisp/progmodes/subword.el
index 8cf4feb..1866ad9 100644
--- a/lisp/progmodes/subword.el
+++ b/lisp/progmodes/subword.el
@@ -260,21 +260,25 @@ Optional argument ARG is the same as for `capitalize-word'."
   (let ((count (abs arg))
 	(start (point))
 	(advance (if (< arg 0) nil t)))
-    (dotimes (i count)
-      (if advance
-	  (progn (re-search-forward
-		  (concat "[[:alpha:]]")
-		  nil t)
-		 (goto-char (match-beginning 0)))
-	(subword-backward))
-      (let* ((p (point))
-	     (pp (1+ p))
-	     (np (subword-forward)))
-	(upcase-region p pp)
-	(downcase-region pp np)
-	(goto-char (if advance np p))))
-    (unless advance
-      (goto-char start))))
+
+    (catch 'search-failed
+      (dotimes (i count)
+        (if advance
+            (progn
+              (when (not (re-search-forward
+                          (concat "[[:alpha:]]")
+                          nil t))
+                (throw 'search-failed "search failed"))
+              (goto-char (match-beginning 0)))
+          (subword-backward))
+        (let* ((p (point))
+               (pp (1+ p))
+               (np (subword-forward)))
+          (upcase-region p pp)
+          (downcase-region pp np)
+          (goto-char (if advance np p))))
+      (unless advance
+        (goto-char start)))))
 
 
 
-- 
1.8.3.2