From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: YE via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs 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 Message-ID: References: Reply-To: YE Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5876"; mail-complaints-to="usenet@ciao.gmane.io" Cc: yet@ego.team, 56679@debbugs.gnu.org To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 24 09:51:39 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oFWOn-0001Ka-0Y for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Jul 2022 09:51:37 +0200 Original-Received: from localhost ([::1]:46156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFWOl-0005G2-GF for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 24 Jul 2022 03:51:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55684) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFWNH-0004kj-6S for bug-gnu-emacs@gnu.org; Sun, 24 Jul 2022 03:50:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:57013) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oFWNG-0003Fm-8B for bug-gnu-emacs@gnu.org; Sun, 24 Jul 2022 03:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oFWNG-0005Pr-0a for bug-gnu-emacs@gnu.org; Sun, 24 Jul 2022 03:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: YE Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 24 Jul 2022 07:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56679 X-GNU-PR-Package: emacs Original-Received: via spool by 56679-submit@debbugs.gnu.org id=B56679.165864898620786 (code B ref 56679); Sun, 24 Jul 2022 07:50:01 +0000 Original-Received: (at 56679) by debbugs.gnu.org; 24 Jul 2022 07:49:46 +0000 Original-Received: from localhost ([127.0.0.1]:46762 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oFWMz-0005PB-KV for submit@debbugs.gnu.org; Sun, 24 Jul 2022 03:49:45 -0400 Original-Received: from out0.migadu.com ([94.23.1.103]:53766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oFWMw-0005P1-AD for 56679@debbugs.gnu.org; Sun, 24 Jul 2022 03:49:44 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ego.team; s=key1; t=1658648980; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to; bh=4cYB/gz8XHpwQQleb+SpcJhMm+mWmntdrg7rqWtZvkY=; b=n6H5NTjyBXxn893PiVS8ez/CDmlsBxKdya4zpod2Fq/s1rzDYhApCllJQdIMh4+Yx2hXQ5 jLkEzsKiNjkDyBkiHN1qNOomARbinK5+u5twPzKxTdrom0XcZQ8h9jQtoH5cs+3bfHrL1l J1npJcZJHmsfk4gqTq8XFqCVAMEhUCg= In-Reply-To: <87r12c8z10.fsf@web.de> (message from Michael Heerdegen on Sat, 23 Jul 2022 02:15:39 +0200) X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: ego.team X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" X-ACL-Warn: , YE Xref: news.gmane.io gmane.emacs.bugs:237813 Archived-At: --=-=-= Content-Type: text/plain >> 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-new-user-option-diff-whitespace-style.patch Content-Description: Add user option diff-whitespace-style >From 86a90344673a8ca9645f11ec790c16eda6a4120e Mon Sep 17 00:00:00 2001 From: YugaEgo 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 --=-=-=--