Commit 1f02cbea authored by Juanma Barranquero's avatar Juanma Barranquero

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.
parent 785c0d83
......@@ -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))
(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)))
......@@ -180,5 +180,27 @@
(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))
(insert (concat "query = \"\"\"WITH filtered AS \n"
"WHERE \n"
(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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment