emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/ws-butler 11311538f6 50/64: fix up tests, simplify predica


From: Stefan Kangas
Subject: [nongnu] elpa/ws-butler 11311538f6 50/64: fix up tests, simplify predicate code a bit.
Date: Fri, 31 Dec 2021 11:09:33 -0500 (EST)

branch: elpa/ws-butler
commit 11311538f6e16b25461d4a11d3038d27a50ab9ed
Author: Le Wang <l26wang@gmail.com>
Commit: Le Wang <l26wang@gmail.com>

    fix up tests, simplify predicate code a bit.
---
 tests/ws-butler-tests.el | 21 ++++++++++++---------
 ws-butler.el             |  9 +++++----
 2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/tests/ws-butler-tests.el b/tests/ws-butler-tests.el
index 5784a4aeb7..f49c1d614c 100644
--- a/tests/ws-butler-tests.el
+++ b/tests/ws-butler-tests.el
@@ -14,6 +14,7 @@
        (when (get-buffer test-buffer-name)
          (kill-buffer test-buffer-name))
        (switch-to-buffer (get-buffer-create test-buffer-name))
+       (ws-butler-mode t)
        ,@body)))
 
 (defmacro ws-butler-test-with-common-setup (&rest body)
@@ -33,12 +34,14 @@
 (ert-deftest ws-butler-test-trim-predicate ()
   "Tests `ws-butler-trim-predicate'."
   (ws-butler-test-with-common-setup
-   (let ((ws-butler-trim-predicate (lambda (_beg _end) false)))
-     (insert "a b c. \n")
-     (ws-butler-before-save)
-     (should (string-equal (buffer-string) "a b c. \n")))
-   (let (ws-butler-trim-predicate)
-     (erase-buffer)
-     (insert "a b c. \n")
-     (ws-butler-before-save)
-     (should (string-equal (buffer-string) "a b c.\n")))))
+    (setq-local ws-butler-trim-predicate (lambda (_beg _end) nil))
+    (insert "a b c. \n")
+    (ws-butler-before-save)
+    (should (string-equal (buffer-string) "a b c. \n"))))
+
+(ert-deftest ws-butler-test-trim-predicate-nil ()
+  "Tests `ws-butler-trim-predicate' is nil."
+  (ws-butler-test-with-common-setup
+    (insert "a b c. \n")
+    (ws-butler-before-save)
+    (should (string-equal (buffer-string) "a b c.\n"))))
diff --git a/ws-butler.el b/ws-butler.el
index 4ef08be6fd..5a00f1bb33 100644
--- a/ws-butler.el
+++ b/ws-butler.el
@@ -72,7 +72,7 @@ i.e. only the \"virtual\" space is preserved in the buffer."
   :group 'ws-butler)
 
 (defcustom ws-butler-trim-predicate
-  nil
+  (lambda (_beg _end) t)
   "Return true for regions that should be trimmed.
 
 Expects 2 arguments - beginning and end of a region.
@@ -135,7 +135,8 @@ Also see `require-final-newline'."
        (goto-char (point-max))
        (skip-chars-backward " \t\n\v")
        (let ((printable-point-max (point)))
-         (when (>= last-modified-pos printable-point-max)
+         (when (and (funcall ws-butler-trim-predicate printable-point-max 
(point-max))
+                  (>= last-modified-pos printable-point-max))
            (ws-butler-trim-eob-lines))))))
   ;; clean return code for hooks
   nil)
@@ -193,6 +194,7 @@ in place."
 
 Setting `ws-butler-keep-whitespace-before-point' will also
 ensure point doesn't jump due to white space trimming."
+
   ;; save data to restore later
   (when ws-butler-keep-whitespace-before-point
     (ws-butler-with-save
@@ -210,8 +212,7 @@ ensure point doesn't jump due to white space trimming."
                ;; always expand to end of line anyway, this should be OK.
                end (progn (goto-char (1- end))
                           (point-at-eol))))
-       (unless (and (functionp ws-butler-trim-predicate)
-                    (not (funcall ws-butler-trim-predicate beg end)))
+       (when (funcall ws-butler-trim-predicate beg end)
          (ws-butler-clean-region beg end))
        (setq last-end end)))
     (ws-butler-maybe-trim-eob-lines last-end)))



reply via email to

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