[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/ws-butler ee0fc31020 52/64: Merge branch 'xificurC-master'
From: |
Stefan Kangas |
Subject: |
[nongnu] elpa/ws-butler ee0fc31020 52/64: Merge branch 'xificurC-master' |
Date: |
Fri, 31 Dec 2021 11:09:33 -0500 (EST) |
branch: elpa/ws-butler
commit ee0fc3102011062ffce1d50d8a41f4a0f4110c86
Merge: 123a517a14 93409c1ca7
Author: Le Wang <l26wang@gmail.com>
Commit: Le Wang <l26wang@gmail.com>
Merge branch 'xificurC-master'
---
README.md | 10 ++++++++++
tests/ws-butler-tests.el | 17 +++++++++++++++++
ws-butler.el | 24 ++++++++++++++++++++++--
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 0982d20400..612e6e0c1c 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,16 @@ By default, ws-butler preserves "virtual spaces" in front of
point if necessary.
This can be disabled with `ws-butler-keep-whitespace-before-point`.
+#### Trimming only specific lines.
+
+There might be lines you don't want to get trimmed, e.g. spaces in multiline
strings. The behavior can be customized through `ws-butler-trim-predicate`.
This variable should hold a function that expects 2 arguments (region beginning
and end) and should return true only for regions that one wants to get trimmed.
As an example
+
+ (setq ws-butler-trim-predicate
+ (lambda (beg end)
+ (not (eq 'font-lock-string-face
+ (get-text-property end 'face)))))
+
+
## Installation
### Debian 9 or later or Ubuntu 16.10 or later
diff --git a/tests/ws-butler-tests.el b/tests/ws-butler-tests.el
index 43bcde435f..f49c1d614c 100644
--- a/tests/ws-butler-tests.el
+++ b/tests/ws-butler-tests.el
@@ -5,6 +5,7 @@
;; for "every" function
(require 'cl)
+(load-file "ws-butler.el")
(defmacro ws-butler-test-with-test-buffer (&rest body)
(declare (indent 0) (debug t))
@@ -13,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)
@@ -28,3 +30,18 @@
(execute-kbd-macro (read-kbd-macro "M-DEL"))
(should (every #'identity (list 1 2 3)))
(should (string-equal (buffer-string) "a b "))))
+
+(ert-deftest ws-butler-test-trim-predicate ()
+ "Tests `ws-butler-trim-predicate'."
+ (ws-butler-test-with-common-setup
+ (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 b008c8e15b..fa51b08415 100644
--- a/ws-butler.el
+++ b/ws-butler.el
@@ -56,6 +56,13 @@
(eval-when-compile
(require 'cl))
+(eval-and-compile
+ (unless (fboundp 'setq-local)
+ (defmacro setq-local (var val)
+ "Set variable VAR to value VAL in current buffer."
+ ;; Can't use backquote here, it's too early in the bootstrap.
+ (list 'set (list 'make-local-variable (list 'quote var)) val))))
+
(defgroup ws-butler nil
"Unobtrusively whitespace deletion like a butler."
:group 'convenience)
@@ -79,6 +86,16 @@ This should be a list of trailing whitespace significant
major-modes."
:type '(repeat (symbol :tag "Major mode"))
:group 'ws-butler)
+(defcustom ws-butler-trim-predicate
+ (lambda (_beg _end) t)
+ "Return true for regions that should be trimmed.
+
+Expects 2 arguments - beginning and end of a region.
+Should return a truthy value for regions that should
+have their trailing whitespace trimmed.
+When not defined all regions are trimmed."
+ :type 'function
+ :group 'ws-butler)
(defvar ws-butler-saved)
@@ -133,7 +150,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)
@@ -196,6 +214,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
@@ -213,7 +232,8 @@ 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))))
- (ws-butler-clean-region 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)))
- [nongnu] elpa/ws-butler a5c01e3221 06/64: remove debug message, (continued)
- [nongnu] elpa/ws-butler a5c01e3221 06/64: remove debug message, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 45a93f2bc2 18/64: add Travis-CI tests skeleton, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 0c941aedeb 31/64: Declare type of keep-whitespace-before-point, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 7d30203cf9 19/64: forgot to trim blanks in README (oh the irony!), Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler fe08e8770b 08/64: update lighter, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 8ca373047a 24/64: Fix point moving if after blanks., Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 4154816145 27/64: Clean up end marker., Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 106d313c0d 30/64: Fix package problems; bump version to 0.3., Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 34393f1aaa 07/64: add install instructions, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 75deadecb9 35/64: Remove dependency on highlight-changes-mode., Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler ee0fc31020 52/64: Merge branch 'xificurC-master',
Stefan Kangas <=
- [nongnu] elpa/ws-butler 76265d11f8 44/64: Debian and Ubuntu installation instructions, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 7553d6392a 36/64: Handle adding back text during undo correctly., Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler aa1935f150 37/64: update documentation re: highlight-changes-mode, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 11311538f6 50/64: fix up tests, simplify predicate code a bit., Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler a998a23ee8 41/64: Clarify ws-butler-keep-whitespace-before-point docs., Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 9b40da8428 46/64: add exemptions to ws-butler-global-mode, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler e5fc878904 54/64: disable changing leading whitespace by default, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 52321b99be 59/64: Merge pull request #29 from alevy03/master, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler 323b651dd7 55/64: bump version, Stefan Kangas, 2021/12/31
- [nongnu] elpa/ws-butler a02607ef63 33/64: Some minor grammatical fixes, Stefan Kangas, 2021/12/31