Subject: Re: bug#36837: 26.2; whitespace-mode: whitespace-line-column is not set to local fill-column

From: Štěpán Němec <[email-masked]>
Date: Sat, 03 Aug 2019 11:23:27 +0200

On Sat, 03 Aug 2019 09:50:56 +0200
[email-masked] wrote:

> Maybe whitespace-mode could watch fill-column for changes, at least
> until the file-local variables are loaded?
> There is also the possibility that fill-column is changed afterwards by
> the user, but I guess that's not too common…

Ah, the new variable watcher thing. I suppose that would be a
possibility, though so far its use in Emacs seems to be quite limited.

Less avant-garde perhaps would be to do what's being done for some of
the other regexps already: turn it into a function:

diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index d0368b54a8..a67e5efee5 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -2066,16 +2066,7 @@ whitespace-color-on
        ,@(when (or (memq 'lines      whitespace-active-style)
                    (memq 'lines-tail whitespace-active-style))
            ;; Show "long" lines.
-           `((,(let ((line-column (or whitespace-line-column fill-column)))
-                 (format
-                  "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$"
-                  tab-width
-                  (1- tab-width)
-                  (/ line-column tab-width)
-                  (let ((rem (% line-column tab-width)))
-                    (if (zerop rem)
-                        ""
-                      (format ".\\{%d\\}" rem)))))
+           `((,#'whitespace-lines-regexp
               ,(if (memq 'lines whitespace-active-style)
                    0                    ; whole line
                  2)                     ; line tail
@@ -2176,6 +2167,19 @@ whitespace-trailing-regexp
 	     (setq status nil)))		  ;; end of buffer
     status))
 
+(defun whitespace-lines-regexp (limit)
+  (re-search-forward
+   (let ((line-column (or whitespace-line-column fill-column)))
+     (format
+      "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$"
+      tab-width
+      (1- tab-width)
+      (/ line-column tab-width)
+      (let ((rem (% line-column tab-width)))
+        (if (zerop rem)
+            ""
+          (format ".\\{%d\\}" rem)))))
+   limit t))
 
 (defun whitespace-empty-at-bob-regexp (limit)
   "Match spaces at beginning of buffer which do not contain the point at \