all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dima Kogan <dima@secretsauce.net>
To: 13758@debbugs.gnu.org
Subject: bug#13758: 24.3.50; [PATCH] fixed (subword-forward) edge case at the end of a buffer
Date: Tue, 19 Feb 2013 02:21:49 -0800	[thread overview]
Message-ID: <8738wspps2.fsf@secretsauce.net> (raw)

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

I'm attaching a patch to fix an edge case of (subword-forward). To
reproduce the issue:

1. create a buffer that has an all-caps string such as 'ASDF' at the end
   of the buffer. There must not be a newline at the end; the 'F' should
   be the last character

2. Go to the start of the buffer, and do (subword-forward).

Observe that the point ends up at the 'F', but it should end up one
character ahead of there. To see more clearly that this is wrong, do
(subword-downcase 1) instead of (subword-forward). This should make all
the characters lowercase, but it misses the last one.

This is happening because (subword-forward) is trying to match the
character after the start of the new subword, but at the end of the
buffer, this character doesn't exist.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1893 bytes --]

From c248e56c86d96dac8990880b44b983fd4883b1d9 Mon Sep 17 00:00:00 2001
From: Dima Kogan <dima@secretsauce.net>
Date: Tue, 19 Feb 2013 02:14:26 -0800
Subject: [PATCH] (subword-forward) no longer gets confused by the end of the
 buffer

This fixes an edge case of (subword-forward). If the point is at the
start of an all-caps word at the end of the buffer, (subword-forward)
would end up at the last character of the word, NOT past the word, as
it should. This was happening because (subword-forward) was trying to
match the character after the start of the new subword, but at the end
of the buffer, this character didn't exist
---
 lisp/progmodes/subword.el |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/subword.el b/lisp/progmodes/subword.el
index 80e632c..a86a29b 100644
--- a/lisp/progmodes/subword.el
+++ b/lisp/progmodes/subword.el
@@ -87,7 +87,7 @@
   "Function to call for backward subword movement.")
 
 (defvar subword-forward-regexp
-  "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)"
+  "\\W*\\(\\([[:upper:]]*\\(\\W?\\)\\)[[:lower:][:digit:]]*\\)"
   "Regexp used by `subword-forward-internal'.")
 
 (defvar subword-backward-regexp
@@ -268,7 +268,16 @@ Optional argument ARG is the same as for `capitalize-word'."
       (goto-char
        (cond
 	((< 1 (- (match-end 2) (match-beginning 2)))
-	 (1- (match-end 2)))
+	 ;; if we saw start of subword (capital letters or
+	 ;; whitespace)...
+	 (if (and (= (match-end 2) (point-max))
+		  (= (match-end 2) (match-beginning 3)))
+	     ;; ... and we have all-caps at the end of the buffer, the
+	     ;; next subword starts at end of buffer...
+	     (match-end 2)
+	   ;; ... if we're not at the end, we have the position of the
+	   ;; 2nd character in the subword, so go back one
+	   (1- (match-end 2))))
 	(t
 	 (match-end 0))))
     (forward-word 1)))
-- 
1.7.10.4


             reply	other threads:[~2013-02-19 10:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-19 10:21 Dima Kogan [this message]
2013-07-17 21:02 ` bug#13758: Note Dima Kogan
2013-07-22 16:26 ` bug#13758: 24.3.50; [PATCH] fixed (subword-forward) edge case at the end of a buffer Stefan Monnier

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=8738wspps2.fsf@secretsauce.net \
    --to=dima@secretsauce.net \
    --cc=13758@debbugs.gnu.org \
    /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.