From 0ac26976f1da4921fd146851740a73b9185a054b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 22 Jul 2013 12:25:32 -0400 Subject: [PATCH] * lisp/progmodes/subword.el: Fix boundary case. (subword-forward-regexp): Make it a constant. Wrap optional \\W in its own group. (subword-backward-regexp): Make it a constant. (subword-forward-internal): Don't treat a trailing capital as the beginning of a word. * test/automated/subword-tests.el: New file. Fixes: debbugs:13758 --- lisp/ChangeLog | 21 ++++++++++---- lisp/progmodes/subword.el | 12 +++++--- test/ChangeLog | 4 +++ test/automated/subword-tests.el | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 test/automated/subword-tests.el diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 349e6bb742..bf243febe4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2013-07-22 Stefan Monnier + + * progmodes/subword.el: Fix boundary case (bug#13758). + (subword-forward-regexp): Make it a constant. Wrap optional \\W in its + own group. + (subword-backward-regexp): Make it a constant. + (subword-forward-internal): Don't treat a trailing capital as the + beginning of a word. + 2013-07-22 Ari Roponen (tiny change) * emacs-lisp/package.el (package-menu-mode): Don't modify the @@ -10,8 +19,8 @@ (desktop--process-minibuffer-frames): Set desktop-mini parameter only for frames being saved. Rename from desktop--save-minibuffer-frames. (desktop-save-frames): Run hook desktop-before-saving-frames-functions. - Do not save frames with non-nil `desktop-dont-save' parameter. Filter - out deleted frames. + Do not save frames with non-nil `desktop-dont-save' parameter. + Filter out deleted frames. (desktop--find-frame): Use cl-find-if. (desktop--select-frame): Use cl-(first|second|third) to access values of desktop-mini. @@ -352,17 +361,17 @@ * net/tramp.el (tramp-current-connection): New defvar, moved from tramp-sh.el. - (tramp-message-show-progress-reporter-message): Removed, not + (tramp-message-show-progress-reporter-message): Remove, not needed anymore. - (tramp-error-with-buffer): Show message in minibuffer. Discard - input before waiting. Reset connection timestamp. + (tramp-error-with-buffer): Show message in minibuffer. + Discard input before waiting. Reset connection timestamp. (with-tramp-progress-reporter): Improve messages. (tramp-process-actions): Use progress reporter. Delete process in case of error. Improve messages. * net/tramp-sh.el (tramp-barf-if-no-shell-prompt): Use condition-case. Call `tramp-error-with-buffer' with vector and buffer. - (tramp-current-connection): Removed. + (tramp-current-connection): Remove. (tramp-maybe-open-connection): The car of `tramp-current-connection' are the first 3 slots of the vector. diff --git a/lisp/progmodes/subword.el b/lisp/progmodes/subword.el index a75bdff27b..8cf4feb62c 100644 --- a/lisp/progmodes/subword.el +++ b/lisp/progmodes/subword.el @@ -93,11 +93,11 @@ (defvar subword-backward-function 'subword-backward-internal "Function to call for backward subword movement.") -(defvar subword-forward-regexp - "\\W*\\(\\([[:upper:]]*\\W?\\)[[:lower:][:digit:]]*\\)" +(defconst subword-forward-regexp + "\\W*\\(\\([[:upper:]]*\\(\\W\\)?\\)[[:lower:][:digit:]]*\\)" "Regexp used by `subword-forward-internal'.") -(defvar subword-backward-regexp +(defconst subword-backward-regexp "\\(\\(\\W\\|[[:lower:][:digit:]]\\)\\([[:upper:]]+\\W*\\)\\|\\W\\w+\\)" "Regexp used by `subword-backward-internal'.") @@ -319,7 +319,11 @@ edit them as words. (> (match-end 0) (point))) (goto-char (cond - ((< 1 (- (match-end 2) (match-beginning 2))) + ((and (< 1 (- (match-end 2) (match-beginning 2))) + ;; If we have an all-caps word with no following lower-case or + ;; non-word letter, don't leave the last char (bug#13758). + (not (and (null (match-beginning 3)) + (eq (match-end 2) (match-end 1))))) (1- (match-end 2))) (t (match-end 0)))) diff --git a/test/ChangeLog b/test/ChangeLog index d69155a27f..c36948eec3 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +2013-07-22 Stefan Monnier + + * automated/subword-tests.el: New file. + 2013-07-13 Fabián Ezequiel Gallina * automated/python-tests.el (python-imenu-create-index-2) diff --git a/test/automated/subword-tests.el b/test/automated/subword-tests.el new file mode 100644 index 0000000000..62c466439d --- /dev/null +++ b/test/automated/subword-tests.el @@ -0,0 +1,49 @@ +;;; subword-tests.el --- Testing the subword rules + +;; Copyright (C) 2011-2013 Free Software Foundation, Inc. + +;; Author: Stefan Monnier +;; Keywords: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; + +;;; Code: + +(require 'ert) + +(defconst subword-tests-strings + '("ABC^" ;;Bug#13758 + "ABC^ ABC^Foo^ ABC^-Foo^ toto^ ABC^")) + +(ert-deftest subword-tests () + "Test the `subword-mode' rules." + (with-temp-buffer + (dolist (str subword-tests-strings) + (erase-buffer) + (insert str) + (goto-char (point-min)) + (while (search-forward "^" nil t) + (replace-match "")) + (goto-char (point-min)) + (while (not (eobp)) + (subword-forward 1) + (insert "^")) + (should (equal (buffer-string) str))))) + +(provide 'subword-tests) +;;; subword-tests.el ends here -- 2.20.1