[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 1172c7303d: whitespace: Redraw if indentation or line length chan
From: |
Lars Ingebrigtsen |
Subject: |
master 1172c7303d: whitespace: Redraw if indentation or line length changes |
Date: |
Mon, 20 Jun 2022 03:41:20 -0400 (EDT) |
branch: master
commit 1172c7303dbce015d12424739a56bfce00e195b1
Author: Richard Hansen <rhansen@rhansen.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
whitespace: Redraw if indentation or line length changes
* lisp/whitespace.el (whitespace-color-on): Convert the indentation
matcher from a static regular expression to a function so that changes
to `indent-tabs-mode' and `tab-width' are picked up the next time
`font-lock-flush' runs.
(whitespace--indentation-matcher): The new function matcher.
(whitespace--variable-watcher): New variable watcher that calls
`font-lock-flush' if `whitespace-mode' is enabled for the buffer.
(whitespace--watched-vars): List of variables to watch.
(whitespace-unload-function): Un-watch the variables. (bug#56103).
---
lisp/whitespace.el | 38 ++++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 10 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 7ee8a46cec..98f21ce9a5 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -2112,16 +2112,7 @@ resultant list will be returned."
,@(when (or (memq 'indentation whitespace-active-style)
(memq 'indentation::tab whitespace-active-style)
(memq 'indentation::space whitespace-active-style))
- `((,(cond
- ((memq 'indentation whitespace-active-style)
- ;; Show indentation SPACEs (indent-tabs-mode).
- (whitespace-indentation-regexp))
- ((memq 'indentation::tab whitespace-active-style)
- ;; Show indentation SPACEs (SPACEs).
- (whitespace-indentation-regexp 'tab))
- ((memq 'indentation::space whitespace-active-style)
- ;; Show indentation SPACEs (TABs).
- (whitespace-indentation-regexp 'space)))
+ `((,#'whitespace--indentation-matcher
1 whitespace-indentation t)))
,@(when (memq 'big-indent whitespace-active-style)
;; Show big indentation.
@@ -2356,6 +2347,26 @@ Also refontify when necessary."
(font-lock-flush ostart (overlay-end whitespace-point--used))
(delete-overlay whitespace-point--used))))))
+(defun whitespace--indentation-matcher (limit)
+ "Indentation matcher for `font-lock-keywords'.
+This matcher is a function instead of a static regular expression
+so that the next call to `font-lock-flush' picks up any changes
+to `indent-tabs-mode' and `tab-width'."
+ (re-search-forward
+ (whitespace-indentation-regexp
+ (cond
+ ((memq 'indentation whitespace-active-style) nil)
+ ((memq 'indentation::tab whitespace-active-style) 'tab)
+ ((memq 'indentation::space whitespace-active-style) 'space)))
+ limit t))
+
+(defun whitespace--variable-watcher (_symbol _newval _op buffer)
+ "Variable watcher that calls `font-lock-flush' for BUFFER."
+ (when buffer
+ (with-current-buffer buffer
+ (when whitespace-mode
+ (font-lock-flush)))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Hacked from visws.el (Miles Bader <miles@gnu.org>)
@@ -2468,9 +2479,16 @@ It should be added buffer-locally to
`write-file-functions'."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(defvar whitespace--watched-vars
+ '(fill-column indent-tabs-mode tab-width whitespace-line-column))
+
+(dolist (var whitespace--watched-vars)
+ (add-variable-watcher var #'whitespace--variable-watcher))
(defun whitespace-unload-function ()
"Unload the whitespace library."
+ (dolist (var whitespace--watched-vars)
+ (remove-variable-watcher var #'whitespace--variable-watcher))
(global-whitespace-mode -1)
;; be sure all local whitespace mode is turned off
(save-current-buffer
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 1172c7303d: whitespace: Redraw if indentation or line length changes,
Lars Ingebrigtsen <=