emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] masater 8b30c33 1/3: Make ‘delete-trailing-whitespace’ de


From: Michal Nazarewicz
Subject: [Emacs-diffs] masater 8b30c33 1/3: Make ‘delete-trailing-whitespace’ delete spaces after form feed
Date: Mon, 4 Jul 2016 12:11:59 +0000 (UTC)

branch: masater
commit 8b30c33e187b4921203306579c798416d80df3d4
Author: Michal Nazarewicz <address@hidden>
Commit: Michal Nazarewicz <address@hidden>

    Make ‘delete-trailing-whitespace’ delete spaces after form feed
    
    * lisp/simple.el (delete-trailing-whitespace): Treat form fead as
    a non-whitespace character (regradless of whether it’s character syntax
    is whitespace) and delete any whitespace following it instead of leaving
    lines with form feeds completely unchanged.  I.e. a line like "\f " will
    now became "\f".
---
 etc/NEWS                  |    6 ++++++
 lisp/simple.el            |   15 +++++++--------
 test/lisp/simple-tests.el |   17 +++++++++++++++--
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 7e11f62..d98bb90 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -187,6 +187,12 @@ questions, with a handy way to display help texts.
 'undo', undo the last replacement; bound to 'u'.
 'undo-all', undo all replacements; bound to 'U'.
 
+** 'delete-trailing-whitespace' deletes whitespace after form feed.
+In modes where form feed was treated as a whitespace character,
+'delete-trailing-whitespace' would keep lines containing it unchanged.
+It now deletes whitespace after the last form feed thus behaving the
+same as in modes where the character is not whitespace.
+
 
 * Changes in Specialized Modes and Packages in Emacs 25.2
 
diff --git a/lisp/simple.el b/lisp/simple.el
index 0da7097..3fa23ff 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -602,15 +602,14 @@ buffer if the variable `delete-trailing-lines' is 
non-nil."
                    (list nil nil))))
   (save-match-data
     (save-excursion
-      (let ((end-marker (copy-marker (or end (point-max))))
-            (start (or start (point-min))))
-        (goto-char start)
-        (while (re-search-forward "\\s-$" end-marker t)
-          (skip-syntax-backward "-" (line-beginning-position))
+      (let ((end-marker (copy-marker (or end (point-max)))))
+        (goto-char (or start (point-min)))
+        (with-syntax-table (make-syntax-table (syntax-table))
           ;; Don't delete formfeeds, even if they are considered whitespace.
-          (if (looking-at-p ".*\f")
-              (goto-char (match-end 0)))
-          (delete-region (point) (match-end 0)))
+          (modify-syntax-entry ?\f "_")
+          (while (re-search-forward "\\s-$" end-marker t)
+            (skip-syntax-backward "-" (line-beginning-position))
+            (delete-region (point) (match-end 0))))
         ;; Delete trailing empty lines.
         (goto-char end-marker)
         (when (and (not end)
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 40cd1d2..2722544 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -204,7 +204,7 @@
 
 
 ;;; `delete-trailing-whitespace'
-(ert-deftest simple-delete-trailing-whitespace ()
+(ert-deftest simple-delete-trailing-whitespace--bug-21766 ()
   "Test bug#21766: delete-whitespace sometimes deletes non-whitespace."
   (defvar python-indent-guess-indent-offset)  ; to avoid a warning
   (let ((python (featurep 'python))
@@ -219,11 +219,24 @@
                           "\n"
                           "\n"))
           (delete-trailing-whitespace)
-          (should (equal (count-lines (point-min) (point-max)) 3)))
+          (should (string-equal (buffer-string)
+                                (concat "query = \"\"\"WITH filtered AS\n"
+                                        "WHERE\n"
+                                        "\"\"\".format(fv_)\n"))))
       ;; Let's clean up if running interactive
       (unless (or noninteractive python)
         (unload-feature 'python)))))
 
+(ert-deftest simple-delete-trailing-whitespace--formfeeds ()
+  "Test formfeeds are not deleted but whitespace past them is."
+  (with-temp-buffer
+    (with-syntax-table (make-syntax-table)
+      (modify-syntax-entry ?\f " ")     ; Make sure \f is whitespace
+      (insert " \f \n \f \f \n\nlast\n")
+      (delete-trailing-whitespace)
+      (should (string-equal (buffer-string) " \f\n \f \f\n\nlast\n"))
+      (should (equal ?\s (char-syntax ?\f))))))
+
 
 ;;; auto-boundary tests
 (ert-deftest undo-auto-boundary-timer ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]