]> git.eshelyaron.com Git - emacs.git/commitdiff
Recomplexify ‘delete-trailing-whitespace’ by treating \n as whitespace again
authorNoam Postavsky <npostavs@gmail.com>
Tue, 14 Mar 2017 13:23:08 +0000 (09:23 -0400)
committerNoam Postavsky <npostavs@gmail.com>
Wed, 15 Mar 2017 02:14:30 +0000 (22:14 -0400)
Mostly reverts "Simplify ‘delete-trailing-whitespace’ by not treating
\n as whitespace" from 2016-07-04.  Setting \n to non-whitespace
causes the regex engine to backtrack a lot when searching for
"\\s-+$" (Bug#26079).

* lisp/simple.el (delete-trailing-whitespace): Don't change newline
syntax, search for "\\s-$" and then skip backward over trailing
whitespace.

lisp/simple.el

index f110c6f3267e9b0f07644c30da2f9726bd9914d6..369fbf7192316c883a88929a07e44868f9012436 100644 (file)
@@ -633,10 +633,9 @@ buffer if the variable `delete-trailing-lines' is non-nil."
         (with-syntax-table (make-syntax-table (syntax-table))
           ;; Don't delete formfeeds, even if they are considered whitespace.
           (modify-syntax-entry ?\f "_")
-          ;; Treating \n as non-whitespace makes things easier.
-          (modify-syntax-entry ?\n "_")
-          (while (re-search-forward "\\s-+$" end-marker t)
-            (let ((b (match-beginning 0)) (e (match-end 0)))
+          (while (re-search-forward "\\s-$" end-marker t)
+            (skip-syntax-backward "-" (line-beginning-position))
+            (let ((b (point)) (e (match-end 0)))
               (when (region-modifiable-p b e)
                 (delete-region b e)))))
         (if end