From c248e56c86d96dac8990880b44b983fd4883b1d9 Mon Sep 17 00:00:00 2001 From: Dima Kogan 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