]> code.delx.au - gnu-emacs/commitdiff
Fix bug#21766 and add test
authorJuanma Barranquero <lekktu@gmail.com>
Wed, 28 Oct 2015 08:55:25 +0000 (09:55 +0100)
committerJuanma Barranquero <lekktu@gmail.com>
Wed, 28 Oct 2015 17:23:53 +0000 (18:23 +0100)
* 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.

lisp/simple.el
test/automated/simple-test.el

index 338a0600829e8ad7f939c7b3f2ab8d371739e33a..f6c580ffcd6e955a88cc125047a15cba747d9cbd 100644 (file)
@@ -609,7 +609,8 @@ buffer if the variable `delete-trailing-lines' is non-nil."
             (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)))
index 8da575d5d973cd574312791356bacc6e88ce4080..5bfb74615a48f8f905e15c57b13812fc362d9728 100644 (file)
           (should (= x 2)))
       (remove-hook 'post-self-insert-hook inc))))
 
+\f
+;;; `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