From: Matthias Meulien <orontee@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 51016@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
Subject: bug#51016: 28.0.50; 'diff-font-lock-prettify' breaks display of outline headers
Date: Mon, 08 Nov 2021 23:38:43 +0100 [thread overview]
Message-ID: <87czna6znw.fsf@gmail.com> (raw)
In-Reply-To: <874k8pb0hq.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 06 Nov 2021 19:30:25 +0100")
[-- Attachment #1: Type: text/plain, Size: 1269 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Juri Linkov <juri@linkov.net> writes:
>
>> This patch broke vc-diff. For example, after 'C-x v L' type 'd',
>> and check that *vc-diff* buffer doesn't have buffer-local variables
>> diff-vc-backend, diff-vc-revisions anymore, because they were defined
>> in vc-diff-internal after diff-mode, but now the postponed diff-mode
>> kills these buffer-local variables:
>>
>> (set-buffer buffer)
>> - (diff-mode)
>> (setq-local diff-vc-backend (car vc-fileset))
>> (setq-local diff-vc-revisions (list rev1 rev2))
>
> Right. Matthias -- can this be fixed in a different way that doesn't
> postpone changing the major mode?
Thanks Juri!
I moved the call to `diff-mode` since in its implementation one
initialize `diff-buffer-type` by searching:
(save-excursion
(setq-local diff-buffer-type
(if (re-search-forward "^diff --git" nil t)
'git
nil)))
I suggest to restore the original call to `diff-mode` (before the
asynchronous operation completes) and keep the initialization of
`diff-buffer-type` by searching but make it available to
`vc-diff-finish' which is called when the asynchronous operation
completes.
See the attached patch for details.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-local-variables-overwritten-when-diff-mode-is-se.patch --]
[-- Type: text/x-diff, Size: 3612 bytes --]
From 61d0a96df15f3fe4c44ade01747246b05fed2a48 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@gmail.com>
Date: Mon, 8 Nov 2021 23:37:33 +0100
Subject: [PATCH] Fix local variables overwritten when diff-mode is set
* lisp/vc/diff-mode.el (diff-mode):
(diff-setup-buffer-type): Defun to initialize `diff-buffer-type'
* lisp/vc/vc.el (vc-diff-finish): Set `diff-buffer-type' after content
inserted
(vc-diff-internal): Restore `diff-mode' being set before local variables
---
lisp/vc/diff-mode.el | 26 ++++++++++++++++----------
lisp/vc/vc.el | 6 +++---
2 files changed, 19 insertions(+), 13 deletions(-)
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index 746f76b46c..e68aa2257d 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -1540,16 +1540,7 @@ diff-mode
#'diff--filter-substring)
(unless buffer-file-name
(hack-dir-local-variables-non-file-buffer))
- (save-excursion
- (setq-local diff-buffer-type
- (if (re-search-forward "^diff --git" nil t)
- 'git
- nil)))
- (when (eq diff-buffer-type 'git)
- (setq diff-outline-regexp
- (concat "\\(^diff --git.*\n\\|" diff-hunk-header-re "\\)"))
- (setq-local outline-level #'diff--outline-level))
- (setq-local outline-regexp diff-outline-regexp))
+ (diff-setup-buffer-type))
;;;###autoload
(define-minor-mode diff-minor-mode
@@ -1585,6 +1576,21 @@ diff-setup-whitespace
"^[-+!] .*?\\([\t ]+\\)$"
"^[-+!<>].*?\\([\t ]+\\)$"))))
+(defun diff-setup-buffer-type ()
+ "Try to guess the `diff-buffer-type' from content of current Diff mode buffer.
+`outline-regexp' is updated accordingly."
+ (save-excursion
+ (goto-char (point-min))
+ (setq-local diff-buffer-type
+ (if (re-search-forward "^diff --git" nil t)
+ 'git
+ nil)))
+ (when (eq diff-buffer-type 'git)
+ (setq diff-outline-regexp
+ (concat "\\(^diff --git.*\n\\|" diff-hunk-header-re "\\)"))
+ (setq-local outline-level #'diff--outline-level))
+ (setq-local outline-regexp diff-outline-regexp))
+
(defun diff-delete-if-empty ()
;; An empty diff file means there's no more diffs to integrate, so we
;; can just remove the file altogether. Very handy for .rej files if we
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index c9500f454a..87137d8ede 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1739,6 +1739,7 @@ vc-diff-finish
(insert (cdr messages) ".\n")
(message "%s" (cdr messages))))
(diff-setup-whitespace)
+ (diff-setup-buffer-type)
(goto-char (point-min))
(when window
(shrink-window-if-larger-than-buffer window)))
@@ -1804,6 +1805,7 @@ vc-diff-internal
(setq files (nreverse filtered))))
(vc-call-backend (car vc-fileset) 'diff files rev1 rev2 buffer async)
(set-buffer buffer)
+ (diff-mode)
(setq-local diff-vc-backend (car vc-fileset))
(setq-local diff-vc-revisions (list rev1 rev2))
(setq-local revert-buffer-function
@@ -1825,9 +1827,7 @@ vc-diff-internal
;; after `pop-to-buffer'; the former assumes the diff buffer is
;; shown in some window.
(let ((buf (current-buffer)))
- (vc-run-delayed (progn
- (vc-diff-finish buf (when verbose messages))
- (diff-mode))))
+ (vc-run-delayed (vc-diff-finish buf (when verbose messages))))
;; In the async case, we return t even if there are no differences
;; because we don't know that yet.
t)))
--
2.30.2
[-- Attachment #3: Type: text/plain, Size: 14 bytes --]
--
Matthias
next prev parent reply other threads:[~2021-11-08 22:38 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-04 21:05 bug#51016: 28.0.50; 'diff-font-lock-prettify' breaks display of outline headers Matthias Meulien
2021-10-09 0:26 ` bug#51016: Status: " Matthias Meulien
2021-10-09 0:37 ` Matthias Meulien
2021-10-13 20:30 ` bug#51016: " Matthias Meulien
2021-11-05 2:51 ` Lars Ingebrigtsen
2021-11-06 16:40 ` Juri Linkov
2021-11-06 18:30 ` Lars Ingebrigtsen
2021-11-08 22:38 ` Matthias Meulien [this message]
2021-11-09 3:47 ` Lars Ingebrigtsen
2021-11-09 8:19 ` Juri Linkov
2021-11-18 18:06 ` Juri Linkov
2021-11-19 7:22 ` Lars Ingebrigtsen
2021-11-19 8:31 ` Juri Linkov
2021-11-20 8:37 ` Lars Ingebrigtsen
2021-11-20 19:17 ` Juri Linkov
2021-11-21 17:02 ` Lars Ingebrigtsen
2021-11-21 17:26 ` Matthias Meulien
2021-11-21 17:41 ` Juri Linkov
2021-11-21 17:54 ` Matthias Meulien
2021-11-22 22:11 ` Matthias Meulien
2021-11-22 23:03 ` Matthias Meulien
2021-11-24 6:54 ` Lars Ingebrigtsen
2021-11-24 18:48 ` Juri Linkov
2021-12-15 17:08 ` Juri Linkov
2021-12-16 5:50 ` Lars Ingebrigtsen
2021-12-16 17:22 ` Juri Linkov
2021-12-16 17:48 ` Eli Zaretskii
2021-12-16 19:04 ` Juri Linkov
2021-12-16 20:06 ` Eli Zaretskii
2021-12-16 21:02 ` Kévin Le Gouguec
2021-12-17 6:36 ` Eli Zaretskii
2021-12-17 7:07 ` Kévin Le Gouguec
2021-12-17 7:55 ` Eli Zaretskii
2021-12-17 21:27 ` Kévin Le Gouguec
2021-12-18 6:23 ` Eli Zaretskii
2021-12-18 9:18 ` Kévin Le Gouguec
2021-12-18 17:05 ` Juri Linkov
2021-12-18 17:52 ` Eli Zaretskii
2021-12-18 19:43 ` Kévin Le Gouguec
2021-12-18 20:03 ` Eli Zaretskii
2021-12-18 23:30 ` Kévin Le Gouguec
2021-12-19 11:00 ` Lars Ingebrigtsen
2021-12-19 11:27 ` Eli Zaretskii
2021-12-17 4:25 ` Richard Stallman
2021-11-21 17:49 ` Juri Linkov
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87czna6znw.fsf@gmail.com \
--to=orontee@gmail.com \
--cc=51016@debbugs.gnu.org \
--cc=juri@linkov.net \
--cc=larsi@gnus.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).