all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: YE via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 56679@debbugs.gnu.org
Subject: bug#56679: 28.1; whitespace-style cannot be configured for diff-mode via hook
Date: Thu, 21 Jul 2022 17:46:17 +0300	[thread overview]
Message-ID: <m2r12e1q2u.fsf@ego.team> (raw)


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






             reply	other threads:[~2022-07-21 14:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21 14:46 YE via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-07-23  0:15 ` bug#56679: 28.1; whitespace-style cannot be configured for diff-mode via hook Michael Heerdegen
2022-07-24  7:49   ` bug#56679: 28.1; [PATCH] " YE via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-07-24  9:02     ` 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=m2r12e1q2u.fsf@ego.team \
    --to=bug-gnu-emacs@gnu.org \
    --cc=56679@debbugs.gnu.org \
    --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.