GNU bug report logs -
#21766
25.0.50; delete-trailing-whitespace sometimes deletes non-whitespace
Previous Next
Reported by: Markus Triska <triska <at> metalevel.at>
Date: Mon, 26 Oct 2015 23:10:01 UTC
Severity: normal
Merged with 21769
Found in version 25.0.50
Done: Juanma Barranquero <lekktu <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #56 received at 21766 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On Wed, Oct 28, 2015 at 2:51 AM, Stephen Leake <
stephen_leake <at> stephe-leake.org> wrote:
> I suggest instead to save the file without extra whitespace, and add code
> to the test to insert the extra whitespace.
The file is quite short, so in this case is better to get rid of it and
just insert its contents into the buffer.
Thanks,
Juanma
Fix bug#21766 and add test.
* lisp/simple.el (delete-trailing-whitespace): Save match data when
calling `skip-syntax-backward'.
* test/automated/simple-test.el (simple-delete-trailing-whitespace):
New test.
diff --git a/lisp/simple.el b/lisp/simple.el
index 338a060..f6c580f 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -609,7 +609,8 @@ delete-trailing-whitespace
(start (or start (point-min))))
(goto-char start)
(while (re-search-forward "\\s-$" end-marker t)
- (skip-syntax-backward "-" (line-beginning-position))
+ (save-match-data
+ (skip-syntax-backward "-" (line-beginning-position)))
;; Don't delete formfeeds, even if they are considered
whitespace.
(if (looking-at-p ".*\f")
(goto-char (match-end 0)))
diff --git a/test/automated/simple-test.el b/test/automated/simple-test.el
index 8da575d..5bfb746 100644
--- a/test/automated/simple-test.el
+++ b/test/automated/simple-test.el
@@ -180,5 +180,27 @@ simple-test--dummy-buffer
(should (= x 2)))
(remove-hook 'post-self-insert-hook inc))))
+
+;;; `delete-trailing-whitespace'
+(ert-deftest simple-delete-trailing-whitespace ()
+ "Test bug#21766: delete-whitespace sometimes deletes non-whitespace."
+ (defvar python-indent-guess-indent-offset) ; to avoid a warning
+ (let ((python (featurep 'python))
+ (python-indent-guess-indent-offset nil)
+ (delete-trailing-lines t))
+ (unwind-protect
+ (with-temp-buffer
+ (python-mode)
+ (insert (concat "query = \"\"\"WITH filtered AS \n"
+ "WHERE \n"
+ "\"\"\".format(fv_)\n"
+ "\n"
+ "\n"))
+ (delete-trailing-whitespace)
+ (should (equal (count-lines (point-min) (point-max)) 3)))
+ ;; Let's clean up if running interactive
+ (unless (or noninteractive python)
+ (unload-feature 'python)))))
+
(provide 'simple-test)
;;; simple-test.el ends here
--
2.6.2.windows.1
[Message part 2 (text/html, inline)]
This bug report was last modified 9 years and 210 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.