From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matthias Meulien Newsgroups: gmane.emacs.bugs Subject: bug#51016: 28.0.50; 'diff-font-lock-prettify' breaks display of outline headers Date: Mon, 08 Nov 2021 23:38:43 +0100 Message-ID: <87czna6znw.fsf@gmail.com> References: <87bl44qz5o.fsf@gmail.com> <87wnmgk6r7.fsf@gmail.com> <87tugrmi1j.fsf@gnus.org> <86ee7t8cgl.fsf@mail.linkov.net> <874k8pb0hq.fsf@gnus.org> 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="23138"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 51016@debbugs.gnu.org, Juri Linkov To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 08 23:39:32 2021 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 1mkDIZ-0005nY-2i for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Nov 2021 23:39:31 +0100 Original-Received: from localhost ([::1]:41694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mkDIX-0003x9-LA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 08 Nov 2021 17:39:29 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkDI6-0003wm-UC for bug-gnu-emacs@gnu.org; Mon, 08 Nov 2021 17:39:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48245) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mkDI6-0002rb-MO for bug-gnu-emacs@gnu.org; Mon, 08 Nov 2021 17:39:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mkDI6-0002EL-97 for bug-gnu-emacs@gnu.org; Mon, 08 Nov 2021 17:39:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Matthias Meulien Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 08 Nov 2021 22:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51016 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51016-submit@debbugs.gnu.org id=B51016.16364111358561 (code B ref 51016); Mon, 08 Nov 2021 22:39:02 +0000 Original-Received: (at 51016) by debbugs.gnu.org; 8 Nov 2021 22:38:55 +0000 Original-Received: from localhost ([127.0.0.1]:59791 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkDHz-0002E0-BF for submit@debbugs.gnu.org; Mon, 08 Nov 2021 17:38:55 -0500 Original-Received: from mail-wr1-f49.google.com ([209.85.221.49]:43948) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mkDHu-0002Dm-Up for 51016@debbugs.gnu.org; Mon, 08 Nov 2021 17:38:53 -0500 Original-Received: by mail-wr1-f49.google.com with SMTP id t30so29558238wra.10 for <51016@debbugs.gnu.org>; Mon, 08 Nov 2021 14:38:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=ZJd0qodrcKMOsLTCIJfp5gSXmDGKZhPu1BX/h/3zMlw=; b=lajlpVITNcN5oEdH/iqEp82Y6ZnDj+sOheAjxbm94salttSSaDmOmAVvfB2U15Ni2A t2BQxGN/DTiPqg59fOc0+SaZMNuLbZdJm2MpcFi0KKZoJiYNUKSiVnihhiZ9nqMt54ge SKfH5y4iYyHMYIQOks4OxCEEpOpCbsuvg9CbKurhoZyq0JYbJnpa/4qG7q6w9JUig3Ch jyXL2lHPK4tboGnoOwcGeSSib4ursutiIZSbLUQKiQy1tjPHxNhghwsvp8Wv0ajks/zk 9fxDptiLc5H6eh880Dq5opGMMELXX04pbmruWNAcucGqyVVxEs6dWisLbjH3JSyCCs65 J2pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=ZJd0qodrcKMOsLTCIJfp5gSXmDGKZhPu1BX/h/3zMlw=; b=CSwRYJqgSjvoJNcItZKaXQ95QaDC9560DccRZBCu8FWd8dNNBu9XmYYYifvlCHu5AA v0yCn9+iONOZbjRUjWLhUPqnLtLB9K8nghd+Coi6xCZEcFeL8BnPdk1Jgzw2CVd++ynK NSx0oTJdcNFnxOhaX4Vhk3yq4+t1HSZEyWXjZE88KN+r3wnSEiZOadVnLowUxFaB/gdB 9MdiOGr8YfcSFRxNbKjI5KExgC2XQDFo78EhFB3QO+DuJRYcOPr+Rq9lsXcLraF1zwU3 Q1SVmMwVARjg/XBQhKAeO/qCKcR15UjgSkq2DTRfo0afpsD7v0VVwdty/dzQxp1O7wTj BKnw== X-Gm-Message-State: AOAM533vIsvCqXL7JI7WXzNitvIn5DIwcIDMoHirMq/oqJGDqvHftY80 6Sp3wXiLsmKNmEpfdx14/g8iBnyJQnI= X-Google-Smtp-Source: ABdhPJywu9j6AWV/IQINviV5OzcgL10HkiYpv3FSgyTwxV8uK192ZcWJkiCJ590P98c+DJSaFpPr8w== X-Received: by 2002:a5d:6843:: with SMTP id o3mr3284117wrw.174.1636411125024; Mon, 08 Nov 2021 14:38:45 -0800 (PST) Original-Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb]) by smtp.gmail.com with ESMTPSA id o12sm663896wmq.12.2021.11.08.14.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 14:38:44 -0800 (PST) In-Reply-To: <874k8pb0hq.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 06 Nov 2021 19:30:25 +0100") 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" Xref: news.gmane.io gmane.emacs.bugs:219380 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > Juri Linkov 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Fix-local-variables-overwritten-when-diff-mode-is-se.patch >From 61d0a96df15f3fe4c44ade01747246b05fed2a48 Mon Sep 17 00:00:00 2001 From: Matthias Meulien 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 --=-=-= Content-Type: text/plain -- Matthias --=-=-=--