From: YE via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: yet@ego.team, 56679@debbugs.gnu.org
Subject: bug#56679: 28.1; [PATCH] whitespace-style cannot be configured for diff-mode via hook
Date: Sun, 24 Jul 2022 10:49:33 +0300 [thread overview]
Message-ID: <m2mtczc5ma.fsf@ego.team> (raw)
In-Reply-To: <87r12c8z10.fsf@web.de> (message from Michael Heerdegen on Sat, 23 Jul 2022 02:15:39 +0200)
[-- Attachment #1: Type: text/plain, Size: 650 bytes --]
>> Or maybe adding a defcustom 'diff-whitespace-style' would be a proper
>> solution here?
>
> Since `diff-setup-whitespace' unconditionally sets whitespace-style from
> a hardcoded value, this is the natural fix.
>
>> I started working on such a patch but stuck disliking the probable
>> need in the 'whitespace-style' large ':type' definition duplication.
>
> I think you don't need a duplication. You can reuse an existing type
> definition by looking up the `custom-type` symbol property of an already
> defined option. See e.g. "lisp/eshell/em-cmpl.el" for a few example
> definitions.
Thanks for the advice.
The proposed patch is attached.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Add user option diff-whitespace-style --]
[-- Type: text/x-patch, Size: 2545 bytes --]
From 86a90344673a8ca9645f11ec790c16eda6a4120e Mon Sep 17 00:00:00 2001
From: YugaEgo <yet@ego.team>
Date: Sat, 23 Jul 2022 22:25:10 +0300
Subject: [PATCH] Add new user option 'diff-whitespace-style'
* lisp/vc/diff-mode.el (diff-whitespace-style): New user option.
(diff-setup-whitespace): Use it (Bug#56679).
(top level): require 'whitespace.
(whitespace-style, whitespace-trailing-regexp): Remove defvars.
---
etc/NEWS | 7 +++++++
lisp/vc/diff-mode.el | 11 +++++++----
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 412a93bbf9..dcece83767 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1190,6 +1190,13 @@ the run/continue command.
This is bound to 'H' and toggles whether to hide or show the widget
contents.
+** Diff mode
+
+---
+*** New user option 'diff-whitespace-style'.
+This option determines buffer-local 'whitespace-style' value.
+
+
** Ispell
---
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 30ba4153a9..8d9caf35a3 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -56,6 +56,7 @@
(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")
@@ -147,6 +148,11 @@ diff-font-lock-syntax
(const :tag "Highlight syntax" t)
(const :tag "Allow hunk-based fallback" hunk-also)))
+(defcustom diff-whitespace-style '(face trailing)
+ "Specify `whitespace-style' variable for the current Diff mode buffer."
+ :type (get 'whitespace-style 'custom-type)
+ :version "29.1")
+
(defvar diff-vc-backend nil
"The VC backend that created the current Diff buffer, if any.")
@@ -1476,9 +1482,6 @@ diff--font-lock-cleanup
;; Added when diff--font-lock-prettify is non-nil!
(cl-pushnew 'display font-lock-extra-managed-props)))
-(defvar whitespace-style)
-(defvar whitespace-trailing-regexp)
-
(defvar-local diff-mode-read-only nil
"Non-nil when read-only diff buffer uses short keys.")
@@ -1572,7 +1575,7 @@ diff-setup-whitespace
This sets `whitespace-style' and `whitespace-trailing-regexp' so
that Whitespace mode shows trailing whitespace problems on the
modified lines of the diff."
- (setq-local whitespace-style '(face trailing))
+ (setq-local whitespace-style diff-whitespace-style)
(let ((style (save-excursion
(goto-char (point-min))
;; FIXME: For buffers filled from async processes, this search
--
2.34.1
next prev parent reply other threads:[~2022-07-24 7:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 14:46 bug#56679: 28.1; whitespace-style cannot be configured for diff-mode via hook YE via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-23 0:15 ` Michael Heerdegen
2022-07-24 7:49 ` YE via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-07-24 9:02 ` bug#56679: 28.1; [PATCH] " Lars Ingebrigtsen
2022-07-24 9:08 ` Eli Zaretskii
2022-07-25 2:38 ` Michael Heerdegen
2022-07-25 11:07 ` Eli Zaretskii
2022-07-26 3:59 ` Michael Heerdegen
2022-07-26 12:27 ` YE via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-27 9:52 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2mtczc5ma.fsf@ego.team \
--to=bug-gnu-emacs@gnu.org \
--cc=56679@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=yet@ego.team \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.