Subject: bug#56679: 28.1; [PATCH] whitespace-style cannot be configured for diff-mode via hook

From: YE <[email-masked]>
Date: Tue, 26 Jul 2022 15:27:18 +0300

> YE, could you maybe try to take care of Elis hints?

Sure. See attached.

>From 2c4b52d4b9cb9728e2de8d8e01f27c73fb0a0f8d Mon Sep 17 00:00:00 2001
From: YugaEgo <[email-masked]>
Date: Tue, 26 Jul 2022 15:17:44 +0300
Subject: [PATCH] Improve 'diff-whitespace-style' user option declaration

* lisp/vc/diff-mode.el (diff-whitespace-style):
Use ':require'.  Minor docstring fix.
(top level): Do not require 'whitespace.
(whitespace-style, whitespace-trailing-regexp):
Add defvars (rollback recent removal).
* etc/NEWS: Extend 'diff-whitespace-style' introduction.
(Bug#56679).
---
 etc/NEWS             | 4 +++-
 lisp/vc/diff-mode.el | 7 +++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 1d0e45fdcc..86780165e9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1194,7 +1194,9 @@ contents.
 
 ---
 *** New user option 'diff-whitespace-style'.
-This option determines buffer-local 'whitespace-style' value.
+Sets the value of the buffer-local variable 'whitespace-style' in
+'diff-mode' buffers.  By default, this variable is '(face trailing)',
+which preserves behavior from previous Emacs versions.

 ** Ispell
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 8d9caf35a3..aa426446d7 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -56,7 +56,6 @@
 (eval-when-compile (require 'cl-lib))
 (eval-when-compile (require 'subr-x))
 (require 'easy-mmode)
-(require 'whitespace)
 
 (autoload 'vc-find-revision "vc")
 (autoload 'vc-find-revision-no-save "vc")
@@ -149,7 +148,8 @@ diff-font-lock-syntax
                  (const :tag "Allow hunk-based fallback" hunk-also)))
 
 (defcustom diff-whitespace-style '(face trailing)
-  "Specify `whitespace-style' variable for the current Diff mode buffer."
+  "Specify `whitespace-style' variable for `diff-mode' buffers."
+  :require 'whitespace
   :type (get 'whitespace-style 'custom-type)
   :version "29.1")
 
@@ -1490,6 +1490,9 @@ diff-mode-read-only
     (nconc minor-mode-map-alist
            (list (cons 'diff-mode-read-only diff-mode-shared-map))))
 
+(defvar whitespace-style)
+(defvar whitespace-trailing-regexp)
+
 ;;;###autoload
 (define-derived-mode diff-mode fundamental-mode "Diff"
   "Major mode for viewing/editing context diffs.
-- 
2.34.1