unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning
@ 2013-10-10  7:01 Dima Kogan
  2013-10-14 19:25 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Dima Kogan @ 2013-10-10  7:01 UTC (permalink / raw)
  To: 15580

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-subword-capitalize-now-fails-gracefully-at-end-of-bu.patch --]
[-- Type: text/x-diff, Size: 1691 bytes --]

From 3329a22e633ce345d727ebceb81d3183bd74372f Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
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)))))
 
 \f
 
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning
  2013-10-10  7:01 bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning Dima Kogan
@ 2013-10-14 19:25 ` Stefan Monnier
  2013-10-15 19:03   ` Dima Kogan
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2013-10-14 19:25 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 15580-done

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning
  2013-10-14 19:25 ` Stefan Monnier
@ 2013-10-15 19:03   ` Dima Kogan
  2013-10-16  3:03     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Dima Kogan @ 2013-10-15 19:03 UTC (permalink / raw)
  To: 15580

[-- Attachment #1: Type: text/plain, Size: 577 bytes --]

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

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

Hi.

Thanks for looking at this. I tried the fix you made in the repo, and it
has two issues:

1. search-failed is raised with (signal) not (throw), so it needs to be
   caught differently

2. You changed (re-search-forward) to (search-forward), however we still
   are searching for a regex, so it must remain re-search-forward.

I'm attaching a patch to fix these two issues

dima


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Correction-to-the-recent-subword-capitalize-fix.patch --]
[-- Type: text/x-diff, Size: 1500 bytes --]

From b3d45ce893aa51f9fd7175a70003dca5571be9d2 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
Date: Tue, 15 Oct 2013 11:54:56 -0700
Subject: [PATCH] Correction to the recent subword-capitalize fix

This applies to emacs bug 15580
---
 lisp/progmodes/subword.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/subword.el b/lisp/progmodes/subword.el
index 1232588..0d754d5 100644
--- a/lisp/progmodes/subword.el
+++ b/lisp/progmodes/subword.el
@@ -257,7 +257,7 @@ Optional argument ARG is the same as for `upcase-word'."
 See the command `subword-mode' for a description of subwords.
 Optional argument ARG is the same as for `capitalize-word'."
   (interactive "p")
-  (catch 'search-failed
+  (condition-case nil
     (let ((count (abs arg))
           (start (point))
           (advance (>= arg 0)))
@@ -265,7 +265,7 @@ Optional argument ARG is the same as for `capitalize-word'."
       (dotimes (i count)
         (if advance
             (progn
-              (search-forward "[[:alpha:]]")
+              (re-search-forward "[[:alpha:]]")
               (goto-char (match-beginning 0)))
           (subword-backward))
         (let* ((p (point))
@@ -275,7 +275,8 @@ Optional argument ARG is the same as for `capitalize-word'."
           (downcase-region pp np)
           (goto-char (if advance np p))))
       (unless advance
-        (goto-char start)))))
+        (goto-char start)))
+    (search-failed nil)))
 
 \f
 
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning
  2013-10-15 19:03   ` Dima Kogan
@ 2013-10-16  3:03     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2013-10-16  3:03 UTC (permalink / raw)
  To: Dima Kogan; +Cc: 15580-done

> Thanks for looking at this. I tried the fix you made in the repo, and it
> has two issues:

Duh!

> I'm attaching a patch to fix these two issues

Thank you very much.  Installed as-is for fear of messing up again,


        Stefan





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-16  3:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-10  7:01 bug#15580: [PATCH] 24.3.50; subword-capitalize at the end of a buffer jumps to the beginning Dima Kogan
2013-10-14 19:25 ` Stefan Monnier
2013-10-15 19:03   ` Dima Kogan
2013-10-16  3:03     ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).