[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/ws-butler 75deadecb9 35/64: Remove dependency on highlight
From: |
Stefan Kangas |
Subject: |
[nongnu] elpa/ws-butler 75deadecb9 35/64: Remove dependency on highlight-changes-mode. |
Date: |
Fri, 31 Dec 2021 11:09:30 -0500 (EST) |
branch: elpa/ws-butler
commit 75deadecb96dda8344bb92ba313bae3a1f06c498
Author: Le Wang <le.wang@agworld.com.au>
Commit: Le Wang <le.wang@agworld.com.au>
Remove dependency on highlight-changes-mode.
---
ws-butler.el | 47 +++++++++++++++++++++++++----------------------
1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/ws-butler.el b/ws-butler.el
index 404cf3ae56..6ff1bbe726 100644
--- a/ws-butler.el
+++ b/ws-butler.el
@@ -54,8 +54,7 @@
;;; Code:
(eval-when-compile
- (require 'cl)
- (require 'hilit-chg))
+ (require 'cl))
(defgroup ws-butler nil
"Unobtrusively whitespace deletion like a butler."
@@ -162,19 +161,17 @@ This is the key to the virtual spaces preserving
indentation mechanism.")
(make-variable-buffer-local 'ws-butler-presave-coord)
(defun ws-butler-map-changes (func &optional start-position end-position)
- "See `hilit-chg-map-changes'.
-
-Call FUNC with each changed region (START-POSITION END-POSITION).
+ "Call FUNC with each changed region (START-POSITION END-POSITION).
This simply uses an end marker since we are modifying the buffer
in place."
-
+ ;; See `hilit-chg-map-changes'.
(let ((start (or start-position (point-min)))
(limit (copy-marker (or end-position (point-max))))
prop end)
(while (and start (< start limit))
- (setq prop (get-text-property start 'hilit-chg))
- (setq end (text-property-not-all start limit 'hilit-chg prop))
+ (setq prop (get-text-property start 'ws-butler-chg))
+ (setq end (text-property-not-all start limit 'ws-butler-chg prop))
(if prop
(funcall func prop start (or end limit)))
(setq start end))
@@ -206,12 +203,24 @@ ensure point doesn't jump due to white space trimming."
(setq last-end end)))
(ws-butler-maybe-trim-eob-lines last-end)))
+(defun ws-butler-clear-properties ()
+ "Clear all ws-butler text properties in buffer."
+ (with-silent-modifications
+ (ws-butler-map-changes (lambda (_prop start end)
+ (remove-list-of-text-properties start end
'(ws-butler-chg))))))
+
+(defun ws-butler-after-change (beg end leng-before &optional)
+ (unless undo-in-progress
+ (with-silent-modifications
+ (when (and (= beg end) (> leng-before 0))
+ ;; deletion
+ (setq end (min (+ end 1) (point-max))))
+ (put-text-property beg end 'ws-butler-chg t))))
+
(defun ws-butler-after-save ()
"Restore trimmed whitespace before point."
- ;; reset text properties
- (highlight-changes-mode 0)
- (highlight-changes-mode 1)
+ (ws-butler-clear-properties)
;; go to saved line+col
(when ws-butler-presave-coord
(let (remaining-lines)
@@ -230,27 +239,21 @@ ensure point doesn't jump due to white space trimming."
;;;###autoload
(define-minor-mode ws-butler-mode
- "White space cleanup mode implemented on top of `highlight-changes-mode'.
-
-With this mode in operation, it's not possible to rotate changes,
-etc.
+ "White space cleanup, without obtrusive white space removal.
-Change visibility can be toggled with
-`highlight-changes-visible-mode', but changes get reset on every
-save."
+Whitespaces at EOL and EOF are trimmed upon file save, and only
+for lines modified by you."
:lighter " wb"
:group 'ws-butler
(if ws-butler-mode
(progn
- (require 'hilit-chg)
- (setq highlight-changes-visibility-initial-state nil)
- (highlight-changes-mode 1)
+ (add-hook 'after-change-functions 'ws-butler-after-change t t)
(add-hook 'before-save-hook 'ws-butler-before-save t t)
(add-hook 'after-save-hook 'ws-butler-after-save t t)
(add-hook 'before-revert-hook 'ws-butler-before-revert t t)
(add-hook 'after-revert-hook 'ws-butler-after-save t t)
(add-hook 'edit-server-done-hook 'ws-butler-before-save t t))
- (highlight-changes-mode 0)
+ (remove-hook 'after-change-functions 'ws-butler-after-change t)
(remove-hook 'before-save-hook 'ws-butler-before-save t)
(remove-hook 'after-save-hook 'ws-butler-after-save t)
(remove-hook 'before-revert-hook 'ws-butler-before-revert t)
- [nongnu] elpa/ws-butler af050ffb6c 09/64: fix typo in commentary #1, (continued)
- [nongnu] elpa/ws-butler af050ffb6c 09/64: fix typo in commentary #1, Stefan Kangas, 2021/12/31
- [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 <=
- [nongnu] elpa/ws-butler ee0fc31020 52/64: Merge branch 'xificurC-master', Stefan Kangas, 2021/12/31
- [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