GNU bug report logs - #51809
29.0.50; [PATCH] Support for outline default state in Diff buffers

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Matthias Meulien <orontee@HIDDEN>; Keywords: patch; dated Sat, 13 Nov 2021 13:10:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 14 Nov 2021 18:38:02 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Nov 14 13:38:02 2021
Received: from localhost ([127.0.0.1]:51684 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mmKO9-0001xp-Rz
	for submit <at> debbugs.gnu.org; Sun, 14 Nov 2021 13:38:02 -0500
Received: from relay4-d.mail.gandi.net ([217.70.183.196]:58121)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mmKO8-0001xR-Oh
 for 51809 <at> debbugs.gnu.org; Sun, 14 Nov 2021 13:38:01 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id E8F77E0008;
 Sun, 14 Nov 2021 18:37:52 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Matthias Meulien <orontee@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN>
Date: Sun, 14 Nov 2021 20:25:18 +0200
In-Reply-To: <87ee7kvshn.fsf@HIDDEN> (Matthias Meulien's message of "Sat,
 13 Nov 2021 19:08:04 +0100")
Message-ID: <865ysuy56x.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>> (...) I'm using outline-minor-mode in diff buffers all the time with
>> (add-hook 'diff-mode-hook 'outline-minor-mode) and would like to
>> understand how your patch improves this.
>>
>> Could the above hook be replaced with customization of
>> diff-outline-default-state?
>
> It was supposed to. But I am also using outline-minor-mode in diff
> buffers all the time with the same hook as you, and I must confess I've
> not tested until you asked: `diff-outline-apply-default-state' is
> supposed to automatically turn on `outline-minor-mode' but I forgot to
> autoload the later resulting in "Symbol’s value as variable is void:
> outline-minor-mode". I'll fix this.

Something strange happened recently with diff-mode and outline-minor-mode.
I can't use this combination anymore.  While reading your patches, I'm trying
to type TAB on the hunk header to hide already viewed hunks of your patch.
But TAB does nothing now.  Do you see the same?  TAB is used to hide/show body
when outline-minor-mode-cycle is t.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 23:29:24 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 18:29:24 2021
Received: from localhost ([127.0.0.1]:48473 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mm2SZ-0000bV-Me
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 18:29:24 -0500
Received: from mail-wr1-f54.google.com ([209.85.221.54]:44721)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mm2SW-0000bH-PH
 for 51809 <at> debbugs.gnu.org; Sat, 13 Nov 2021 18:29:21 -0500
Received: by mail-wr1-f54.google.com with SMTP id n29so22425490wra.11
 for <51809 <at> debbugs.gnu.org>; Sat, 13 Nov 2021 15:29:20 -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=aPw/dq/+E/risRZKWfFRccNB1qFIVEkLoHFTdhBplqU=;
 b=XS4/sNkTJ0EdvpOh9yJhLhtviSeI1EhVXA50C4q1gBKTMt0H+3XEIIvgEc0fIWn3lk
 3bCMZ7qeoi2LADef2+lhlXuEZH2QG97D9J/p5opizLi5VgAaUZiUdBCRCISEjtS0rXa4
 EGHxjHciL13Umk8EuaYiuoTCwGWYhU8Yz77XDFPHnPN+mFbwY7svcB71qQ2DE0OdNR1m
 dWqraEV10m0JVPpo1k+MrqmPSZh3r+zG91WSrxaRRHNs/lF3eTFWXdvgMCrCRYivMllh
 znvMTZcxaw24683utiW3AQqS4hr+Szs2gPScnPJjzXGUKQh4mdnfink+TGi0zg1zi8u8
 CH3w==
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=aPw/dq/+E/risRZKWfFRccNB1qFIVEkLoHFTdhBplqU=;
 b=xgQVHESqzgMIUfLJqw7WOL2p3ApDnnRWWeB2y3lmqIDerah8rRPL3Mt8DGgf4f3ca9
 WMaPUhjfnu2xLGk6kghfVuaNSM68Pa2dLwksjGPyDrl+/YX2AYQujak4+n4Kzdwq+Edj
 So8LJBZUascOUorxO478vXSTDtgR86R62rQRXFw3KHIiesvu4ZxrWD2/rr/9WVAgIzh0
 RBiFGZ1bn7bRxXbx1kCsUefUfo5nXLLTEoBA1leebW8TB5KM0/na43OBgr00y8ltWTWQ
 ApX+G58Sn7UO9vJmvuAuIwMEA0l/TAQdO7zpnMNCfnXpi/pVo6K19sMzEiVwtMxPTPGL
 pWkA==
X-Gm-Message-State: AOAM533ZZBZeOYOfWmXE2BYxuX5/6M3WkA608JUq62OFS6ZHcBUaEKYy
 5ky5LhBpcsOQVkSquyoIgWWn76RjOjk=
X-Google-Smtp-Source: ABdhPJxYx7l27Orhquzh25P7XWQDcNdwxugH/AWoJsA2aXX8iPJNrRwoJEdns+niMwqoXPm60B/BSQ==
X-Received: by 2002:adf:f708:: with SMTP id r8mr32039536wrp.198.1636846154940; 
 Sat, 13 Nov 2021 15:29:14 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id x1sm9604441wmc.22.2021.11.13.15.29.13
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 13 Nov 2021 15:29:14 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN>
Date: Sun, 14 Nov 2021 00:29:13 +0100
In-Reply-To: <86k0hbam7r.fsf@HIDDEN> (Juri Linkov's message of "Sat, 
 13 Nov 2021 21:29:12 +0200")
Message-ID: <878rxrmy7q.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Updated patch that takes Juri comments into account.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Support-for-outline-default-state-in-Diff-buffers.patch

From 4a9f53e73dcbcd77df339bca012ee72aec343f18 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Sat, 13 Nov 2021 12:08:58 +0100
Subject: [PATCH] Support for outline default state in Diff buffers

* lisp/outline.el (outline-map-sublevel-overlay):
* lisp/vc/diff-mode.el (diff-outline-default-state): Variable that
defines an outline state.
(diff-outline-apply-default-state)
(diff--outline-set-file-heading-visibility): Apply outline state
defined in `diff-outline-default-state'.
---
 lisp/outline.el      |  40 ++++++++++++++
 lisp/vc/diff-mode.el | 128 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 166 insertions(+), 2 deletions(-)

diff --git a/lisp/outline.el b/lisp/outline.el
index cefb811703..77de31f785 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1100,6 +1100,46 @@ outline-hide-sublevels
 
 (define-obsolete-function-alias 'hide-sublevels #'outline-hide-sublevels "25.1")
 
+(defun outline-map-sublevel-overlay (level fun)
+  "Hide everything and call FUN on the LEVEL sublevels of headers .
+
+When FUN is called, point is at the beginning of the heading, the
+match data is set appropriately, and FUN receives one argument,
+the outline overlay for the heading entry.
+
+This also unhides the top heading-less body, if any."
+  (if (< level 1)
+      (error "Must keep at least one level of headers"))
+  (save-excursion
+    (let* (outline-view-change-hook
+           (beg (progn
+                  (goto-char (point-min))
+                  ;; Skip the prelude, if any.
+                  (unless (outline-on-heading-p t) (outline-next-heading))
+                  (point)))
+           (end (progn
+                  (goto-char (point-max))
+                  ;; Keep empty last line, if available.
+                  (if (bolp) (1- (point)) (point)))))
+      (if (< end beg)
+	  (setq beg (prog1 end (setq end beg))))
+      ;; First hide everything.
+      (outline-hide-sublevels level)
+      ;; Then unhide the top level headers.
+      (outline-map-region
+       (lambda ()
+	 (when (= (funcall outline-level) level)
+           (goto-char (match-end 0))
+           (let ((overlays (overlays-at (point))))
+             (while overlays
+	       (let ((overlay (car overlays)))
+                 (when (eq (overlay-get overlay 'invisible) 'outline)
+                   (goto-char (match-beginning 0))
+                   (funcall fun overlay))
+                 (setq overlays (cdr overlays)))))))
+       beg end)))
+  (run-hooks 'outline-view-change-hook))
+
 (defun outline-hide-other ()
   "Hide everything except current body and parent and top-level headings.
 This also unhides the top heading-less body, if any."
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index e68aa2257d..9617e6ceee 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -50,6 +50,7 @@
 ;;
 ;; - in diff-apply-hunk, strip context in replace-match to better
 ;;   preserve markers and spacing.
+;;
 ;; - Handle `diff -b' output in context->unified.
 
 ;;; Code:
@@ -62,6 +63,18 @@
 (defvar vc-find-revision-no-save)
 (defvar add-log-buffer-file-name-function)
 
+(eval-when-compile (require 'outline))
+(defvar outline-minor-mode)
+(declare-function outline-minor-mode "outline" (&optional args))
+(declare-function outline-hide-entry "outline")
+(declare-function outline-show-branches "outline")
+(declare-function outline-show-subtree "outline" (&optional event))
+
+(eval-when-compile (require 'so-long))
+(autoload 'so-long-detected-long-line-p "so-long")
+(defvar so-long-skip-leading-comments)
+(defvar so-long-threshold)
+(defvar so-long-max-lines)
 
 (defgroup diff-mode ()
   "Major mode for viewing/editing diffs."
@@ -147,6 +160,61 @@ diff-font-lock-syntax
                  (const :tag "Highlight syntax" t)
                  (const :tag "Allow hunk-based fallback" hunk-also)))
 
+(defcustom diff-outline-default-state nil
+  "If non-nil, some files or hunk are outlined.
+Outlining is performed by Outline minor mode.
+
+If equal to `outline-hunks', only file and hunk headings are
+visibles.
+
+If equal to a lambda function or function name, this function is
+expected to toggle file or hunks visibility, and will be called
+after the mode is enabled.
+
+If equal to a list of symbols, hunk headings will be outlined
+depending on the conditions defined for each symbol:
+
+- If `line-count-threshold', when hunks under a given file
+  heading cover more than `diff-outline-line-count-threshold'
+  lines, they are outlined;
+
+- If `file-heading-regexp', file headings which match the regexp
+  `diff-outline-file-heading-regexp' are outlined;
+
+- If `long-line-threshold', when a hunk under a given file
+  heading have a line with more than
+  `diff-outline-long-line-threshold' characters, all hunks for
+  that file heading are outlined."
+  :version "29.1"
+  :type '(choice (const :tag "Don't outline " nil)
+                 (const :tag "Outline hunks" outline-hunks)
+                 (set :tag "Outline some files"
+                      (const
+                       :tag "Outline files with long hunks"
+                       line-count-threshold)
+                      (const
+                       :tag "Outline files by name"
+                       file-heading-regexp)
+                      (const
+                       :tag "Outline files whose hunks involve long lines"
+                       long-line-threshold))
+                 (function :tag "Custom function")))
+
+(defcustom diff-outline-line-count-threshold 50
+  "Minimal number of lines of hunks for a file to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defcustom diff-outline-file-heading-regexp "ChangeLog\\|package-lock\\.json"
+  "Regexp to match file headings to be outlined."
+  :version "29.1"
+  :type '(regexp :tag "Files to outline"))
+
+(defcustom diff-outline-long-line-threshold 1000
+  "Minimal number of characters in a line for a file to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
 (defvar diff-vc-backend nil
   "The VC backend that created the current Diff buffer, if any.")
 
@@ -1578,7 +1646,8 @@ diff-setup-whitespace
 
 (defun diff-setup-buffer-type ()
   "Try to guess the `diff-buffer-type' from content of current Diff mode buffer.
-`outline-regexp' is updated accordingly."
+`outline-regexp' is updated accordingly and outline default state
+applied."
   (save-excursion
     (goto-char (point-min))
     (setq-local diff-buffer-type
@@ -1589,7 +1658,8 @@ diff-setup-buffer-type
     (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))
+  (setq-local outline-regexp diff-outline-regexp)
+  (diff-outline-apply-default-state))
 
 (defun diff-delete-if-empty ()
   ;; An empty diff file means there's no more diffs to integrate, so we
@@ -2143,6 +2213,60 @@ diff-refresh-hunk
       (delete-file file1)
       (delete-file file2))))
 
+(defun diff-outline-apply-default-state ()
+  "Apply the outline state defined by `diff-outline-default-state'.
+
+When `diff-outline-default-state' is non-nil, Outline minor mode
+is enabled."
+  (interactive)
+  (when diff-outline-default-state
+    (when (not outline-minor-mode)
+      (outline-minor-mode))
+    (cond
+     ((eq diff-outline-default-state 'outline-hunks)
+      (outline-hide-body))
+     ((listp diff-outline-default-state)
+      (outline-map-sublevel-overlay
+       1 #'diff--outline-set-file-heading-visibility))
+     ((when (functionp diff-outline-default-state)
+        (funcall diff-outline-default-state))))))
+
+(defun diff--outline-set-file-heading-visibility (overlay)
+  (cond
+   ;; hide entry when file heading match
+   ;; `diff-outline-file-heading-regexp'
+   ((and
+     (memq 'file-heading-regexp
+           diff-outline-default-state)
+     (string-match-p
+      diff-outline-file-heading-regexp
+      (match-string 0)))
+    (outline-hide-entry))
+   ;; show only branches when line count > threshold
+   ((and
+     (memq 'line-count-threshold
+           diff-outline-default-state)
+     (let ((line-count (count-lines
+                        (overlay-end overlay)
+                        (overlay-start overlay))))
+       (< diff-outline-line-count-threshold line-count)))
+    (outline-show-branches))
+   ;; show only branches when a long line is detected
+   ((and
+     (memq 'long-line-threshold
+           diff-outline-default-state)
+     (save-restriction
+       (narrow-to-region (overlay-start overlay)
+                         (overlay-end overlay))
+       (let ((so-long-skip-leading-comments nil)
+             (so-long-threshold
+              diff-outline-long-line-threshold)
+             (so-long-max-lines nil))
+         (so-long-detected-long-line-p))))
+    (outline-show-branches))
+   ;; otherwise show subtree
+   (t (outline-show-subtree))))
+
 ;;; Fine change highlighting.
 
 (defface diff-refine-changed
-- 
2.30.2


--=-=-=
Content-Type: text/plain


-- 
Matthias

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 21:28:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 16:28:10 2021
Received: from localhost ([127.0.0.1]:48308 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mm0ZF-0003cI-SU
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 16:28:10 -0500
Received: from mail-wm1-f46.google.com ([209.85.128.46]:51815)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mm0ZB-0003bk-7d
 for 51809 <at> debbugs.gnu.org; Sat, 13 Nov 2021 16:28:08 -0500
Received: by mail-wm1-f46.google.com with SMTP id z200so10613684wmc.1
 for <51809 <at> debbugs.gnu.org>; Sat, 13 Nov 2021 13:28:05 -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=9W+xJS/8OF3hfO2V1BrkCUJm3xGkA8amfDS6i68dNJM=;
 b=VJFr6PfjlM55wHTkl1WOBdbcp7/wzUVTbkmUF6tu8W8mTZbze2smVhffNecKNRH7TQ
 OSa293WznWEFQkvqM3orvimCjUyViRNRlu2zCIWWdSIg6Gu6liYmYGr4Z7mnwl0wzMP3
 0q1x95Vt7JBpvenduGrewleI/tvzAXwOtF4Bmcn4xcdzbIMVT6CiLnFHdFjw6VY0si83
 4FyLLMx8lrFP94jEjV1/7wEzreimxdE5XN22azXqHXcfgZcFzEcayrTty2+gGeGvL110
 Qkwc9ICRKKfopQAYYxeZVnbKz3EYbh2ZjZpv7oCQIVjgPzL+ALS0q6tI+iX+7F5e9X1M
 L1Hg==
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=9W+xJS/8OF3hfO2V1BrkCUJm3xGkA8amfDS6i68dNJM=;
 b=kA81XwVQnc+qXJ6mq+pg61Lb72MR2lIEfiAudsXdJy2gS17koWTLNy4O7dRL+yj51f
 0MDa4z2xCBzzjSo7WL1ocotQGN0Vs92yx92sNnDzsce+seVv4nD9uQA2D2RtUf3wccfj
 nVdbqxmcSjOL0fZKlh5oqPvVNfgWvq+GcfJBWFYMkyXV3KfuNQkAxqjSBLkAkEfVIsXR
 nRAsGdVoPd7Wbg6reyPMF3bblNDYIEsSkp/Ur/BJQuoS1BQoGh6WIFlXf2CI9LEom2W/
 CVRAfIjcm5WFLg+8QFKjriXl4L33z4SFO/LcHN3O2GJOf2kc2wUTPH4C6/OGy9u8JEXI
 6q4A==
X-Gm-Message-State: AOAM532lFZl/4RymFM+xTUTvZrg4GnPL8jAlOQMVieGOQunCH0e2nvcs
 GeguZlr6E8KlfWzyptaTW8oUJDEi1XA=
X-Google-Smtp-Source: ABdhPJx9aLYFzuyplQyLpiJTWsr/8flF0q+E5lDNERl3YCNHLkUgzgLoXu001BMUt3UIrP8Dj20JKA==
X-Received: by 2002:a05:600c:3b28:: with SMTP id
 m40mr46642674wms.100.1636838879042; 
 Sat, 13 Nov 2021 13:27:59 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id o63sm10151595wme.2.2021.11.13.13.27.57
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 13 Nov 2021 13:27:58 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN>
Date: Sat, 13 Nov 2021 22:27:52 +0100
In-Reply-To: <86k0hbam7r.fsf@HIDDEN> (Juri Linkov's message of "Sat, 
 13 Nov 2021 21:29:12 +0200")
Message-ID: <87wnlbwxt3.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Juri Linkov <juri@HIDDEN> writes:

Thanks for your comments!

>> +(autoload 'outline-minor-mode "outline")
>
> Actually, outline-minor-mode is already autoloaded, so no special
> handling is needed for it.

Ok, I'll improve this.

> But the problem is that too many outline functions are used in
> diff-mode.el in your patch.  This is a clear indication that
> some part should be moved to outline.el.

You're right. 

> Note that the following function has no diff-specific code, so it could
> be refactored and some generalized function added to outline.el.  Such
> function could be like `outline-map-region' to accept arguments `beg', `end'
> and a predicate function that defines whether to hide or show the
> body.

Ok. I'll make a try.

In the meantime, here is a new version that implements both:

- Outline based on presence of long lines (using `so-long-detected-long-line-p'
predicate)

- Outline based on file names matching a regexp (well, truly file
  heading matching a regexp).


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Support-for-outline-default-state-in-Diff-buffers.patch

From a571efeb5f90e42d1c86e0bef8fe0ebba819914c Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Sat, 13 Nov 2021 12:08:58 +0100
Subject: [PATCH] Support for outline default state in Diff buffers

* lisp/vc/diff-mode.el (diff-outline-default-state): Add custom
variable that defines an outline state and apply that state in Diff
buffers.
---
 lisp/vc/diff-mode.el | 166 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 164 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index e68aa2257d..578e80b4e2 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -50,7 +50,11 @@
 ;;
 ;; - in diff-apply-hunk, strip context in replace-match to better
 ;;   preserve markers and spacing.
+;;
 ;; - Handle `diff -b' output in context->unified.
+;;
+;; - Support outlining files by name (eg to skip automatically
+;;   generated files like package-lock.json in Javascript projects).
 
 ;;; Code:
 (eval-when-compile (require 'cl-lib))
@@ -62,6 +66,15 @@
 (defvar vc-find-revision-no-save)
 (defvar add-log-buffer-file-name-function)
 
+(eval-when-compile (require 'outline))
+(autoload 'outline-minor-mode "outline")
+(defvar outline-minor-mode)
+
+(eval-when-compile (require 'so-long))
+(autoload 'so-long-detected-long-line-p "so-long")
+(defvar so-long-skip-leading-comments)
+(defvar so-long-threshold)
+(defvar so-long-max-lines)
 
 (defgroup diff-mode ()
   "Major mode for viewing/editing diffs."
@@ -147,6 +160,61 @@ diff-font-lock-syntax
                  (const :tag "Highlight syntax" t)
                  (const :tag "Allow hunk-based fallback" hunk-also)))
 
+(defcustom diff-outline-default-state nil
+  "If non-nil, some files or hunk are outlined.
+Outlining is performed by Outline minor mode.
+
+If equal to `outline-hunks', only file and hunk headings are
+visibles.
+
+If equal to a lambda function or function name, this function is
+expected to toggle file or hunks visibility, and will be called
+after the mode is enabled.
+
+If equal to a list of symbols, hunk headings will be outlined
+depending on the conditions defined for each symbol:
+
+- If `line-count-threshold', when hunks under a given file
+  heading cover more than `diff-outline-line-count-threshold'
+  lines, they are outlined;
+
+- If `file-heading-regexp', file headings which match the regexp
+  `diff-outline-file-heading-regexp' are outlined;
+
+- If `long-line-threshold', when a hunk under a given file
+  heading have a line with more than
+  `diff-outline-long-line-threshold' characters, all hunks for
+  that file heading are outlined."
+  :version "29.1"
+  :type '(choice (const :tag "Don't outline " nil)
+                 (const :tag "Outline hunks" outline-hunks)
+                 (set :tag "Outline some files"
+                      (const
+                       :tag "Outline files with long hunks"
+                       line-count-threshold)
+                      (const
+                       :tag "Outline files by name"
+                       file-heading-regexp)
+                      (const
+                       :tag "Outline files whose hunks involve long lines"
+                       long-line-threshold))
+                 (function :tag "Custom function")))
+
+(defcustom diff-outline-line-count-threshold 50
+  "Minimal number of lines of hunks for a file to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defcustom diff-outline-file-heading-regexp "ChangeLog\\|package-lock\\.json"
+  "Regexp to match file headings to be outlined."
+  :version "29.1"
+  :type '(regexp :tag "Files to outline"))
+
+(defcustom diff-outline-long-line-threshold 1000
+  "Minimal number of characters in a line for a file to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
 (defvar diff-vc-backend nil
   "The VC backend that created the current Diff buffer, if any.")
 
@@ -1578,7 +1646,8 @@ diff-setup-whitespace
 
 (defun diff-setup-buffer-type ()
   "Try to guess the `diff-buffer-type' from content of current Diff mode buffer.
-`outline-regexp' is updated accordingly."
+`outline-regexp' is updated accordingly and outline default state
+applied."
   (save-excursion
     (goto-char (point-min))
     (setq-local diff-buffer-type
@@ -1589,7 +1658,8 @@ diff-setup-buffer-type
     (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))
+  (setq-local outline-regexp diff-outline-regexp)
+  (diff-outline-apply-default-state))
 
 (defun diff-delete-if-empty ()
   ;; An empty diff file means there's no more diffs to integrate, so we
@@ -2143,6 +2213,98 @@ diff-refresh-hunk
       (delete-file file1)
       (delete-file file2))))
 
+(defun diff-outline-apply-default-state ()
+  "Apply the outline state defined by `diff-outline-default-state'.
+
+When `diff-outline-default-state' is non-nil, Outline minor mode
+is enabled."
+  (when diff-outline-default-state
+    (when (not outline-minor-mode)
+      (outline-minor-mode))
+    (cond
+     ((eq diff-outline-default-state 'outline-hunks)
+      (outline-hide-body))
+     ((listp diff-outline-default-state)
+      (diff--outline-apply-default-state))
+     ((when (functionp diff-outline-default-state)
+        (funcall diff-outline-default-state))))))
+
+(defun diff--outline-apply-default-state ()
+  "Outline file or hunks according to `diff-outline-default-state'.
+
+See `diff-outline-default-state' for details.
+
+Inspired by `outline-hide-sublevels'."
+  (interactive)
+  (when outline-minor-mode
+    (save-excursion
+      (let* (outline-view-change-hook
+             (beg (progn
+                    (goto-char (point-min))
+                    ;; Skip the prelude, if any.
+                    (unless (outline-on-heading-p t) (outline-next-heading))
+                    (point)))
+             (end (progn
+                    (goto-char (point-max))
+                    ;; Keep empty last line, if available.
+                    (if (bolp) (1- (point)) (point)))))
+	(if (< end beg)
+            (setq beg (prog1 end (setq end beg))))
+	;; First hide sublevels
+	(outline-hide-sublevels 1)
+	;; Then unhide short subtrees
+	(outline-map-region
+	 (lambda ()
+           (when (= (funcall outline-level) 1)
+             (goto-char (match-end 0))
+             (let ((overlays (overlays-at (point))))
+               (while overlays
+		 (let ((overlay (car overlays)))
+		   (progn
+                     (when (eq (overlay-get overlay 'invisible) 'outline)
+                       (goto-char (match-beginning 0))
+                       (cond
+                        ((and
+                          (memq 'file-heading-regexp
+                                diff-outline-default-state)
+                          ;; hide entry when file heading match
+                          ;; `diff-outline-file-heading-regexp'
+                          (message (concat "trying regexp on " (match-string 0)))
+                          (string-match-p
+                           diff-outline-file-heading-regexp
+                           (match-string 0)))
+                         (outline-hide-entry))
+
+                        ((and
+                          (memq 'line-count-threshold
+                                diff-outline-default-state)
+                          ;; show only branches when line count >
+                          ;; threshold
+                          (let ((line-count (count-lines
+                                             (overlay-end overlay)
+                                             (overlay-start overlay))))
+			    (< diff-outline-line-count-threshold line-count)))
+                         (outline-show-branches))
+
+                        ((and
+                          (memq 'long-line-threshold
+                                diff-outline-default-state)
+                          ;; show only branches when a long line is
+                          ;; detected
+                          (save-restriction
+                            (narrow-to-region (overlay-start overlay)
+                                              (overlay-end overlay))
+                            (let ((so-long-skip-leading-comments nil)
+                                  (so-long-threshold
+                                   diff-outline-long-line-threshold)
+                                  (so-long-max-lines nil))
+                              (so-long-detected-long-line-p))))
+                         (outline-show-branches))
+
+                        (t (outline-show-subtree))))
+                     (setq overlays (cdr overlays))))))))
+	 beg end)))))
+
 ;;; Fine change highlighting.
 
 (defface diff-refine-changed
-- 
2.30.2


--=-=-=
Content-Type: text/plain


-- 
Matthias

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 19:30:13 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 14:30:13 2021
Received: from localhost ([127.0.0.1]:48102 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mlyj7-0006dr-Ho
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 14:30:13 -0500
Received: from relay8-d.mail.gandi.net ([217.70.183.201]:56395)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mlyj5-0006cT-Hf
 for 51809 <at> debbugs.gnu.org; Sat, 13 Nov 2021 14:30:12 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 25C7E1BF205;
 Sat, 13 Nov 2021 19:30:03 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Matthias Meulien <orontee@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
Date: Sat, 13 Nov 2021 21:29:12 +0200
In-Reply-To: <87a6i7x5iq.fsf@HIDDEN> (Matthias Meulien's message of "Sat,
 13 Nov 2021 19:41:17 +0100")
Message-ID: <86k0hbam7r.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>>> (...)  Could the above hook be replaced with customization of
>>> diff-outline-default-state?
>
> With the attached patch, Outline minor mode is automatically enabled
> when `diff-outline-default-state' is customized. Tested within "emacs
> -q". That said, I am not a proficient elisper and my use of the
> autoload, declare-function, eval-when-compile machinery may not be
> standard. Sorry for this.

> +(autoload 'outline-minor-mode "outline")

Actually, outline-minor-mode is already autoloaded, so no special
handling is needed for it.

But the problem is that too many outline functions are used in
diff-mode.el in your patch.  This is a clear indication that
some part should be moved to outline.el.

Note that the following function has no diff-specific code, so it could
be refactored and some generalized function added to outline.el.  Such
function could be like `outline-map-region' to accept arguments `beg', `end'
and a predicate function that defines whether to hide or show the body.

> +  (when outline-minor-mode
> +    (save-excursion
> +      (let* (outline-view-change-hook
> +             (beg (progn
> +                    (goto-char (point-min))
> +                    ;; Skip the prelude, if any.
> +                    (unless (outline-on-heading-p t) (outline-next-heading))
> +                    (point)))
> +             (end (progn
> +                    (goto-char (point-max))
> +                    ;; Keep empty last line, if available.
> +                    (if (bolp) (1- (point)) (point)))))
> +	(if (< end beg)
> +            (setq beg (prog1 end (setq end beg))))
> +	;; First hide sublevels
> +	(outline-hide-sublevels 1)
> +	;; Then unhide short subtrees
> +	(outline-map-region
> +	 (lambda ()
> +           (when (= (funcall outline-level) 1)
> +             (goto-char (match-end 0))
> +             (let ((overlays (overlays-at (point))))
> +               (while overlays
> +		 (let ((overlay (car overlays)))
> +		   (progn
> +                     (when (eq (overlay-get overlay 'invisible) 'outline)
> +                       (let ((size (count-lines
> +                                    (overlay-end overlay)
> +                                    (overlay-start overlay))))
> +                         (goto-char (match-beginning 0))
> +			 (if (< size diff-file-outline-threshold)
> +			     (outline-show-subtree)
> +                           (outline-show-branches))))
> +                     (setq overlays (cdr overlays))))))))
> +	 beg end)))))




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 18:41:27 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 13:41:27 2021
Received: from localhost ([127.0.0.1]:48057 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mlxxv-0005L1-65
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 13:41:27 -0500
Received: from mail-wr1-f49.google.com ([209.85.221.49]:44596)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mlxxs-0005Kg-W2
 for 51809 <at> debbugs.gnu.org; Sat, 13 Nov 2021 13:41:25 -0500
Received: by mail-wr1-f49.google.com with SMTP id n29so21661490wra.11
 for <51809 <at> debbugs.gnu.org>; Sat, 13 Nov 2021 10:41:24 -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=LuJoc0dVlPOnY+8INI9suDCuwMg/Uz5aQqdD+m8kFdk=;
 b=fR2vziQCZv4ziwivMDXIFTV4H25nehemRnkryEJ8desLIq7BDx2uw+vAYseqXek9KK
 rrH2gYloifFvzGs23SGsrTIKG/utiNsgpPJI/U5ZMpzXywuJrPh1sS2wTSELnFKWJyFv
 rLKha8N+EeSYHElwPEgH1LMAK5r+lwS70EQ/RcszGgiUpDw8rondCgpy2MF4Dj0lTmE2
 FA+VX0ulsg9P6DnD46Tg2kPPNHiWocV+Yf4hnFmqw26R2aXhAvkNpZL6/AQyRBEHcvxt
 GjHRY5IoKcSkntHFsQMkF7WPQebJPsnr2aUHaNzyLXP/qaKdtq8YKRJ5YpM1rz7RSnUM
 QJAg==
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=LuJoc0dVlPOnY+8INI9suDCuwMg/Uz5aQqdD+m8kFdk=;
 b=V7m905aBNPItJadsCwng3WD0gohp9pq4D0tIQcL4YhpYQAy91Q/EGqB7wGCrAIE3/X
 aH8ZAYLKHWCgA6IDtMk4elynTJLmZnAdx8Lu6nGAqc7ixqCqjMKrrq23UI5fJSgdNPxt
 cUTQidBOh1Fnp06gZmG3swUhRGLR1vMh0qRaXdpF8O3ufzg32336r2anXCi5k70vhP+y
 IEXOVovDcyyz2hmkpAw6EYrPg1pySzA1y/YHVPN6A+IVPMeR1cZwm39ZHy21xfCq47Bv
 yXwEZuGR1g0mjkKFxa6ykjSSAnUqFsxROznxB/MoByfIvjCifee6nkiqIsvjAuwWnFeT
 kdDA==
X-Gm-Message-State: AOAM530AV365J6zzlfuUuhECO26uFExkef4xl+mmzVi7IdbecVrfD9TL
 U2/LxVvonNHM5+0IAZATj7bcdarEu9c=
X-Google-Smtp-Source: ABdhPJzQlwpN0p4m85CiNsWjEeB4Cv7zlRt7KVKuMT976WDkeX+GedoDHPX4C62dZ+ypuk5FUjUX5g==
X-Received: by 2002:a05:6000:4b:: with SMTP id
 k11mr29294527wrx.86.1636828879011; 
 Sat, 13 Nov 2021 10:41:19 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id be3sm4840901wmb.1.2021.11.13.10.41.17
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 13 Nov 2021 10:41:18 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN>
Date: Sat, 13 Nov 2021 19:41:17 +0100
In-Reply-To: <87ee7kvshn.fsf@HIDDEN> (Matthias Meulien's message of "Sat,
 13 Nov 2021 19:08:04 +0100")
Message-ID: <87a6i7x5iq.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Matthias Meulien <orontee@HIDDEN> writes:

>> (...)  Could the above hook be replaced with customization of
>> diff-outline-default-state?

With the attached patch, Outline minor mode is automatically enabled
when `diff-outline-default-state' is customized. Tested within "emacs
-q". That said, I am not a proficient elisper and my use of the
autoload, declare-function, eval-when-compile machinery may not be
standard. Sorry for this.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Support-for-outline-default-state-in-Diff-buffers.patch

From 967df41ffc0bcaf74d4b2c8da4be9a354169498b Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Sat, 13 Nov 2021 12:08:58 +0100
Subject: [PATCH] Support for outline default state in Diff buffers

* lisp/vc/diff-mode.el (diff-outline-default-state): Add custom
variable that defines an outline state and apply that state in Diff
buffers.
---
 lisp/vc/diff-mode.el | 95 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index e68aa2257d..8751a9905c 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -50,7 +50,11 @@
 ;;
 ;; - in diff-apply-hunk, strip context in replace-match to better
 ;;   preserve markers and spacing.
+;;
 ;; - Handle `diff -b' output in context->unified.
+;;
+;; - Support outlining files by name (eg to skip automatically
+;;   generated files like package-lock.json in Javascript projects).
 
 ;;; Code:
 (eval-when-compile (require 'cl-lib))
@@ -62,6 +66,9 @@
 (defvar vc-find-revision-no-save)
 (defvar add-log-buffer-file-name-function)
 
+(eval-when-compile (require 'outline))
+(autoload 'outline-minor-mode "outline")
+(defvar outline-minor-mode)
 
 (defgroup diff-mode ()
   "Major mode for viewing/editing diffs."
@@ -147,6 +154,27 @@ diff-font-lock-syntax
                  (const :tag "Highlight syntax" t)
                  (const :tag "Allow hunk-based fallback" hunk-also)))
 
+(defcustom diff-outline-default-state nil
+  "If non-nil, some files or hunk are outlined.
+Outlining is performed by Outline minor mode.
+
+If `hide-body', only file and hunk headings are visible.
+
+If `size-threshold', files whose hunks cover more than
+`diff-file-outline-threshold' lines are outlined."
+  :version "29.1"
+  :type '(choice (const :tag "Don't outline " nil)
+                 (const :tag "Outline hunks" hide-body)
+                 (const :tag "Outline files with long hunks" size-threshold)
+                 (function :tag "Custom function")))
+
+(defcustom diff-file-outline-threshold 50
+  "Number of lines of hunks for a file to be outlined.
+
+Used by `diff-outline-file-according-to-size'."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
 (defvar diff-vc-backend nil
   "The VC backend that created the current Diff buffer, if any.")
 
@@ -1578,7 +1606,8 @@ diff-setup-whitespace
 
 (defun diff-setup-buffer-type ()
   "Try to guess the `diff-buffer-type' from content of current Diff mode buffer.
-`outline-regexp' is updated accordingly."
+`outline-regexp' is updated accordingly and outline default state
+applied."
   (save-excursion
     (goto-char (point-min))
     (setq-local diff-buffer-type
@@ -1589,7 +1618,8 @@ diff-setup-buffer-type
     (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))
+  (setq-local outline-regexp diff-outline-regexp)
+  (diff-outline-apply-default-state))
 
 (defun diff-delete-if-empty ()
   ;; An empty diff file means there's no more diffs to integrate, so we
@@ -2143,6 +2173,67 @@ diff-refresh-hunk
       (delete-file file1)
       (delete-file file2))))
 
+(defun diff-outline-apply-default-state ()
+  "Apply the outline state defined by `diff-outline-default-state'.
+
+When `diff-outline-default-state' is non-nil, Outline minor mode
+is enabled."
+  (when diff-outline-default-state
+    (when (not outline-minor-mode)
+      (outline-minor-mode))
+    (cond
+     ((eq diff-outline-default-state 'size-threshold)
+      (diff-outline-file-according-to-size))
+     ((eq diff-outline-default-state 'hide-body)
+      (outline-hide-body))
+     ((when (functionp diff-outline-default-state)
+        (funcall diff-outline-default-state))))))
+
+(defun diff-outline-file-according-to-size ()
+  "Outline file with long hunks.
+
+A file is outlined when its hunks cover more than
+`diff-file-outline-threshold' lines. Does nothing when Outline
+minor mode is not enabled.
+
+Inspired by `outline-hide-sublevels'."
+  (interactive)
+  (when outline-minor-mode
+    (save-excursion
+      (let* (outline-view-change-hook
+             (beg (progn
+                    (goto-char (point-min))
+                    ;; Skip the prelude, if any.
+                    (unless (outline-on-heading-p t) (outline-next-heading))
+                    (point)))
+             (end (progn
+                    (goto-char (point-max))
+                    ;; Keep empty last line, if available.
+                    (if (bolp) (1- (point)) (point)))))
+	(if (< end beg)
+            (setq beg (prog1 end (setq end beg))))
+	;; First hide sublevels
+	(outline-hide-sublevels 1)
+	;; Then unhide short subtrees
+	(outline-map-region
+	 (lambda ()
+           (when (= (funcall outline-level) 1)
+             (goto-char (match-end 0))
+             (let ((overlays (overlays-at (point))))
+               (while overlays
+		 (let ((overlay (car overlays)))
+		   (progn
+                     (when (eq (overlay-get overlay 'invisible) 'outline)
+                       (let ((size (count-lines
+                                    (overlay-end overlay)
+                                    (overlay-start overlay))))
+                         (goto-char (match-beginning 0))
+			 (if (< size diff-file-outline-threshold)
+			     (outline-show-subtree)
+                           (outline-show-branches))))
+                     (setq overlays (cdr overlays))))))))
+	 beg end)))))
+
 ;;; Fine change highlighting.
 
 (defface diff-refine-changed
-- 
2.30.2


--=-=-=
Content-Type: text/plain


-- 
Matthias

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 18:29:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 13:29:16 2021
Received: from localhost ([127.0.0.1]:48040 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mlxm8-00050B-7X
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 13:29:16 -0500
Received: from relay10.mail.gandi.net ([217.70.178.230]:50819)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mlxm4-0004zv-Hv
 for 51809 <at> debbugs.gnu.org; Sat, 13 Nov 2021 13:29:15 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay10.mail.gandi.net (Postfix) with ESMTPSA id 514BA240005;
 Sat, 13 Nov 2021 18:29:04 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Matthias Meulien <orontee@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN>
Date: Sat, 13 Nov 2021 20:27:36 +0200
In-Reply-To: <87ee7kvshn.fsf@HIDDEN> (Matthias Meulien's message of "Sat,
 13 Nov 2021 19:08:04 +0100")
Message-ID: <86pmr3c3mv.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

>>> +;; - Support outlining files by name (eg to skip automatically
>>> +;;   generated files like package-lock.json in Javascript projects).
>>>…
>>> +(defcustom diff-file-outline-threshold 50
>>> +  "Number of lines of hunks for a file to be outlined.
>>
>> Often the files that need to be hidden contain just one very long line
>> without newlines such as in compiled assets, etc. and eventually make
>> Emacs unresponsive.  This is a big problem.  Would it be possible
>> in your patch to check the size of the hunk counting characters
>> instead of lines?
>
> Good point. I guess counting characters can be achieved by:
>   (- (overlay-end overlay) (overlay-start overlay))
> thus it looks feasible.

It seems this should work.

> Wouldn't it better to add a new choice "Outline hunks with long lines"
> and allow multiple choices in `diff-outline-default-state'
> customization?

Many customizable variables that check the size such as
large-file-warning-threshold etc. count bytes/characters.
But if you think that someone might want to restrict
only the number of lines whereas wanting to see long lines,
then a new option could be added too.

> It would allow to implement one more usefull choice (from my pov),
> "Outline files by name" to hide automatically generated files (like
> package-lock.json in Javascript projects using NPM)...
>
> Does it looks reasonnable to you?

An option to hide by file names (I assume a regexp?) looks useful too.

This is how I configured the xref output buffer to
initially hide only ChangeLog and test files:

#+begin_src emacs-lisp
(add-hook 'xref-after-update-hook
          (lambda ()
            (setq-local outline-regexp (if (eq xref-file-name-display 'abs)
                                           "/" "[^ 0-9]"))
            (outline-minor-mode +1)
            (save-excursion
              (goto-char (point-min))
              (while (and (re-search-forward "ChangeLog\\|test/manual/etags" nil t)
                          (get-text-property (point) 'xref-group))
                (outline-cycle)))))
#+end_src

Something like this could be customizable in diff-mode.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 18:08:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 13:08:16 2021
Received: from localhost ([127.0.0.1]:48031 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mlxRo-0004St-6Q
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 13:08:16 -0500
Received: from mail-wr1-f44.google.com ([209.85.221.44]:38522)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mlxRj-0004Sc-LD
 for 51809 <at> debbugs.gnu.org; Sat, 13 Nov 2021 13:08:15 -0500
Received: by mail-wr1-f44.google.com with SMTP id u18so21607384wrg.5
 for <51809 <at> debbugs.gnu.org>; Sat, 13 Nov 2021 10:08:11 -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:content-transfer-encoding;
 bh=u4BRVqzXq8dffPEEKuf5Q2EU7Q8lqJqql0UIoXVAxNQ=;
 b=que00FrfKsg0eaYVjliDcZbQ9dbS7iqt/nx1JDUuv6Uj7mLImV/jCkHsdb/YYY2uVs
 hj+ifG+iZ2iWEY5UTWpduBXoGKQbA/7ej0C3gk8+QornvR/TGcmOKiH3fhyH9AU+tuiD
 dq6mGIEb5r9bt29RmNKRF+8qrs0GQ1IxzW7cX1mXWHHMxHeV1EWM5HF9Gs87DSfVXWXB
 QegBcuMLDYDw6cTT/7v2hhh0vxTzATapMMdFXb0I2cO5WIqY1WMBI6RFHFR+a1ap+NV0
 YN6QwQVtXsFAM4XVUSIqqHkFuPOs0f4ytvHWmh9WYqZjEm4MyNhXGuvb7pyfveD6vfIS
 PVug==
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:content-transfer-encoding;
 bh=u4BRVqzXq8dffPEEKuf5Q2EU7Q8lqJqql0UIoXVAxNQ=;
 b=m2/NlxjCZG0iT9FWKXoQVJM3tCUSWUqgns7EfrQiLbeTuyp/ub8yxoanDIiZV2hqJX
 4hGfB+T7yjRoAlqhZ4/M19rdoiBX50fI2A0MqvSehwjv9r/1NRmc1tgNMbeBPBdQia6m
 JkbekOi/fa7dFRx8Z+R0Ny9j+i/r/epidTU4RSR7lGulcP3ZUmCuR0IrdlY+Mr49nvVL
 gT8cZDaLKbje4lBlhc/d9KbwMqmcZ8XF8fbk83vD1gF/ToRgBwGblnTP5qHBN+Evdic4
 Kb3bBKAqwUbUl050nhgwutJYYEPUs91xb4L2c2wOQB27Wj/pK4UKa8wEpDKBWfdNyuF0
 hIcg==
X-Gm-Message-State: AOAM531/+Osngne1YqOHFS+8uIsRb8KNC+EzVQmLMp7tgAsPGrILdGAA
 SbtxmEvlQJQxgT6TAEFAR2Ps3KxfZLI=
X-Google-Smtp-Source: ABdhPJzeT5Rcdm6ZlTOpEbp1ny2kE2ZELxl3XQKFVGHJlbWxdR8rus0Gk3qPLHQMEh7NQOe7NTDdIg==
X-Received: by 2002:adf:f08d:: with SMTP id n13mr31170041wro.395.1636826885822; 
 Sat, 13 Nov 2021 10:08:05 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id f7sm16795386wmg.6.2021.11.13.10.08.05
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 13 Nov 2021 10:08:05 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
To: Juri Linkov <juri@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
Date: Sat, 13 Nov 2021 19:08:04 +0100
In-Reply-To: <86h7cgdk4v.fsf@HIDDEN> (Juri Linkov's message of "Sat, 
 13 Nov 2021 19:45:52 +0200")
Message-ID: <87ee7kvshn.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Juri Linkov <juri@HIDDEN> writes:

> (...) I'm using outline-minor-mode in diff buffers all the time with
> (add-hook 'diff-mode-hook 'outline-minor-mode) and would like to
> understand how your patch improves this.
>
> Could the above hook be replaced with customization of
> diff-outline-default-state?

It was supposed to. But I am also using outline-minor-mode in diff
buffers all the time with the same hook as you, and I must confess I've
not tested until you asked: `diff-outline-apply-default-state' is
supposed to automatically turn on `outline-minor-mode' but I forgot to
autoload the later resulting in "Symbol=E2=80=99s value as variable is void:
outline-minor-mode". I'll fix this.

>
>> +;; - Support outlining files by name (eg to skip automatically
>> +;;   generated files like package-lock.json in Javascript projects).
>>=E2=80=A6
>> +(defcustom diff-file-outline-threshold 50
>> +  "Number of lines of hunks for a file to be outlined.
>
> Often the files that need to be hidden contain just one very long line
> without newlines such as in compiled assets, etc. and eventually make
> Emacs unresponsive.  This is a big problem.  Would it be possible
> in your patch to check the size of the hunk counting characters
> instead of lines?

Good point. I guess counting characters can be achieved by:
  (- (overlay-end overlay) (overlay-start overlay))
thus it looks feasible.

Wouldn't it better to add a new choice "Outline hunks with long lines"
and allow multiple choices in `diff-outline-default-state'
customization?

It would allow to implement one more usefull choice (from my pov),
"Outline files by name" to hide automatically generated files (like
package-lock.json in Javascript projects using NPM)...

Does it looks reasonnable to you?
--=20
Matthias




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at 51809 <at> debbugs.gnu.org:


Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 17:48:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 12:48:55 2021
Received: from localhost ([127.0.0.1]:48013 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mlx94-0003wV-SD
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 12:48:55 -0500
Received: from relay7-d.mail.gandi.net ([217.70.183.200]:59037)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mlx91-0003vy-UP
 for 51809 <at> debbugs.gnu.org; Sat, 13 Nov 2021 12:48:52 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id D650520002;
 Sat, 13 Nov 2021 17:48:44 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
To: Matthias Meulien <orontee@HIDDEN>
Subject: Re: bug#51809: 29.0.50; [PATCH] Support for outline default state
 in Diff buffers
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN>
Date: Sat, 13 Nov 2021 19:45:52 +0200
In-Reply-To: <87lf1sw6ji.fsf@HIDDEN> (Matthias Meulien's message of "Sat,
 13 Nov 2021 14:04:33 +0100")
Message-ID: <86h7cgdk4v.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 51809
Cc: 51809 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

> Attached is a patch that adds support for an outline default state in
> Diff buffers.

Thanks.

> One state makes only files and hunks headings visibles. Another one
> outlines files with long hunks. A third value is proposed for users who
> want to implement their own state.
>
> My point is that, when I first review a changeset, I am trying to get an
> overview of the changes; And files cumulating long hunks often don't
> help for that matter.
>
> Tell me if it's worth including in Emacs 29.

I'm using outline-minor-mode in diff buffers all the time
with (add-hook 'diff-mode-hook 'outline-minor-mode)
and would like to understand how your patch improves this.

Could the above hook be replaced with customization of
diff-outline-default-state?

> +;; - Support outlining files by name (eg to skip automatically
> +;;   generated files like package-lock.json in Javascript projects).
>…
> +(defcustom diff-file-outline-threshold 50
> +  "Number of lines of hunks for a file to be outlined.

Often the files that need to be hidden contain just one very long line
without newlines such as in compiled assets, etc. and eventually make
Emacs unresponsive.  This is a big problem.  Would it be possible
in your patch to check the size of the hunk counting characters
instead of lines?




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 13 Nov 2021 13:09:53 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 13 08:09:53 2021
Received: from localhost ([127.0.0.1]:46721 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mlsn2-0000GP-VX
	for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 08:09:53 -0500
Received: from lists.gnu.org ([209.51.188.17]:45382)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mlsn0-0000GA-1j
 for submit <at> debbugs.gnu.org; Sat, 13 Nov 2021 08:09:51 -0500
Received: from eggs.gnu.org ([209.51.188.92]:56228)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <orontee@HIDDEN>) id 1mlsmz-0005ZQ-S5
 for bug-gnu-emacs@HIDDEN; Sat, 13 Nov 2021 08:09:49 -0500
Received: from [2a00:1450:4864:20::429] (port=36555
 helo=mail-wr1-x429.google.com)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <orontee@HIDDEN>) id 1mlsmx-0000st-8Q
 for bug-gnu-emacs@HIDDEN; Sat, 13 Nov 2021 08:09:49 -0500
Received: by mail-wr1-x429.google.com with SMTP id s13so20612436wrb.3
 for <bug-gnu-emacs@HIDDEN>; Sat, 13 Nov 2021 05:09:45 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:subject:date:message-id:user-agent:mime-version;
 bh=cYEdD8Q+aj0T2hbsnVS2lma0itEpXc8a2QEPEGsX57I=;
 b=W7Uqu83NU9N+sEG79yV4Qu3g81n2t5hV7d6Bkhw/UNggcZtEiLnA+ue2PeFM+Rr+8V
 q/ywXpwOL9uxuaeXHkAMm56Dx68QEhdjJxhKlKnkgA/Bub6AFFY9l9dwYVQTsBsodvWH
 F3isFB704/C/DfWqrlQNgxU0SnYeUJxhZnpvDBn6ErEi0+Hur5yj0eQ3AjJ9STI9Fri6
 wQdegtrQqoCMZJJiNBZVxE53qFlpt7rnmuTjpg8l74IQhEEtRttvB8ZV+dNXn2rpAan3
 8ShwAUBT4SziSGBLHCGELXXFdNBEDWiYB/tNM6//314BWxgqdierwPr3DPplv+3NL+GU
 sZ+Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=x-gm-message-state:from:to:subject:date:message-id:user-agent
 :mime-version;
 bh=cYEdD8Q+aj0T2hbsnVS2lma0itEpXc8a2QEPEGsX57I=;
 b=JyCNxWSMjwy9UJ1HeMeXsunv6dgwx5enHyYP1Rtn8gxPwQyX6zSjij0vhZe7d7u2gD
 lLitGWfwdLLNDjs1HvCgTaP/lhzCbKZZ8u3TEcnI8YyC6xuknNw6TwEBIzGSqdZPgEzC
 LrPeH/raV8UrVyV6EpuPE3gpYlP1aXVBlmD8u+GAi2HqxH3Z8B7xAxlsxAMfj1kyr4V7
 /kdvf7hzKx4yHlwEAdS3V8JknacRRLUB6O3v/KQrneX7bOtc2PdRVNGKXQ44rSejF+Wt
 yBTPh4nfTwChhoEl1Mn2Z1UMAzdf9JdFbx2Ri07AE0PDbMqwqtbB2dUYhOA9qjZfFNsH
 f1GQ==
X-Gm-Message-State: AOAM532fEvyVzXc3LSwRVMaUX1mpCQ9nptIoz/DZUQRO5BCtLa4g6IHV
 UaUbflC56JTEwwFzKlgpjr/Mipmqh5I=
X-Google-Smtp-Source: ABdhPJwntkdnAjvkUJQVz/E5ZaWk+bktUEBV+zqTlfErdu2bvkwc45P+ol/wEYlZ3XMTv3sSoYdlfA==
X-Received: by 2002:adf:f44e:: with SMTP id f14mr28122329wrp.37.1636808675428; 
 Sat, 13 Nov 2021 05:04:35 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id v15sm4717691wro.35.2021.11.13.05.04.34
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 13 Nov 2021 05:04:34 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Date: Sat, 13 Nov 2021 14:04:33 +0100
Message-ID: <87lf1sw6ji.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::429
 (failed)
Received-SPF: pass client-ip=2a00:1450:4864:20::429;
 envelope-from=orontee@HIDDEN; helo=mail-wr1-x429.google.com
X-Spam_score_int: -12
X-Spam_score: -1.3
X-Spam_bar: -
X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.9 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

--=-=-=
Content-Type: text/plain


Hi,

Attached is a patch that adds support for an outline default state in
Diff buffers.

One state makes only files and hunks headings visibles. Another one
outlines files with long hunks. A third value is proposed for users who
want to implement their own state.

My point is that, when I first review a changeset, I am trying to get an
overview of the changes; And files cumulating long hunks often don't
help for that matter.

Tell me if it's worth including in Emacs 29.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Support-for-outline-default-state-in-Diff-buffers.patch

From f698c22bffd8cd5dd5c98a86f0e143c4e184b4dc Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Sat, 13 Nov 2021 12:08:58 +0100
Subject: [PATCH] Support for outline default state in Diff buffers

* lisp/vc/diff-mode.el (diff-outline-default-state): Add custom
variable that defines an outline state and apply that state in Diff
buffers.
---
 lisp/vc/diff-mode.el | 92 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 90 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index e68aa2257d..01ea1c3994 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -50,7 +50,11 @@
 ;;
 ;; - in diff-apply-hunk, strip context in replace-match to better
 ;;   preserve markers and spacing.
+;;
 ;; - Handle `diff -b' output in context->unified.
+;;
+;; - Support outlining files by name (eg to skip automatically
+;;   generated files like package-lock.json in Javascript projects).
 
 ;;; Code:
 (eval-when-compile (require 'cl-lib))
@@ -147,6 +151,27 @@ diff-font-lock-syntax
                  (const :tag "Highlight syntax" t)
                  (const :tag "Allow hunk-based fallback" hunk-also)))
 
+(defcustom diff-outline-default-state nil
+  "If non-nil, some files or hunk are outlined.
+Outlining is performed by Outline minor mode.
+
+If `hide-body', only file and hunk headings are visible.
+
+If `size-threshold', files whose hunks cover more than
+`diff-file-outline-threshold' lines are outlined."
+  :version "29.1"
+  :type '(choice (const :tag "Don't outline " nil)
+                 (const :tag "Outline hunks" hide-body)
+                 (const :tag "Outline files with long hunks" size-threshold)
+                 (function :tag "Custom function")))
+
+(defcustom diff-file-outline-threshold 50
+  "Number of lines of hunks for a file to be outlined.
+
+Used by `diff-outline-file-according-to-size'."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
 (defvar diff-vc-backend nil
   "The VC backend that created the current Diff buffer, if any.")
 
@@ -1578,7 +1603,8 @@ diff-setup-whitespace
 
 (defun diff-setup-buffer-type ()
   "Try to guess the `diff-buffer-type' from content of current Diff mode buffer.
-`outline-regexp' is updated accordingly."
+`outline-regexp' is updated accordingly and outline default state
+applied."
   (save-excursion
     (goto-char (point-min))
     (setq-local diff-buffer-type
@@ -1589,7 +1615,8 @@ diff-setup-buffer-type
     (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))
+  (setq-local outline-regexp diff-outline-regexp)
+  (diff-outline-apply-default-state))
 
 (defun diff-delete-if-empty ()
   ;; An empty diff file means there's no more diffs to integrate, so we
@@ -2143,6 +2170,67 @@ diff-refresh-hunk
       (delete-file file1)
       (delete-file file2))))
 
+(defun diff-outline-apply-default-state ()
+  "Apply the outline state defined by `diff-outline-default-state'.
+
+When `diff-outline-default-state' is non-nil, Outline minor mode
+is enabled."
+  (when diff-outline-default-state
+    (when (not outline-minor-mode)
+      (outline-minor-mode))
+    (cond
+     ((eq diff-outline-default-state 'size-threshold)
+      (diff-outline-file-according-to-size))
+     ((eq diff-outline-default-state 'hide-body)
+      (outline-hide-body))
+     ((when (functionp diff-outline-default-state)
+        (funcall diff-outline-default-state))))))
+
+(defun diff-outline-file-according-to-size ()
+  "Outline file with long hunks.
+
+A file is outlined when its hunks cover more than
+`diff-file-outline-threshold' lines. Does nothing when Outline
+minor mode is not enabled or `diff-file-outline-threshold'.
+
+Inspired by `outline-hide-sublevels'."
+  (interactive)
+  (when (and outline-minor-mode diff-file-outline-threshold)
+    (save-excursion
+      (let* (outline-view-change-hook
+             (beg (progn
+                    (goto-char (point-min))
+                    ;; Skip the prelude, if any.
+                    (unless (outline-on-heading-p t) (outline-next-heading))
+                    (point)))
+             (end (progn
+                    (goto-char (point-max))
+                    ;; Keep empty last line, if available.
+                    (if (bolp) (1- (point)) (point)))))
+	(if (< end beg)
+            (setq beg (prog1 end (setq end beg))))
+	;; First hide sublevels
+	(outline-hide-sublevels 1)
+	;; Then unhide short subtrees
+	(outline-map-region
+	 (lambda ()
+           (when (= (funcall outline-level) 1)
+             (goto-char (match-end 0))
+             (let ((overlays (overlays-at (point))))
+               (while overlays
+		 (let ((overlay (car overlays)))
+		   (progn
+                     (when (eq (overlay-get overlay 'invisible) 'outline)
+                       (let ((size (count-lines
+                                    (overlay-end overlay)
+                                    (overlay-start overlay))))
+                         (goto-char (match-beginning 0))
+			 (if (< size diff-file-outline-threshold)
+			     (outline-show-subtree)
+                           (outline-show-branches))))
+                     (setq overlays (cdr overlays))))))))
+	 beg end)))))
+
 ;;; Fine change highlighting.
 
 (defface diff-refine-changed
-- 
2.30.2


--=-=-=
Content-Type: text/plain




In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
 of 2021-11-13 built on carbon
Repository revision: f698c22bffd8cd5dd5c98a86f0e143c4e184b4dc
Repository branch: dev/mm
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-native-compilation'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
X11 XDBE XIM XPM GTK3 ZLIB

Important settings:
  value of $LANG: fr_FR.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: VC dir

Minor modes in effect:
  highlight-changes-visible-mode: t
  shell-dirtrack-mode: t
  minions-mode: t
  desktop-save-mode: t
  save-place-mode: t
  electric-pair-mode: t
  icomplete-mode: t
  global-so-long-mode: t
  global-auto-revert-mode: t
  auto-insert-mode: t
  text-scale-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-layout-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  window-divider-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/home/matthias/.config/emacs/elpa/transient-20211029.1405/transient hides /usr/local/share/emacs/29.0.50/lisp/transient
/home/matthias/.config/emacs/elpa/dictionary-20201001.1727/dictionary hides /usr/local/share/emacs/29.0.50/lisp/net/dictionary

Features:
(shadow flow-fill nndoc gnus-dup url-cache crm debbugs-gnu debbugs
soap-client url-http url-auth url-gw rng-xsd xsd-regexp misearch
multi-isearch emacsbug sendmail mm-archive qp gnus-fun sort smiley
gnus-cite mail-extr gnus-async gnus-bcklg follow gnus-ml disp-table
novice gnus-topic nndraft nnmh nnfolder utf-7 reftex-dcr reftex
reftex-loaddefs reftex-vars tex-mode tramp-archive tramp-gvfs
tramp-cache zeroconf tramp tramp-loaddefs trampver tramp-integration
files-x tramp-compat ls-lisp epa-file gnutls network-stream nsm
gnus-agent gnus-srvr gnus-score score-mode nnvirtual gnus-msg gnus-cache
hl-line add-log smerge-mode diff flyspell ox-odt rng-loc rng-uri
rng-parse rng-match rng-dt rng-util rng-pttrn nxml-parse nxml-ns
nxml-enc xmltok nxml-util ox-latex ox-icalendar org-agenda ox-html table
ox-ascii ox-publish ox goto-addr org-element avl-tree generator ol-eww
eww xdg url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect
gnus-search eieio-opt speedbar ezimage dframe gnus-art mm-uu mml2015
mm-view mml-smime smime dig gnus-sum shr kinsoku svg dom ol-docview
doc-view image-mode exif ol-bibtex ol-bbdb ol-w3m ol-doi org-link-doi
mule-util jka-compr dired-aux bug-reference display-line-numbers
hilit-chg vc-dir whitespace vc-mtn vc-hg vc-bzr vc-src vc-sccs vc-svn
vc-cvs vc-rcs vc bash-completion shell eglot array jsonrpc ert ewoc
debug backtrace xref flymake-proc flymake compile pcase project imenu
avoid minions carbon-custom cus-edit cus-load gnus-demon nntp gnus-group
gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap nnmail
mail-source utf7 netrc parse-time gnus-spec gnus-win nnoo gnus-int
gnus-range message yank-media rmc puny rfc822 mml mml-sec epa derived
epg rfc6068 epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader gnus nnheader gnus-util rmail
rmail-loaddefs rfc2047 rfc2045 ietf-drums mail-utils mm-util mail-prsvr
wid-edit gnus-dired dired-x dired dired-loaddefs org-capture org-refile
org ob ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-footnote
org-src ob-comint org-pcomplete pcomplete comint ansi-color ring
org-list org-faces org-entities org-version ob-emacs-lisp ob-core
ob-eval org-table oc-basic bibtex iso8601 time-date ol org-keys oc
org-compat org-macs org-loaddefs format-spec find-func cal-menu calendar
cal-loaddefs dictionary link connection advice markdown-mode
edit-indirect color thingatpt noutline outline skeleton find-file vc-git
diff-mode easy-mmode vc-dispatcher ispell desktop frameset server
bookmark text-property-search pp saveplace elec-pair icomplete so-long
autorevert filenotify autoinsert cc-mode cc-fonts cc-guess cc-menus
cc-cmds cc-styles cc-align cc-engine cc-vars cc-defs generic-x
face-remap proof-site proof-autoloads info package browse-url url
url-proxy url-privacy url-expand url-methods url-history url-cookie
url-domsuf url-util mailcap url-handlers url-parse auth-source eieio
eieio-core eieio-loaddefs password-cache json map url-vars comp
comp-cstr warnings rx cl-seq cl-macs cl-extra help-mode seq gv subr-x
byte-opt bytecomp byte-compile cconv cl-loaddefs cl-lib iso-transl
tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray
cl-preloaded nadvice button loaddefs faces cus-face macroexp files
window text-properties overlay sha1 md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote threads dbusbind
inotify lcms2 dynamic-setting system-font-setting font-render-setting
cairo move-toolbar gtk x-toolkit x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 1000739 201421)
 (symbols 48 39721 27)
 (strings 32 228421 52284)
 (string-bytes 1 7452737)
 (vectors 16 85442)
 (vector-slots 8 1542974 101097)
 (floats 8 3167 1088)
 (intervals 56 22491 1885)
 (buffers 992 61))

-- 
Matthias

--=-=-=--




Acknowledgement sent to Matthias Meulien <orontee@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#51809; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 14 Nov 2021 18:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.