GNU bug report logs -
#56679
28.1; whitespace-style cannot be configured for diff-mode via hook
Previous Next
Reported by: YE <yet <at> ego.team>
Date: Thu, 21 Jul 2022 14:47:01 UTC
Severity: normal
Found in version 28.1
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 56679 in the body.
You can then email your comments to 56679 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Thu, 21 Jul 2022 14:47:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
YE <yet <at> ego.team>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Thu, 21 Jul 2022 14:47:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Steps To Reproduce:
emacs -Q
*diff-mode-hook*
1.
#+begin_src emacs-lisp
(defun my-diff-mode ()
(setq-local whitespace-style '(face trailing spaces))
(message "diff-mode-hook: %S" whitespace-style))
(add-hook 'diff-mode-hook 'my-diff-mode)
#+end_src
2. 'M-x vc-dir <any-repo>'
3. Activate diff view (f.i. 'M-x vc-diff' or 'M-x log-view-diff')
4. See that 'C-h v whitespace-style' outputs '(face trailing)' instead of the
expected value '(face trailing spaces)'.
Additional Information
A bit of investigation showed that 'diff-setup-whitespace' always sets
'whitespace-style' to '(face trailing)'.
The debugged order of setting 'whitespace-style' value:
- diff-setup-whitespace: (face trailing)
- diff-mode-hook: (face trailing spaces)
- diff-setup-whitespace: (face trailing)
So might be the order of the value setting can be fixed?
Or maybe adding a defcustom 'diff-whitespace-style' would be a proper solution
here? I started working on such a patch but stuck disliking the probable need in
the 'whitespace-style' large ':type' definition duplication.
*whitespace-mode-hook*
I also attempted another approach (though didn't investigate it,
so probably it's a separate issue). It's also not functional.
emacs -Q
1.
#+begin_src emacs-lisp
(defun my-whitespace-mode ()
(when (eq major-mode 'diff-mode)
(setq-local whitespace-style '(face trailing spaces))))
(add-hook 'whitespace-mode-hook 'my-whitespace-mode)
#+end_src
2. In diff-mode 'C-h v whitespace-style' outputs expected '(face trailing)'.
3. Enable whitespace-mode 'M-x whitespace-mode'.
4. See that 'C-h v whitespace-style' outputs expected '(face trailing spaces)'.
But this doesn't change the buffer's output.
5. Eval '(whitespace-turn-on)' to see the expected buffer output (or toggle the
mode twice with 'M-x whitespace-mode').
*Current Workaround*
The workaround I currently use adds a keybinding to set 'whitespace-style'
and toggle 'whitespace-mode'.
#+begin_src emacs-lisp
(defun my-diff-whitespace ()
"Toggle whitespace visualization with local `whitespace-style'."
(interactive)
(setq-local whitespace-style '(face trailing spaces))
(whitespace-mode 'toggle))
(define-key diff-mode-map (kbd "C-c b w") 'my-diff-whitespace)
#+end_src
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Sat, 23 Jul 2022 00:16:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 56679 <at> debbugs.gnu.org (full text, mbox):
YE via "Bug reports for GNU Emacs, the Swiss army knife of text editors"
<bug-gnu-emacs <at> gnu.org> writes:
> 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.
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Sat, 23 Jul 2022 00:17:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Sun, 24 Jul 2022 07:50:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 56679 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>> 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.
[0001-Add-new-user-option-diff-whitespace-style.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Sun, 24 Jul 2022 09:03:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 56679 <at> debbugs.gnu.org (full text, mbox):
YE <yet <at> ego.team> writes:
> The proposed patch is attached.
Looks good to me; pushed to Emacs 29.
bug marked as fixed in version 29.1, send any further explanations to
56679 <at> debbugs.gnu.org and YE <yet <at> ego.team>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Sun, 24 Jul 2022 09:03:03 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Sun, 24 Jul 2022 09:09:02 GMT)
Full text and
rfc822 format available.
Message #22 received at 56679 <at> debbugs.gnu.org (full text, mbox):
> Cc: yet <at> ego.team, 56679 <at> debbugs.gnu.org
> Date: Sun, 24 Jul 2022 10:49:33 +0300
> From: YE via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> > 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.
Thanks.
> --- 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)
Can we delay loading whitespace.el until the user actually wants to
turn on whitespace-mode, or until he/she customizes this option?
AFAIU, whitespace-mode is not turned on unconditionally by diff-mode,
so this 'require' is not needed for users who don't turn that minor
mode in Diff buffers.
> +(defcustom diff-whitespace-style '(face trailing)
> + "Specify `whitespace-style' variable for the current Diff mode buffer."
AFAIU, this style will be applied to all Diff mode buffers, not just
the "current" one. Right?
> +** Diff mode
> +
> +---
> +*** New user option 'diff-whitespace-style'.
> +This option determines buffer-local 'whitespace-style' value.
Should we tell that if someone was using whitespace-style directly for
this purpose, they should use this new option instead?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Mon, 25 Jul 2022 02:39:01 GMT)
Full text and
rfc822 format available.
Message #25 received at 56679 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
> Can we delay loading whitespace.el until the user actually wants to
> turn on whitespace-mode, or until he/she customizes this option?
> AFAIU, whitespace-mode is not turned on unconditionally by diff-mode,
> so this 'require' is not needed for users who don't turn that minor
> mode in Diff buffers.
Principally correct - but how do we do this correctly for the
(get 'whitespace-style 'custom-type) :type definition?
> > +(defcustom diff-whitespace-style '(face trailing)
> > + "Specify `whitespace-style' variable for the current Diff mode buffer."
>
> AFAIU, this style will be applied to all Diff mode buffers, not just
> the "current" one. Right?
Yes, that, and also the language of the News entry, is a bit misleading.
> > +** Diff mode
> > +
> > +---
> > +*** New user option 'diff-whitespace-style'.
> > +This option determines buffer-local 'whitespace-style' value.
>
> Should we tell that if someone was using whitespace-style directly for
> this purpose, they should use this new option instead?
AFAIU this never worked, this is what this patch is about (unless those
someones knew some trick maybe).
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Mon, 25 Jul 2022 11:08:01 GMT)
Full text and
rfc822 format available.
Message #28 received at 56679 <at> debbugs.gnu.org (full text, mbox):
> From: Michael Heerdegen <michael_heerdegen <at> web.de>
> Cc: YE <yet <at> ego.team>, 56679 <at> debbugs.gnu.org
> Date: Mon, 25 Jul 2022 04:38:18 +0200
>
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> > Can we delay loading whitespace.el until the user actually wants to
> > turn on whitespace-mode, or until he/she customizes this option?
> > AFAIU, whitespace-mode is not turned on unconditionally by diff-mode,
> > so this 'require' is not needed for users who don't turn that minor
> > mode in Diff buffers.
>
> Principally correct - but how do we do this correctly for the
> (get 'whitespace-style 'custom-type) :type definition?
What are the problems with this that require us to load whitespace.el
up front?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Tue, 26 Jul 2022 04:00:03 GMT)
Full text and
rfc822 format available.
Message #31 received at 56679 <at> debbugs.gnu.org (full text, mbox):
Eli Zaretskii <eliz <at> gnu.org> writes:
> > Principally correct - but how do we do this correctly for the
> > (get 'whitespace-style 'custom-type) :type definition?
>
> What are the problems with this that require us to load whitespace.el
> up front?
Ahhh... that expression is not evaluated before you try to customize the
option, right? Nice.
YE, could you maybe try to take care of Elis hints?
Thanks,
Michael.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Tue, 26 Jul 2022 12:28:01 GMT)
Full text and
rfc822 format available.
Message #34 received at 56679 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> YE, could you maybe try to take care of Elis hints?
Sure. See attached.
[0001-Improve-diff-whitespace-style-user-option-declaratio.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#56679
; Package
emacs
.
(Wed, 27 Jul 2022 09:53:02 GMT)
Full text and
rfc822 format available.
Message #37 received at 56679 <at> debbugs.gnu.org (full text, mbox):
YE <yet <at> ego.team> writes:
>> YE, could you maybe try to take care of Elis hints?
>
> Sure. See attached.
Thanks; pushed to Emacs 29.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 24 Aug 2022 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 2 years and 352 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.