GNU logs - #51809, boring messages


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 13:10:02 +0000
Resent-Message-ID: <handler.51809.B.16368089931021 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: 51809 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-gnu-emacs@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.16368089931021
          (code B ref -1); Sat, 13 Nov 2021 13:10:02 +0000
Received: (at submit) by debbugs.gnu.org; 13 Nov 2021 13:09:53 +0000
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>
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-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

--=-=-=--




Message sent:


Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-Mailer: MIME-tools 5.505 (Entity 5.505)
Content-Type: text/plain; charset=utf-8
X-Loop: help-debbugs@HIDDEN
From: help-debbugs@HIDDEN (GNU bug Tracking System)
To: Matthias Meulien <orontee@HIDDEN>
Subject: bug#51809: Acknowledgement (29.0.50; [PATCH] Support for outline
 default state in Diff buffers)
Message-ID: <handler.51809.B.16368089931021.ack <at> debbugs.gnu.org>
References: <87lf1sw6ji.fsf@HIDDEN>
X-Gnu-PR-Message: ack 51809
X-Gnu-PR-Package: emacs
X-Gnu-PR-Keywords: patch
Reply-To: 51809 <at> debbugs.gnu.org
Date: Sat, 13 Nov 2021 13:10:02 +0000

Thank you for filing a new bug report with debbugs.gnu.org.

This is an automatically generated reply to let you know your message
has been received.

Your message is being forwarded to the package maintainers and other
interested parties for their attention; they will reply in due course.

Your message has been sent to the package maintainer(s):
 bug-gnu-emacs@HIDDEN

If you wish to submit further information on this problem, please
send it to 51809 <at> debbugs.gnu.org.

Please do not send mail to help-debbugs@HIDDEN unless you wish
to report a problem with the Bug-tracking system.

--=20
51809: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D51809
GNU Bug Tracking System
Contact help-debbugs@HIDDEN with problems


Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 17:49:02 +0000
Resent-Message-ID: <handler.51809.B51809.163682573515163 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163682573515163
          (code B ref 51809); Sat, 13 Nov 2021 17:49:02 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 17:48:55 +0000
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>
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-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?




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 18:09:01 +0000
Resent-Message-ID: <handler.51809.B51809.163682689617171 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163682689617171
          (code B ref 51809); Sat, 13 Nov 2021 18:09:01 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 18:08:16 +0000
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>
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-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




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 18:30:01 +0000
Resent-Message-ID: <handler.51809.B51809.163682815619236 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163682815619236
          (code B ref 51809); Sat, 13 Nov 2021 18:30:01 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 18:29:16 +0000
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>
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-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.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 18:42:02 +0000
Resent-Message-ID: <handler.51809.B51809.163682888720527 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163682888720527
          (code B ref 51809); Sat, 13 Nov 2021 18:42:02 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 18:41:27 +0000
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>
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-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

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 19:31:02 +0000
Resent-Message-ID: <handler.51809.B51809.163683181325540 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163683181325540
          (code B ref 51809); Sat, 13 Nov 2021 19:31:02 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 19:30:13 +0000
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>
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-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)))))




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 21:29:02 +0000
Resent-Message-ID: <handler.51809.B51809.163683889013910 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163683889013910
          (code B ref 51809); Sat, 13 Nov 2021 21:29:02 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 21:28:10 +0000
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>
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-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

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 13 Nov 2021 23:30:04 +0000
Resent-Message-ID: <handler.51809.B51809.16368461642329 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.16368461642329
          (code B ref 51809); Sat, 13 Nov 2021 23:30:04 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 23:29:24 +0000
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>
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-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

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 14 Nov 2021 18:39:02 +0000
Resent-Message-ID: <handler.51809.B51809.16369150827558 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.16369150827558
          (code B ref 51809); Sun, 14 Nov 2021 18:39:02 +0000
Received: (at 51809) by debbugs.gnu.org; 14 Nov 2021 18:38:02 +0000
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>
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-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.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 14 Nov 2021 19:36:01 +0000
Resent-Message-ID: <handler.51809.B51809.163691854321996 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163691854321996
          (code B ref 51809); Sun, 14 Nov 2021 19:36:01 +0000
Received: (at 51809) by debbugs.gnu.org; 14 Nov 2021 19:35:43 +0000
Received: from localhost ([127.0.0.1]:51756 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mmLHz-0005ii-CJ
	for submit <at> debbugs.gnu.org; Sun, 14 Nov 2021 14:35:43 -0500
Received: from mail-wm1-f46.google.com ([209.85.128.46]:35725)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mmLHy-0005iV-0e
 for 51809 <at> debbugs.gnu.org; Sun, 14 Nov 2021 14:35:42 -0500
Received: by mail-wm1-f46.google.com with SMTP id
 77-20020a1c0450000000b0033123de3425so14114662wme.0
 for <51809 <at> debbugs.gnu.org>; Sun, 14 Nov 2021 11:35:41 -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=iKPWAg2N3RCdgB6IhhFFFDOdbRKQgmq1x+fNtYnMbW4=;
 b=KSFztEevCaF/Y1eCZLZNrMtExsd5pnzEnpW5NaTsz2G80mftLqp0JnBO4Cbhber4Fz
 RXD5SGTLBPyli8zocmQqvqXyD/q+aSkP928MgzgevzJdSPDTD/oDZFz6+HMra0lLmVsZ
 M2pko4b8+p4Q8tAzIylOf+q3c8krhZMcO2jOme2SeQLFuXXmZNaSd95wlqnF6lGSP07i
 PpqwXXUyPyACZxCHtnkZvRW/DG71GqDRBRnQ+UFmB+dBQSld5grT4mIM6fcxkn5f5D6x
 AIWH3o8tdHZnnS8Tgdv97FCp3/wVRhet9aqatryFRt/h7U3ZMBJ9kjbIs95CJbrqxLuj
 WF2Q==
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=iKPWAg2N3RCdgB6IhhFFFDOdbRKQgmq1x+fNtYnMbW4=;
 b=JbWq/u/0kru/yNwrJhvSYOtztxE/KUlUWc7aSNQ7yYuTokPGmlOchXTW2lRdamKKis
 HaqRhRCw6ffWZ/aW4BcIh5chxoOZ1jpwNHIllT4yQ1J5YtEHZJ6skuEdWJzQZq283zY7
 BzAVqsjtl7KrjbeFExNoabAMRBIvC3CSxGrAzN16IQrHzvUeKm6WwkyEurD/UntnZyh0
 02C9dYAnI2Zo8dZEsKdX/yvqb6FAVHFxKYlnHkbPXu0pEicS9OJpeuEz+PNwQuVDcMTQ
 WBrjWVf2vgSNwBq35Zpzj9xOHSPNM1JGIDw5Jyax9XloqO7CcHZseCu9zgv9HqnxgioS
 OEWQ==
X-Gm-Message-State: AOAM5301UWqr4xnIbgnLlVtcWQLuL1lg99ZlhQ4v+sjHLTVFj3Oglp5W
 PWBKds3Lsch+sRNeHaujybNzDL4Z1Oc=
X-Google-Smtp-Source: ABdhPJyNyh5e+LNj4EepgghvXTW1fIShyYI1nIlQ4q1X3Jc6+UAbdr6C6Qvv3G35kKk0yz3i9F74bA==
X-Received: by 2002:a05:600c:3486:: with SMTP id
 a6mr20085303wmq.32.1636918536081; 
 Sun, 14 Nov 2021 11:35:36 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id z15sm11807675wrr.65.2021.11.14.11.35.35
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 14 Nov 2021 11:35:35 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <865ysuy56x.fsf@HIDDEN>
Date: Sun, 14 Nov 2021 20:35:33 +0100
In-Reply-To: <865ysuy56x.fsf@HIDDEN> (Juri Linkov's message of "Sun, 
 14 Nov 2021 20:25:18 +0200")
Message-ID: <8735nymsxm.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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:

> 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.

I've observed too that `outline-minor-mode-cycle' didn't worked well in
`diff-mode' buffers but I never saw it working!

Since I am used to hitting TAB to go to next button or for completion,
and I am used to the horrible `outline-minor-mode-prefix' bindings, my
feeling is that TAB was a bad choice for this, and I didn't try to
debug: I just turned off `outline-minor-mode-cycle'...

Do you have `diff-font-lock-prettify' enabled? I remember the situation
was better without this, not sure...
-- 
Matthias




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 14 Nov 2021 19:48:01 +0000
Resent-Message-ID: <handler.51809.B51809.163691927523281 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163691927523281
          (code B ref 51809); Sun, 14 Nov 2021 19:48:01 +0000
Received: (at 51809) by debbugs.gnu.org; 14 Nov 2021 19:47:55 +0000
Received: from localhost ([127.0.0.1]:51760 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mmLTn-00063Q-GY
	for submit <at> debbugs.gnu.org; Sun, 14 Nov 2021 14:47:55 -0500
Received: from relay1-d.mail.gandi.net ([217.70.183.193]:36709)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mmLTk-00062u-Lg
 for 51809 <at> debbugs.gnu.org; Sun, 14 Nov 2021 14:47:53 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 58E17240007;
 Sun, 14 Nov 2021 19:47:44 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <865ysuy56x.fsf@HIDDEN>
 <8735nymsxm.fsf@HIDDEN>
Date: Sun, 14 Nov 2021 21:46:33 +0200
In-Reply-To: <8735nymsxm.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 14 Nov 2021 20:35:33 +0100")
Message-ID: <86r1bisep2.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-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 (-)

>> 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.
>
> I've observed too that `outline-minor-mode-cycle' didn't worked well in
> `diff-mode' buffers but I never saw it working!
>
> Since I am used to hitting TAB to go to next button or for completion,
> and I am used to the horrible `outline-minor-mode-prefix' bindings, my
> feeling is that TAB was a bad choice for this, and I didn't try to
> debug: I just turned off `outline-minor-mode-cycle'...

TAB is not a problem when `outline-minor-mode-cycle-filter'
is customized to allow outline's TAB only on some parts
of the outline heading, e.g. only at the beginning,
or everywhere except the beginning of the diff hunk line.
Then typing TAB everywhere else will go to the next button.

> Do you have `diff-font-lock-prettify' enabled? I remember the situation
> was better without this, not sure...

Nope, `diff-font-lock-prettify' is disabled.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 14 Nov 2021 19:55:01 +0000
Resent-Message-ID: <handler.51809.B51809.163691965223898 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163691965223898
          (code B ref 51809); Sun, 14 Nov 2021 19:55:01 +0000
Received: (at 51809) by debbugs.gnu.org; 14 Nov 2021 19:54:12 +0000
Received: from localhost ([127.0.0.1]:51773 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mmLZr-0006DN-Qe
	for submit <at> debbugs.gnu.org; Sun, 14 Nov 2021 14:54:12 -0500
Received: from mail-wr1-f47.google.com ([209.85.221.47]:43586)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mmLZq-0006DA-Ai
 for 51809 <at> debbugs.gnu.org; Sun, 14 Nov 2021 14:54:10 -0500
Received: by mail-wr1-f47.google.com with SMTP id t30so26299844wra.10
 for <51809 <at> debbugs.gnu.org>; Sun, 14 Nov 2021 11:54:10 -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=3RcbNX+lX7x9F7mIQ4bYkFVbyP7nRNheS/jh/fVVAf0=;
 b=G0e5NU65Lfv60Avp2iKC7oYaP9F/VNefWMdA0QkRTDKJkqIutLf1mr6MzlCKfoQC/j
 lXkZKEeTpR9CGsPG64eac+HQh/yBnNWGJ9aTLBQ6BD0JeQkJz8QOi3pbE4a6tBK2nD/R
 65B+wvKpY1wsifXXi6p++1j1SexwdGjvZp5qHUOWC5QlXOX5We3pvQRBjMlirOvoDLsk
 hu7Dn08t1NA3GRcK3XfzoTcsM48SyqIG+jPvX/2yGo2arI/N6Sa7/KK1Ku1dQAbYaTfO
 X+4ZsG6BTXeY3cohcv1cGH/8eGKfKbEsbFOkNyEUgypKCyhpbXnevdKzt4ga1PsCkngt
 X/dQ==
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=3RcbNX+lX7x9F7mIQ4bYkFVbyP7nRNheS/jh/fVVAf0=;
 b=u8UKxEDWQpEzZclMKpQTAh5zSU1ATUzzVVSiRIsk9Xe+XDVyoEysdlNPps8kozfv/2
 a1SS88WhgjCGg9sU+Lya+GkfxObnYg/5D+yosmD/Llc1CDRVYuX3aB6ULRljlmxhh4kY
 dUcbNUUwUphabgRbEHDadFH6HRda0hivV3SYoq+EQlsxu9hrqyhdZRGQ8GS3hT8HKVh/
 vpwhKkmKZh4WAW0oU9fkPh5B2TOwscTzBrMO35JhVb8tmoKFA3/zOMD2xmxWmTRDYN6q
 uFjrGTIniRZxSbhUEXF9U7whXzH1jbEa2+RT65QkeZNiQK91qyVzi41oEG6JrIANxQpb
 FaoA==
X-Gm-Message-State: AOAM531Nri0M9EGNl8RTNpiYDSj6naa5ilxLcOGO7Nk9GXYKCvP3NQfC
 WjwzNxBCmRWKF0RQ+8tlRaOyLJxnnVU=
X-Google-Smtp-Source: ABdhPJzTJqUsmdGiXGJ7c22fIICTMdvWK2Fvi3sXIbTIo1jBatlWzxVweM1FWnJjnbSMBwpOtdbVyA==
X-Received: by 2002:a5d:6481:: with SMTP id o1mr41324153wri.305.1636919644253; 
 Sun, 14 Nov 2021 11:54:04 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id be3sm7510607wmb.1.2021.11.14.11.54.03
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 14 Nov 2021 11:54:03 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <865ysuy56x.fsf@HIDDEN>
Date: Sun, 14 Nov 2021 20:54:02 +0100
In-Reply-To: <865ysuy56x.fsf@HIDDEN> (Juri Linkov's message of "Sun, 
 14 Nov 2021 20:25:18 +0200")
Message-ID: <87y25qldid.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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:

> 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.

I just tested it: On hunk heading, TAB calls `diff-hunk-next'. On file
headings TAB cycle visibility. It's what I always observed. Looks crazy
but not buggy to my eyes.

-- 
Matthias




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 14 Nov 2021 20:33:02 +0000
Resent-Message-ID: <handler.51809.B51809.163692197227731 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163692197227731
          (code B ref 51809); Sun, 14 Nov 2021 20:33:02 +0000
Received: (at 51809) by debbugs.gnu.org; 14 Nov 2021 20:32:52 +0000
Received: from localhost ([127.0.0.1]:51816 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mmMBH-0007DD-Qn
	for submit <at> debbugs.gnu.org; Sun, 14 Nov 2021 15:32:51 -0500
Received: from relay1-d.mail.gandi.net ([217.70.183.193]:59309)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mmMBG-0007Cg-Cv
 for 51809 <at> debbugs.gnu.org; Sun, 14 Nov 2021 15:32:50 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 9EF9A240005;
 Sun, 14 Nov 2021 20:32:42 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <865ysuy56x.fsf@HIDDEN>
 <87y25qldid.fsf@HIDDEN>
Date: Sun, 14 Nov 2021 22:31:02 +0200
In-Reply-To: <87y25qldid.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 14 Nov 2021 20:54:02 +0100")
Message-ID: <86zgq6pji1.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-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 (-)

>> 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.
>
> I just tested it: On hunk heading, TAB calls `diff-hunk-next'. On file
> headings TAB cycle visibility. It's what I always observed. Looks crazy
> but not buggy to my eyes.

Before the recent changes, TAB cycled visibility not only on file headings,
but also on hunk headings.  It was very useful to use TAB to cycle visibility
on hunk headings on a long patch where navigating to the file heading
to be able to use TAB on it will take too much time.  It's much easier
to navigate to the nearest hunk heading to cycle its visibility.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 29 Nov 2021 17:23:02 +0000
Resent-Message-ID: <handler.51809.B51809.163820657315180 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163820657315180
          (code B ref 51809); Mon, 29 Nov 2021 17:23:02 +0000
Received: (at 51809) by debbugs.gnu.org; 29 Nov 2021 17:22:53 +0000
Received: from localhost ([127.0.0.1]:39218 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mrkMf-0003wh-9f
	for submit <at> debbugs.gnu.org; Mon, 29 Nov 2021 12:22:53 -0500
Received: from relay4-d.mail.gandi.net ([217.70.183.196]:39473)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mrkMQ-0003w2-IV
 for 51809 <at> debbugs.gnu.org; Mon, 29 Nov 2021 12:22:39 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id B9717E000B;
 Mon, 29 Nov 2021 17:22:31 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
Date: Mon, 29 Nov 2021 19:06:40 +0200
In-Reply-To: <878rxrmy7q.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 14 Nov 2021 00:29:13 +0100")
Message-ID: <86y256uc0v.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-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 (-)

Hi Matthias,

> Updated patch that takes Juri comments into account.

I didn't forget about your patch.  Actually, I have been using it all the time,
and it saved me in many cases when long lines in diffs make Emacs unresponsive.
With your patch, there are only slight delays for 2-3 seconds while scrolling
a lot of hidden outlines, but this is not a problem, thank you very much.

I have the same problem of too long outline-body lines in xref buffers,
so need to use a similar feature with:

#+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)
            (outline-map-region
             (lambda ()
               (when (string-match-p "ChangeLog\\|test/manual/etags"
                                     (buffer-substring
                                      (line-beginning-position)
                                      (line-end-position)))
                 (outline-hide-entry)))
             (point-min) (point-max))))
#+end_src

It would be nice to move this feature completely to outline.el,
so it could be used by other modes, not only in diff-mode.
Please see bug#49731 that will be closed after this feature
will be supported generally by outline-minor-mode.

Then there are two variants: to add customizable variables
to outline-minor-mode like outline-default-state or
outline-hide-initial, or allow hiding initial heading
with a hook like

  (add-hook 'outline-minor-mode-hook 'outline-hide-file-headings)

that could use a regexp from e.g. outline-hide-heading-regexp
or some better name.

> +(defun outline-map-sublevel-overlay (level fun)

Instead of adding a new function, you can use outline-map-region
after adding a new argument, e.g.

  (defun outline-map-region (fun beg end &optional next-heading-fun)

By default, outline-map-region uses outline-next-heading to move to the
next heading, but a new argument could allow to use
outline-next-visible-heading or outline-forward-same-level, etc.
with (or (and next-heading-fun (funcall next-heading-fun)) (outline-next-heading))

> +(defcustom diff-outline-file-heading-regexp "ChangeLog\\|package-lock\\.json"

There is no need to add arbitrary default values.
The users know better what values are needed.
For example, I customized it to "public/packs",
so it hides the outline headings for compiled assets like:
"public/packs-pro/js/application-fa9d8202220130e40f46.js"

> +(defun diff-outline-apply-default-state ()
> +  (when diff-outline-default-state
> +    (when (not outline-minor-mode)
> +      (outline-minor-mode))

Actually, the above lines are not needed because the same can be achieved by:

  (add-hook 'diff-mode-hook 'outline-minor-mode)

> +    (cond
> +     ((eq diff-outline-default-state 'outline-hunks)
> +      (outline-hide-body))

These lines are not needed too, because the same can be achieved by:

  (add-hook 'outline-minor-mode-hook 'outline-hide-body)

> +     ((when (functionp diff-outline-default-state)
> +        (funcall diff-outline-default-state))))))

And this can be achieved by:

  (add-hook 'outline-minor-mode-hook 'custom-function)

> +(defun diff--outline-set-file-heading-visibility (overlay)
> +  (cond
> +   ((and
> +     (memq 'file-heading-regexp
> +           diff-outline-default-state)
> +     (string-match-p
> +      diff-outline-file-heading-regexp
> +      (match-string 0)))

Here (match-string 0) is unusable in most values of outline-regexp
that don't contain the whole heading line.  A better way
to get the whole heading line usable in modes other than diff-mode
would be:

  (buffer-substring (line-beginning-position) (line-end-position))




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
In-Reply-To: <87lf1sw6ji.fsf@HIDDEN>
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 30 Nov 2021 19:34:01 +0000
Resent-Message-ID: <handler.51809.B51809.16383008228541 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.16383008228541
          (code B ref 51809); Tue, 30 Nov 2021 19:34:01 +0000
Received: (at 51809) by debbugs.gnu.org; 30 Nov 2021 19:33:42 +0000
Received: from localhost ([127.0.0.1]:42552 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ms8so-0002Dh-Df
	for submit <at> debbugs.gnu.org; Tue, 30 Nov 2021 14:33:42 -0500
Received: from mail-wm1-f49.google.com ([209.85.128.49]:44940)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1ms8sm-0002DU-SQ
 for 51809 <at> debbugs.gnu.org; Tue, 30 Nov 2021 14:33:41 -0500
Received: by mail-wm1-f49.google.com with SMTP id
 p27-20020a05600c1d9b00b0033bf8532855so15563415wms.3
 for <51809 <at> debbugs.gnu.org>; Tue, 30 Nov 2021 11:33:40 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:cc:subject:references:date:message-id:mime-version;
 bh=16cvAqB3D8dz28wv//XGQCoRIPzwb0bVaE8Emv42hfo=;
 b=fdTawBWfRv/Dy//RMZVIVCBzwsuc5If9v03FlLmWGzFJeALVox+1YRZoPL/ybKgoZq
 OHWM9FKSrrRNqi4kRqdf4GvEX7doMFZpHnWBMElkmoI7q20pGXE9rs6ByBIoD7twXd9B
 6XR3IoOhIfdTxo7P3J5wKml5gj/m9oZBcJxuzlyJ6Iy/tI6/7p3jZlUyB2nX9e/88KZw
 bgW7vxkdQIgpAYoEqUSRdTlMDnEfLT1wQCcWg2zPZcfxaTXlfLTrvvDZX/w+XGogLRPF
 Zm8GYEha0nzT1jUVwcQguGEMoeMXMu/zNtTNCztOtUKihPqujernFy4Fj3opkF5t9ntY
 U5lg==
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:message-id
 :mime-version;
 bh=16cvAqB3D8dz28wv//XGQCoRIPzwb0bVaE8Emv42hfo=;
 b=DNrS7WMOnfayFbYeHF3SgDtmFKJu4VZ2V3W7Uqdf6IRAE52JW/DCuI8mnbvNL76ubM
 EgkvGob8Vilb+vI/ZmIsf48aDDaT3O4tH0sKKTMeEwQUXrujJBHytTWRVf4vH9797Vc2
 5hB4An9ZuD6BhUAR6SQ57gEEF1ZpxwD0fnOL+zNK/emtYUClpLjws4pPcbj6NFKKPrYj
 NAVD9hs6fmcB22acPexsHEYp7b0Zgg2x6tBRjcWM6OVPUFON8zsrf6dPIbcj/eq10ipw
 +LFyLeKzr4huw7lAYp6MiUzdYSutJc+W0F//vMFM9rHTodCLl5JiINPmPbxUbLPdwx43
 tTTA==
X-Gm-Message-State: AOAM5306XdaxOT30VMMSDqxrUuHCSv73f4dIHY+CIEeGx1VQLzFsUMuw
 yjGFcLcQ6X8zTi60x85YTaz/Wl0nzNk=
X-Google-Smtp-Source: ABdhPJxu5CrUMsaIq6SBULOLN16gJbBiMyy6TO1FrNajbiNyZtpAJI+akJUAp8eixrGvrT7FqtBfeg==
X-Received: by 2002:a1c:9d03:: with SMTP id g3mr794976wme.143.1638300814839;
 Tue, 30 Nov 2021 11:33:34 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:f180:2554:8940:34b0])
 by smtp.gmail.com with ESMTPSA id n32sm4206647wms.1.2021.11.30.11.33.34
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 30 Nov 2021 11:33:34 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN>
Date: Tue, 30 Nov 2021 20:33:33 +0100
Message-ID: <87bl21igky.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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 (-)

Hi Juri,

> (...) Actually, I have been using it all the time, and it saved me in
> many cases when long lines in diffs make Emacs unresponsive.

Good news!

> I have the same problem of too long outline-body lines in xref
> buffers, (...)  It would be nice to move this feature completely to
> outline.el,

I fully agree.

> so it could be used by other modes, not only in diff-mode.
> Please see bug#49731 that will be closed after this feature
> will be supported generally by outline-minor-mode.
>
> Then there are two variants:

Yes. I'll think of it. If I remember correctly, org-mode handles an
initial state too, I've no idea of how it's implemented there. It may
help to choose between the two variants in order to merge all
implementations in one place at some point.

And many thanks for your comments on the patch. I'll modify it after I
have had a look at your sugestion to move the feature to outline.el. But
since I've not much spare time, please be patient!
-- 
Matthias




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 11 Dec 2021 18:19:02 +0000
Resent-Message-ID: <handler.51809.B51809.163924674023628 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163924674023628
          (code B ref 51809); Sat, 11 Dec 2021 18:19:02 +0000
Received: (at 51809) by debbugs.gnu.org; 11 Dec 2021 18:19:00 +0000
Received: from localhost ([127.0.0.1]:49958 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mw6xX-000692-Io
	for submit <at> debbugs.gnu.org; Sat, 11 Dec 2021 13:18:59 -0500
Received: from mail-wm1-f41.google.com ([209.85.128.41]:54130)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mw6xT-00068S-0d
 for 51809 <at> debbugs.gnu.org; Sat, 11 Dec 2021 13:18:57 -0500
Received: by mail-wm1-f41.google.com with SMTP id y196so9102142wmc.3
 for <51809 <at> debbugs.gnu.org>; Sat, 11 Dec 2021 10:18:54 -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=lUrGX/JN2Zwn2nf80DrQU2Qhpiu8to3tyEqnNigNaIs=;
 b=dcnHH2KVgIePsGhQgH1LzlPFC9miAD20CUnGB0CUR4cgz0Ulr0n9AsEGrFlDWMxqm/
 en1s/mjdRnplitjsLrmC5DzW7jOjJ0CM3K+CHvaiEZGUyxfTXz2bVV3JjbZksJBIwviO
 pjqDtbEYcVrHSROXpZxE8vu20TTWpuX/z34k8pltluNfQsp+gQQEEw4OjnEGmxhlAeoU
 lMIbDXIdxpVsG3SqLwMvbvkAweyHw8pLYQFaAvsl7dSLCZ2mryP26mQVf9uU9YDEw85K
 dLL6IvX7wB4UjY+5xNr3If0X0pRqhJVIQB4XgPbL+6P39lHoMMW2ZKhqUyymU+bD+EXM
 5ruA==
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=lUrGX/JN2Zwn2nf80DrQU2Qhpiu8to3tyEqnNigNaIs=;
 b=O6AW3Cd1l+k5mAUgkDeqUhz1omOB4kGTV7wK4dDa97G1Eu4Qja+9gE/uyOe7HAdOV+
 gKPbH/JjJnC2ueI/dZPDz9/jcqsVDxQcIrAgSGi1fNRhoercL9mIp7Ou5JeIr7+k+mvo
 W7qA8p3s3G+FsA5Le3SCsuDADVo0IFdyFap6eWPD6KOOMQIK69AG07+4CR6yz1LmliT5
 Nb6bTQYcdryopXJwU//a5uv3mVrSxdWbKuMOKaU5OqmHTrZK3cGORFqByR3bEgE8r18T
 KkZScYsszNI1NB4oqEfTa+rEabft9o76k177GsliENC+l8X9owkoN3WO8hoO8x4K4dSP
 IDpQ==
X-Gm-Message-State: AOAM533xL92xSYbFGqghycIliPwIe0JMIWpT5T06pYR+G7n2iOUduQg/
 /7w1YfAU35Cts15/1J1/FP6pq50CeRA=
X-Google-Smtp-Source: ABdhPJzuHpENWjnrecmZk5tNZDP87V4IKC/M3WdF39D4pCyaJZTU4IJXs0rcGAjJTIrEXDF20LX4+A==
X-Received: by 2002:a1c:23d2:: with SMTP id j201mr25564049wmj.76.1639246728780; 
 Sat, 11 Dec 2021 10:18:48 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id g13sm2708599wri.102.2021.12.11.10.18.47
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 11 Dec 2021 10:18:47 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN>
Date: Sat, 11 Dec 2021 19:18:44 +0100
In-Reply-To: <86y256uc0v.fsf@HIDDEN> (Juri Linkov's message of "Mon, 
 29 Nov 2021 19:06:40 +0200")
Message-ID: <87r1ajknsr.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-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

Hi Juri,

Juri Linkov <juri@HIDDEN> writes:

> (...) It would be nice to move this feature completely to outline.el,
> so it could be used by other modes, not only in diff-mode.

I've this simple patch for the outline.el part.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Extend-Outline-mode-with-default-visibility-state.patch

From d8fee4c307178fc2e0e7c206b8b8a42b2acda719 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Wed, 8 Dec 2021 22:35:42 +0100
Subject: [PATCH] Extend Outline mode with default visibility state

* lisp/outline.el (outline-mode, outline-minor-mode): Ensure default
visibility state is applied
(outline-hide-sublevels): Add optional argument for function to call
on each heading
(outline-default-state): Define the default visibility state
(outline-apply-default-state): Apply default visibility state
---
 lisp/outline.el | 50 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 45 insertions(+), 5 deletions(-)

diff --git a/lisp/outline.el b/lisp/outline.el
index 2ede4e23ea..a3e5da4f5b 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -353,7 +353,8 @@ outline-mode
               '(outline-font-lock-keywords t nil nil backward-paragraph))
   (setq-local imenu-generic-expression
 	      (list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
-  (add-hook 'change-major-mode-hook #'outline-show-all nil t))
+  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
+  (outline-apply-default-state))
 
 (defvar outline-minor-mode-map)
 
@@ -436,7 +437,8 @@ outline-minor-mode
 		  nil t)
         (setq-local line-move-ignore-invisible t)
 	;; Cause use of ellipses for invisible text.
-	(add-to-invisibility-spec '(outline . t)))
+	(add-to-invisibility-spec '(outline . t))
+        (outline-apply-default-state))
     (when (or outline-minor-mode-cycle outline-minor-mode-highlight)
       (if font-lock-fontified
           (font-lock-remove-keywords nil outline-font-lock-keywords))
@@ -1058,13 +1060,16 @@ outline-show-heading
 		       (progn (outline-end-of-heading) (point))
 		       nil))
 
-(defun outline-hide-sublevels (levels)
+(defun outline-hide-sublevels (levels &optional fun)
   "Hide everything but the top LEVELS levels of headers, in whole buffer.
 This also unhides the top heading-less body, if any.
 
 Interactively, the prefix argument supplies the value of LEVELS.
 When invoked without a prefix argument, LEVELS defaults to the level
-of the current heading, or to 1 if the current line is not a heading."
+of the current heading, or to 1 if the current line is not a heading.
+
+When FUN is defined, sublevels aren't hidden but FUN is called
+for each of them."
   (interactive (list
 		(cond
 		 (current-prefix-arg (prefix-numeric-value current-prefix-arg))
@@ -1093,7 +1098,9 @@ outline-hide-sublevels
       (outline-map-region
        (lambda ()
 	 (if (<= (funcall outline-level) levels)
-	     (outline-show-heading)))
+	     (if fun
+                 (funcall fun)
+               (outline-show-heading))))
        beg end)
       ;; Finally unhide any trailing newline.
       (goto-char (point-max))
@@ -1307,6 +1314,39 @@ outline-headers-as-kill
                     (insert "\n\n"))))))
           (kill-new (buffer-string)))))))
 
+(defcustom outline-default-state nil
+  "If non-nil, some headings are initially outlined.
+
+If equal to `only-headings', only heading are shown.
+
+If equal to a number, hide everything but the headings at that
+level.
+
+If equal to a lambda function or function name, this function is
+expected to toggle headings visibility, and will be called after
+the mode is enabled."
+  :version "29.1"
+  :type '(choice (const :tag "Show all" nil)
+                 (const :tag "Only headings" only-headings)
+                 (natnum :tag "Outline level")
+                 (function :tag "Custom function"))
+  :local t
+  :safe t)
+;; TODO fix variable being set through file local variable
+
+(defun outline-apply-default-state ()
+  "Apply the outline state defined by `outline-default-state'."
+  (interactive)
+  (cond
+   ((not outline-default-state) (outline-show-all))
+   ((eq outline-default-state 'only-headings)
+    (outline-show-all)
+    (outline-hide-region-body (point-min) (point-max)))
+   ((integerp outline-default-state)
+    (outline-hide-sublevels outline-default-state))
+   ((when (functionp outline-default-state)
+      (funcall outline-default-state)))))
+
 (defun outline--cycle-state ()
   "Return the cycle state of current heading.
 Return either 'hide-all, 'headings-only, or 'show-all."
-- 
2.30.2


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


One thing that bothers me is that I am not able to store the wanted
default visibility state as a local variable... Any suggestion welcome!

Also, I've not started to rewrite the diff-mode part on top of this
patch, so comments are most welcome in case I am going in wrong
direction.
-- 
Matthias


--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 12 Dec 2021 08:59:02 +0000
Resent-Message-ID: <handler.51809.B51809.163929952620490 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163929952620490
          (code B ref 51809); Sun, 12 Dec 2021 08:59:02 +0000
Received: (at 51809) by debbugs.gnu.org; 12 Dec 2021 08:58:46 +0000
Received: from localhost ([127.0.0.1]:50648 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mwKgv-0005KQ-Tx
	for submit <at> debbugs.gnu.org; Sun, 12 Dec 2021 03:58:46 -0500
Received: from relay11.mail.gandi.net ([217.70.178.231]:56863)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mwKgt-0005Jr-Ou
 for 51809 <at> debbugs.gnu.org; Sun, 12 Dec 2021 03:58:44 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay11.mail.gandi.net (Postfix) with ESMTPSA id 9B511100006;
 Sun, 12 Dec 2021 08:58:36 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
Date: Sun, 12 Dec 2021 10:43:39 +0200
In-Reply-To: <87r1ajknsr.fsf@HIDDEN> (Matthias Meulien's message of "Sat,
 11 Dec 2021 19:18:44 +0100")
Message-ID: <86ilvu6w6k.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-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've this simple patch for the outline.el part.

Thanks, this is a good starting point to add just the basic functionality
like org-mode initial visibility supported by ‘org-startup-folded’ and
per-file settings:

   #+STARTUP: fold              (or ‘overview’, this is equivalent)
   #+STARTUP: nofold            (or ‘showall’, this is equivalent)
   #+STARTUP: content
   #+STARTUP: show<n>levels (<n> = 2..5)
   #+STARTUP: showeverything

> @@ -1058,13 +1060,16 @@ outline-show-heading
> -(defun outline-hide-sublevels (levels)
> +(defun outline-hide-sublevels (levels &optional fun)

It seems you don't use this argument in this patch?

> +  :local t
> +  :safe t)
> +;; TODO fix variable being set through file local variable

> One thing that bothers me is that I am not able to store the wanted
> default visibility state as a local variable... Any suggestion welcome!

For example, `outline-minor-mode-cycle' and `outline-minor-mode-highlight'
have no `:local t', but when visiting a file that sets these file local variables,
then automatically become local.

> +(defun outline-apply-default-state ()
> +  "Apply the outline state defined by `outline-default-state'."
> +  (interactive)
> +  (cond
> +   ((not outline-default-state) (outline-show-all))

It seems this change doesn't keep the current default behavior.
Maybe the result will look like it currently works, maybe not.
Who knows what effect will have calling `outline-show-all'
by default in some user configurations.

> +   ((eq outline-default-state 'only-headings)
> +    (outline-show-all)
> +    (outline-hide-region-body (point-min) (point-max)))
> +   ((integerp outline-default-state)
> +    (outline-hide-sublevels outline-default-state))
> +   ((when (functionp outline-default-state)
> +      (funcall outline-default-state)))))

Maybe some other values from org-mode could be supported too?

> Also, I've not started to rewrite the diff-mode part on top of this
> patch, so comments are most welcome in case I am going in wrong
> direction.

I think the direction is right: first outline could support
the initial visibility feature, then later various modes
could use it: in diff-mode, xref, etc.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 13 Dec 2021 07:56:02 +0000
Resent-Message-ID: <handler.51809.B51809.163938215621742 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.163938215621742
          (code B ref 51809); Mon, 13 Dec 2021 07:56:02 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Dec 2021 07:55:56 +0000
Received: from localhost ([127.0.0.1]:53935 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mwgBg-0005eb-4o
	for submit <at> debbugs.gnu.org; Mon, 13 Dec 2021 02:55:56 -0500
Received: from mail-wr1-f43.google.com ([209.85.221.43]:46054)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1mwgBc-0005eM-TJ
 for 51809 <at> debbugs.gnu.org; Mon, 13 Dec 2021 02:55:54 -0500
Received: by mail-wr1-f43.google.com with SMTP id o13so25405683wrs.12
 for <51809 <at> debbugs.gnu.org>; Sun, 12 Dec 2021 23:55:52 -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=gLRXiwU7+S++uM5mYo7JKoieAqn0EwjL0sCvvOdT5Yg=;
 b=MYXuyoq0hPNamnvhgtQ/ddJbdgTmXO8VQEuQ+TL+LVoA2jdrwLne6ku1xvuWzJY8M/
 q20zfYXATRc9sJ31vD83+hy5zIW3FTtQrn/5eQ6kUJ2i4iICw3ovvIEzxfmdC4xhsPia
 BwxsjZCzN7bah2XOKJr2bf3pil7n+mkCNj5Qzk1FlxfayYsK+klHfLqckWQscm/0ftAR
 btI0USRalqGik8zvSw7aDQWMI4ZGls7zIFyMgSpj8vvFbnXK9wbQdRdFLilBbi/1O4/u
 t4PKSLozdI7RUIJIKdSNjG5tgAsbrMm2C7pz0fpArA/2Toy7UTajRKFQXJli8R5Rf2OF
 lSeQ==
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=gLRXiwU7+S++uM5mYo7JKoieAqn0EwjL0sCvvOdT5Yg=;
 b=x1MVtEmqyxDnydXrMEW7qzLkjWDGnYi5SVFkpYbqYN2//zo6RQfT0coyHqnrJio4jo
 QZ8rOk9z+iVLKGFAe/IBkA1JSn/sdzKax7Bzcd0c6dUwQG5CLdQifGJMjtTd/ruJ1q19
 soN5AOGNMw75QyWdqJjQ1Cn3NBmV2jblIp9op3KP0H/jbQhPJr1mmFBjqQ6tu69bKAHH
 PueZj84J1lCOca4wwteTfRsaWR0e0QPf4GShpYcUG/Uypb76x9wjSQLAAxD35ofczLYs
 VAuJGPmHeo4hUyMyqqf//cZM70N2aNJmH7bmNqOhlb8BkhmPTIzIcFjIIC3qkHYNmdle
 4fvw==
X-Gm-Message-State: AOAM532rCX441k8vlJZ34VUMQMPShRMCDcQOGIKxcDwBNM0oZE/J7qPw
 bE3j5UbhaJ+Kyvms0yAsd5ChZgiKQXo=
X-Google-Smtp-Source: ABdhPJxVTd/3oJImtVHsLYa+QhnDr1QBMiRj/3AkWY3QhkG71htiqFGYddq8k0+QKfVvy69/0+0Cwg==
X-Received: by 2002:adf:f0c8:: with SMTP id x8mr30473924wro.290.1639382146703; 
 Sun, 12 Dec 2021 23:55:46 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id p12sm10025162wro.33.2021.12.12.23.55.45
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 12 Dec 2021 23:55:46 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN>
Date: Mon, 13 Dec 2021 08:55:45 +0100
In-Reply-To: <86ilvu6w6k.fsf@HIDDEN> (Juri Linkov's message of "Sun, 
 12 Dec 2021 10:43:39 +0200")
Message-ID: <871r2hc51a.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-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've this simple patch for the outline.el part.
>
> Thanks, this is a good starting point to add just the basic functionality
> like org-mode initial visibility supported by =E2=80=98org-startup-folded=
=E2=80=99 and
> per-file settings:
>
>    #+STARTUP: fold              (or =E2=80=98overview=E2=80=99, this is e=
quivalent)
>    #+STARTUP: nofold            (or =E2=80=98showall=E2=80=99, this is eq=
uivalent)
>
>    #+STARTUP: content
>    #+STARTUP: show<n>levels (<n> =3D 2..5)
>
>    #+STARTUP: showeverything
>
>> @@ -1058,13 +1060,16 @@ outline-show-heading
>> -(defun outline-hide-sublevels (levels)
>> +(defun outline-hide-sublevels (levels &optional fun)
>
> It seems you don't use this argument in this patch?

It will be necessary for `diff-mode' to provide its own default state
functions that decide of the visibility of each heading
individually. You're right, it's not needed right now so I'll remove it
and reintroduce it when working on `diff-mode'.

>> +  :local t
>> +  :safe t)
>> +;; TODO fix variable being set through file local variable
>
>> One thing that bothers me is that I am not able to store the wanted
>> default visibility state as a local variable... Any suggestion welcome!
>
> For example, `outline-minor-mode-cycle' and `outline-minor-mode-highlight'
> have no `:local t', but when visiting a file that sets these file local v=
ariables,
> then automatically become local.
>
>> +(defun outline-apply-default-state ()
>> +  "Apply the outline state defined by `outline-default-state'."
>> +  (interactive)
>> +  (cond
>> +   ((not outline-default-state) (outline-show-all))
>
> It seems this change doesn't keep the current default behavior.
> Maybe the result will look like it currently works, maybe not.
> Who knows what effect will have calling `outline-show-all'
> by default in some user configurations.

Good point. I can remove that line but one must be aware that calling
`outline-apply-default-state' interactively after changing some headings
visibility won't restore the default state. Not very intuitive...

>
>> +   ((eq outline-default-state 'only-headings)
>> +    (outline-show-all)
>> +    (outline-hide-region-body (point-min) (point-max)))
>> +   ((integerp outline-default-state)
>> +    (outline-hide-sublevels outline-default-state))
>> +   ((when (functionp outline-default-state)
>> +      (funcall outline-default-state)))))
>
> Maybe some other values from org-mode could be supported too?

Sure.

Let me first fix handling of local values. I saw that `outline-mode' is
set *before* local variables when I visit a file whose major mode
default to `outline-mode'.=20

> I think the direction is right: first outline could support
> the initial visibility feature, then later various modes
> could use it: in diff-mode, xref, etc.

That's my plan.

For xref mode I am wondering whether "regexp" based outline mode is the
right thing to use. Should there be an outline mode based on
text-properties? The buffer content is built internally and we know
where "headings" are inserted... But it's another topic.

Thanks for reading the patch! I'll send another one, hopefully taking
your remarks into account, when support of local variables is fixed.
--=20
Matthias




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 13 Dec 2021 09:49:02 +0000
Resent-Message-ID: <handler.51809.B51809.1639388905393 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.1639388905393
          (code B ref 51809); Mon, 13 Dec 2021 09:49:02 +0000
Received: (at 51809) by debbugs.gnu.org; 13 Dec 2021 09:48:25 +0000
Received: from localhost ([127.0.0.1]:54174 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1mwhwW-00006G-MH
	for submit <at> debbugs.gnu.org; Mon, 13 Dec 2021 04:48:25 -0500
Received: from relay5-d.mail.gandi.net ([217.70.183.197]:47557)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1mwhwU-00005j-0i
 for 51809 <at> debbugs.gnu.org; Mon, 13 Dec 2021 04:48:23 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id C67DA1C0002;
 Mon, 13 Dec 2021 09:48:14 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
Date: Mon, 13 Dec 2021 10:58:42 +0200
In-Reply-To: <871r2hc51a.fsf@HIDDEN> (Matthias Meulien's message of "Mon,
 13 Dec 2021 08:55:45 +0100")
Message-ID: <86fsqwc01d.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-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 (-)

>> Thanks, this is a good starting point to add just the basic functionality
>> like org-mode initial visibility supported by ‘org-startup-folded’ and
>> per-file settings:
>>
>>    #+STARTUP: fold              (or ‘overview’, this is equivalent)
>>    #+STARTUP: nofold            (or ‘showall’, this is equivalent)
>>    #+STARTUP: content
>>    #+STARTUP: show<n>levels (<n> = 2..5)
>>    #+STARTUP: showeverything
>>
>>> @@ -1058,13 +1060,16 @@ outline-show-heading
>>> -(defun outline-hide-sublevels (levels)
>>> +(defun outline-hide-sublevels (levels &optional fun)
>>
>> It seems you don't use this argument in this patch?
>
> It will be necessary for `diff-mode' to provide its own default state
> functions that decide of the visibility of each heading
> individually. You're right, it's not needed right now so I'll remove it
> and reintroduce it when working on `diff-mode'.

When we will have enough outline functions to be used as values
of `outline-default-state', then `diff-mode' doesn't need to provide
its own default state functions - `diff-mode' could just set
a suitable buffer-local value of `outline-default-state'
from the list of options provided by `outline-default-state'.

Also `outline-default-state' could support a string value
applied as a regexp on outline heading lines to decide
whether to hide or show that outline.

>>> +  (cond
>>> +   ((not outline-default-state) (outline-show-all))
>>
>> It seems this change doesn't keep the current default behavior.
>> Maybe the result will look like it currently works, maybe not.
>> Who knows what effect will have calling `outline-show-all'
>> by default in some user configurations.
>
> Good point. I can remove that line but one must be aware that calling
> `outline-apply-default-state' interactively after changing some headings
> visibility won't restore the default state. Not very intuitive...

`outline-default-state' could provide an explicit value
that will show all outlines.  Maybe even the default value
of `outline-default-state' could be changed to this explicit value.
Then calling `outline-apply-default-state' interactively
will show all outlines.  This way it will be more clear
to users what is going on.

>>> +   ((eq outline-default-state 'only-headings)
>>> +    (outline-show-all)
>>> +    (outline-hide-region-body (point-min) (point-max)))
>>> +   ((integerp outline-default-state)
>>> +    (outline-hide-sublevels outline-default-state))
>>> +   ((when (functionp outline-default-state)
>>> +      (funcall outline-default-state)))))
>>
>> Maybe some other values from org-mode could be supported too?
>
> Sure.

Ideally, there should be an outline-mode function for most values,
so there should be no need for special handling, e.g. instead of
special handling of `only-headings', an outline command should
handle this by funcall (maybe there is an existing function that does this?)

Only integer and string values should have special handling here.

> Let me first fix handling of local values. I saw that `outline-mode' is
> set *before* local variables when I visit a file whose major mode
> default to `outline-mode'.

I don't know where is the problem.  For example, in etc/compilation.txt
these lines set local variables correctly:

  ;;; outline-minor-mode-cycle: t
  ;;; outline-minor-mode-highlight: t
  ;;; mode: outline-minor

> For xref mode I am wondering whether "regexp" based outline mode is the
> right thing to use. Should there be an outline mode based on
> text-properties? The buffer content is built internally and we know
> where "headings" are inserted... But it's another topic.

Good idea.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 26 Dec 2021 16:06:02 +0000
Resent-Message-ID: <handler.51809.B51809.16405347376802 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.16405347376802
          (code B ref 51809); Sun, 26 Dec 2021 16:06:02 +0000
Received: (at 51809) by debbugs.gnu.org; 26 Dec 2021 16:05:37 +0000
Received: from localhost ([127.0.0.1]:41340 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n1W1g-0001lb-9o
	for submit <at> debbugs.gnu.org; Sun, 26 Dec 2021 11:05:36 -0500
Received: from mail-wm1-f53.google.com ([209.85.128.53]:38722)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n1W1e-0001lN-6k
 for 51809 <at> debbugs.gnu.org; Sun, 26 Dec 2021 11:05:34 -0500
Received: by mail-wm1-f53.google.com with SMTP id
 p1-20020a1c7401000000b00345c2d068bdso7221889wmc.3
 for <51809 <at> debbugs.gnu.org>; Sun, 26 Dec 2021 08:05:34 -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=IvjGxsGNHYA1R3qbbbxA5SE3zYTrkq2nJbOel6YB1zg=;
 b=cVow58PlrCbFe9q1VPa9+j5C6X5uPiQBCrmIxgeBiudz1AuI1OOCL+COqe4zVI2OVG
 0A4m2b4OxMmI8cje7HyEMUr6h+rOubloVYxV55BrG0wDRM3knAc/2oQMnA4XeJ1pjMoM
 iraLunP9slzKFzwNzRAVf3zK2QZF/FfDLGRcR3XsnAfHJ1xsFuEF2D/s/VmEMzfWSubF
 U5Ia2qtte8KzXQPzdSW5dOQTeJTAAWrOStFFdFjUYebK5BKto1XO99KzVcHjQRu1sT9G
 XfDJyVX2LzllgCX7Yg2uZ1BkBoZjlXm1VtRpTzjWm+9YB+zt39QVKqtbyuhOGWvZrGYz
 CypQ==
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=IvjGxsGNHYA1R3qbbbxA5SE3zYTrkq2nJbOel6YB1zg=;
 b=T2A45uaBXW/JMuHRMb5dwvAS2elAKUv9LiRBPKMZQxY/pxGco4NOM/WsJheSBRoPPo
 hGwWjYLkt11oPH4gkNtBxwTsPX2t7o6kCQYO8hm/i+cxRYCwKS1KB39jx5usgpcC50fs
 DiCG/guL7RvowCZ3eocSxX/6H0Fksv/uTpX1CicYVVxgJ6sIrxKELhY4/loGpbUHmIhj
 kWwEVo8b6zX/f7JgwHo5oblrOXp6QsEzAvRrO2vzV0CkaTp1f2ERCKJ1bXqieeH02Zjo
 pIbKFlCs0BF2NJBezpVS16YC82CQEfUFwwZZWVogTTPd8M27iSnuAzcalykfsKFasxE8
 waHw==
X-Gm-Message-State: AOAM530FCAGdjUmRo1ocxK55d4g/bNQhYycqC7a7nIKmK5ZW7WrZ7bdX
 DBeOuPDhYdcM7CZzfC91wrWxUSPeR2Y=
X-Google-Smtp-Source: ABdhPJyrWmnyJ7+fA641VPNkGGqjsefOwc8x5K2iIgXuFrGogtADU4oRaMxZdgUxFkEretXwiKtHug==
X-Received: by 2002:a1c:8002:: with SMTP id b2mr10628226wmd.2.1640534728436;
 Sun, 26 Dec 2021 08:05:28 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id m17sm12953105wrz.91.2021.12.26.08.05.27
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 26 Dec 2021 08:05:27 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
Date: Sun, 26 Dec 2021 17:05:25 +0100
In-Reply-To: <871r2hc51a.fsf@HIDDEN> (Matthias Meulien's message of "Mon,
 13 Dec 2021 08:55:45 +0100")
Message-ID: <87r19zs662.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-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:

> (...) Thanks for reading the patch! I'll send another one, hopefully
> taking your remarks into account, when support of local variables is
> fixed.

Here is an updated patch implementing a default state for Outline mode
and Outline minor mode:


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Extend-Outline-mode-with-default-visibility-state.patch

From db0cf942950c7e997d2701742ce16c8385f452e0 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Wed, 8 Dec 2021 22:35:42 +0100
Subject: [PATCH] Extend Outline mode with default visibility state

* lisp/outline.el (outline-mode, outline-minor-mode): Ensure default
visibility state is applied
(outline-hide-sublevels): Add optional argument for function to call
on each heading
(outline-default-state): Define the default visibility state
(outline-apply-default-state): Apply default visibility state
---
 lisp/outline.el | 183 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 180 insertions(+), 3 deletions(-)

diff --git a/lisp/outline.el b/lisp/outline.el
index 2ede4e23ea..c52b9cd4e7 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -353,7 +353,9 @@ outline-mode
               '(outline-font-lock-keywords t nil nil backward-paragraph))
   (setq-local imenu-generic-expression
 	      (list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
-  (add-hook 'change-major-mode-hook #'outline-show-all nil t))
+  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
+  (add-hook 'hack-local-variables-hook
+	    #'outline-apply-default-state))
 
 (defvar outline-minor-mode-map)
 
@@ -436,7 +438,9 @@ outline-minor-mode
 		  nil t)
         (setq-local line-move-ignore-invisible t)
 	;; Cause use of ellipses for invisible text.
-	(add-to-invisibility-spec '(outline . t)))
+	(add-to-invisibility-spec '(outline . t))
+        (add-hook 'hack-local-variables-hook
+	          #'outline-apply-default-state))
     (when (or outline-minor-mode-cycle outline-minor-mode-highlight)
       (if font-lock-fontified
           (font-lock-remove-keywords nil outline-font-lock-keywords))
@@ -1093,7 +1097,7 @@ outline-hide-sublevels
       (outline-map-region
        (lambda ()
 	 (if (<= (funcall outline-level) levels)
-	     (outline-show-heading)))
+             (outline-show-heading)))
        beg end)
       ;; Finally unhide any trailing newline.
       (goto-char (point-max))
@@ -1307,6 +1311,179 @@ outline-headers-as-kill
                     (insert "\n\n"))))))
           (kill-new (buffer-string)))))))
 
+(defcustom outline-default-state nil
+  "If non-nil, some headings are initially outlined.
+
+If equal to `outline-show-all', all text of buffer is shown.
+
+If equal to `outline-show-only-headings', only headings are shown.
+
+If equal to a number, show only headings up to the corresponding
+level. See `outline-default-state-subtree-visibility' to
+customize visibility of the subtree at the choosen level.
+
+If equal to a lambda function or function name, this function is
+expected to toggle headings visibility, and will be called after
+the mode is enabled."
+  :version "29.1"
+  :type '(choice (const :tag "Disabled" nil)
+                 (const :tag "Show all" outline-show-all)
+                 (const :tag "Only headings" outline-show-only-headings)
+                 (natnum :tag "Show headings up to level" :value 1)
+                 (function :tag "Custom function")))
+
+(defcustom outline-default-state-subtree-visibility nil
+  "Defines visibility of subtree starting at level defined by `outline-default-state'.
+
+When nil, the subtree is hidden unconditionally.
+
+When equal to a list, each element is expected to equal one of:
+
+- A cons cell with CAR `match-regexp' and CDR a regexp, the
+  subtree will be hidden when the outline heading match the
+  regexp.
+
+- `subtree-has-long-lines' to only show the heading branches when
+   long lines are detected in its subtree (see
+   `outline-long-line-threshold' for the definition of long
+   lines).
+
+- `subtree-is-long' to only show the heading branches when its
+  subtree contains more than `outline-line-count-threshold'
+  lines.
+
+- A lambda function or function name which will be evaluated with
+  point at the beginningg of the heading and the match data set
+  appropriately, the function being expected to toggle the
+  heading visibility."
+  :version "29.1"
+  :type '(choice (const :tag "Hide subtree" nil)
+                 (set :tag "Show subtree unless"
+                      (cons :tag "Heading match regexp"
+                            (const match-regexp)  string)
+                      (const :tag "Body has long lines"
+                             subtree-has-long-lines)
+                      (const :tag "Body is long"
+                             subtree-is-long)
+                      (cons :tag "Custom function"
+                            (const custom-function) function))))
+
+(defcustom outline-long-line-threshold 1000
+  "Minimal number of characters in a line for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defcustom outline-line-count-threshold 50
+  "Minimal number of lines for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defun outline-apply-default-state ()
+  "Apply the outline state defined by `outline-default-state'."
+  (interactive)
+  (cond
+   ((integerp outline-default-state)
+    (outline--show-headings-up-to-level outline-default-state))
+   ((when (functionp outline-default-state)
+      (funcall outline-default-state)))))
+
+(defun outline-show-only-headings ()
+  "Show only headings."
+  (interactive)
+  (outline-show-all)
+  (outline-hide-region-body (point-min) (point-max)))
+
+(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)
+
+(defun outline--show-headings-up-to-level (level)
+  "Show only headings up to a LEVEL level and call FUN on the leaves.
+
+Like `outline-hide-sublevels' but but call
+`outline-default-state-subtree-visibility' for each heading at
+level equal to LEVEL."
+  (if (not outline-default-state-subtree-visibility)
+      (outline-hide-sublevels level)
+    (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))))
+             (heading-regexp
+              (cdr-safe
+               (assoc 'match-regexp
+                      outline-default-state-subtree-visibility)))
+             (check-line-count
+              (memq 'subtree-is-long
+                    outline-default-state-subtree-visibility))
+             (check-long-lines
+              (memq 'subtree-has-long-lines
+                    outline-default-state-subtree-visibility))
+             (custom-function
+              (cdr-safe
+               (assoc 'custom-function
+                      outline-default-state-subtree-visibility))))
+        (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 ()
+             (let ((current-level (outline-level)))
+	       (when (< current-level level)
+                 (outline-show-heading)
+                 (outline-show-entry))
+               (when (= current-level level)
+                 (cond
+                  ((and heading-regexp
+                        (let ((beg (point))
+                              (end (progn (outline-end-of-heading) (point))))
+                          (string-match-p heading-regexp (buffer-substring beg end))))
+                   ;; hide entry when heading match regexp
+                   (outline-hide-entry))
+                  ((and check-line-count
+                        (save-excursion
+                          (let* ((beg (point))
+                                 (end (progn (outline-end-of-subtree) (point)))
+                                 (line-count (count-lines beg end)))
+                            (< outline-line-count-threshold line-count))))
+                   ;; show only branches when line count of subtree >
+                   ;; threshold
+                   (outline-show-branches))
+                  ((and check-long-lines
+                        (save-excursion
+                          (let ((beg (point))
+                                (end (progn (outline-end-of-subtree) (point))))
+                            (save-restriction
+                              (narrow-to-region beg end)
+                              (let ((so-long-skip-leading-comments nil)
+                                    (so-long-threshold outline-long-line-threshold)
+                                    (so-long-max-lines nil))
+                                (so-long-detected-long-line-p))))))
+                   ;; show only branches when long lines are detected
+                   ;; in subtree
+                   (outline-show-branches))
+                  (custom-function
+                   ;; call custom function if defined
+                   (funcall custom-function))
+                  (t
+                   ;; if no previous clause succeeds, show subtree
+                   (outline-show-subtree))))))
+         beg end)))
+    (run-hooks 'outline-view-change-hook)))
+
 (defun outline--cycle-state ()
   "Return the cycle state of current heading.
 Return either 'hide-all, 'headings-only, or 'show-all."
-- 
2.30.2


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


Here is a file used to test this feature:


--=-=-=
Content-Type: text/plain
Content-Disposition: inline; filename=test.outline

# -*- mode: outline; -*-

Help to test implementation of outline default state.

* Heading 1

Preambule

** Heading with long lines 1.1

With looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line

** Heading 1.2

Some text

** Heading 1.3

A first paragraph followed by a second paragraph but with less
interesting text.

To be discussed.

** Heading with not so long line 1.4

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa	

* Heading 2

Preamble to a heading with many lines.

** Heading with many lines 2.1

Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines
Many lines

** Heading 2.2
Many lines
* Heading 3

Preamble

** Heading matching regex 3.1 TOHIDE

Hidden body

*** Heading 3.1.1

Body of hidden parent

**** Heading 3.1.1.1

*** Heading 3.1.2

Still in a hidden parent

* Heading 4

Last body
and nothing
else but those three lines

# Local Variables:
# outline-default-state: 2
# outline-default-state-subtree-visibility: ((match-regexp . "TOHIDE") subtree-has-long-lines subtree-is-long)
# outline-long-line-threshold: 200
# outline-line-count-threshold: 100
# End:

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


There's a bug when used with diff-mode (where `outline-level' returns
unexpected values), the starting point of that thread! I'll try to study
this in the forthcoming days.

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Eli Zaretskii <eliz@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 26 Dec 2021 16:22:02 +0000
Resent-Message-ID: <handler.51809.B51809.16405356978672 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org, juri@HIDDEN
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.16405356978672
          (code B ref 51809); Sun, 26 Dec 2021 16:22:02 +0000
Received: (at 51809) by debbugs.gnu.org; 26 Dec 2021 16:21:37 +0000
Received: from localhost ([127.0.0.1]:41369 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n1WHA-0002Fn-P5
	for submit <at> debbugs.gnu.org; Sun, 26 Dec 2021 11:21:37 -0500
Received: from eggs.gnu.org ([209.51.188.92]:33422)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1n1WH9-0002FY-G0
 for 51809 <at> debbugs.gnu.org; Sun, 26 Dec 2021 11:21:35 -0500
Received: from [2001:470:142:3::e] (port=57308 helo=fencepost.gnu.org)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1n1WH4-00059e-2Q; Sun, 26 Dec 2021 11:21:30 -0500
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=thFBSIxK+setVGIFc7B0Z/FeCaeaWCYL1SeGO7piPwY=; b=ptN7I9McvFem
 twpXnwsfqYbV0si7b3r75/6QgJUdbA4rGAquPZ17F7DzffVxzBX9EEUHVPqda/F5y27aa9IIpcuFv
 3Kb93RGUqST0WURZtEsESHjgolVc+qMToF+eyDo4nFe9x8qEDspxR7GYbxLIihsCF586Pujt+hlFz
 X4aRI8wpZyzhL/M6rZSIpneKayU77Sz7UqFMMgxteyecq+rHQhvVLnWanj+cpJXvdauWgVON+i7ae
 GSmbE8MOKjvnvdbpleFDka5T75UOishaNFryAzHjrkR2cdjobpcmFeCDnTPaTG36T4CVQlgXeTax3
 x1Po9iTsgY+H+rZAbvTXoQ==;
Received: from [87.69.77.57] (port=2897 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1n1WH2-0001JK-C4; Sun, 26 Dec 2021 11:21:30 -0500
Date: Sun, 26 Dec 2021 18:21:42 +0200
Message-Id: <83fsqfnxpl.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
In-Reply-To: <87r19zs662.fsf@HIDDEN> (message from Matthias Meulien on Sun, 
 26 Dec 2021 17:05:25 +0100)
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN>
X-Spam-Score: -2.3 (--)
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: -3.3 (---)

> From: Matthias Meulien <orontee@HIDDEN>
> Date: Sun, 26 Dec 2021 17:05:25 +0100
> Cc: 51809 <at> debbugs.gnu.org
> 
> Here is an updated patch implementing a default state for Outline mode
> and Outline minor mode:

Thanks, a few comments to the documentation parts:

> +If equal to a number, show only headings up to the corresponding
> +level.

"Up to and including" or "up to and excluding"?

Also, please make sure you leave 2 spaces between sentences in all the
doc strings and comments, per our conventions.

> +  :type '(choice (const :tag "Disabled" nil)

It isn't clear what exactly is "disabled" under this value.  The doc
string itself is also not clear about what happens when the value is
nil: "some headings are outlined" leaves me wondering what that means.
> +(defcustom outline-default-state-subtree-visibility nil
> +  "Defines visibility of subtree starting at level defined by `outline-default-state'.

Not "Defines", "Determines".

Also, the first line is too long.

> +When equal to a list, each element is expected to equal one of:
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
"...should be one of the following:"

(Using "equal" here is not appropriate in any case, since you don't
always describe actual values.)

> +- A lambda function or function name which will be evaluated with
> +  point at the beginningg of the heading and the match data set
                  ^^^^^^^^^^
A typo.

And finally, I think this should have a NEWS entry.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 26 Dec 2021 19:20:02 +0000
Resent-Message-ID: <handler.51809.B51809.164054636422624 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Eli Zaretskii <eliz@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org, juri@HIDDEN
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164054636422624
          (code B ref 51809); Sun, 26 Dec 2021 19:20:02 +0000
Received: (at 51809) by debbugs.gnu.org; 26 Dec 2021 19:19:24 +0000
Received: from localhost ([127.0.0.1]:41584 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n1Z3D-0005sq-FT
	for submit <at> debbugs.gnu.org; Sun, 26 Dec 2021 14:19:24 -0500
Received: from mail-wr1-f54.google.com ([209.85.221.54]:46022)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n1Z3B-0005sa-6C
 for 51809 <at> debbugs.gnu.org; Sun, 26 Dec 2021 14:19:22 -0500
Received: by mail-wr1-f54.google.com with SMTP id v7so28378362wrv.12
 for <51809 <at> debbugs.gnu.org>; Sun, 26 Dec 2021 11:19:21 -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=N80EcxkVP7MISBBsmo5gqNA5xFgUNQbL2vV+GG6ReXs=;
 b=WWDKpvwQxepd9IT8V1wFd3+m6uSityw3oU0URWxC7BaIuWdDCcYmyr8zrGe17Rk8gg
 0o2BYOw/pW8NiFDy3KxEh/uUqGrMqk1G6ouxflIk88YSHPD8n8jjJN/VBacJj805Mspa
 v2RtOyjyDHqK9t6PVwuG4nNa1YF2nKlIGsbV0BnIs5IBr3NzYbLnrrxADbl7zsubyCDh
 imB+ftSbxM7hDOjB+UiwpTRDN+l1ehdpOSTXJulnKV9D9Lnu6Nct5A1F3JoMG6HadMWu
 YpmWIDzuyfT7mGDtD14+r18+rFkH6GGTWw2ow9VCgOAsy3/bj3t6es2zGTImrpOXRSg/
 5G9w==
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=N80EcxkVP7MISBBsmo5gqNA5xFgUNQbL2vV+GG6ReXs=;
 b=unNJyiiHeBAQIVUPOGOxwJ7syAIvC3sZwAboOdArYUMn5mYOq3RdVl6dwPHRnO5Pyp
 4BtzO1HmA1SHNKf/WE02X59Y/LRkdYsQXlKup0/TPH8Mfyp9b733+qI0a1zZWiweXyau
 /88MYV55xhVYXs+EDZXaulzXy+Md0lEZgeVVuEk3LPG2kRBPughkv+/KXx+PUGEpEpZM
 JQtSomfn0BY++CbZYk3qgT6CWAZCxXFCm4qr4k96jCNBXLSwnHjHsR0CLgJlWgWKUWzj
 9gisChc2g5CEJnsmVRl8LprEYI3CinwFo+J8StyhdqORL+NToWbpbRHT0yXoHZgacIrU
 NOtQ==
X-Gm-Message-State: AOAM533VluwLfpYhyULKkfMlDaImd8vbFzV+qZekqvngoX9cUBnhl5RW
 vjfQkA5HhKQisOnVy0Gp8RWzIYRsVzY=
X-Google-Smtp-Source: ABdhPJyttfyCXI0CM0d8zOamx/UsPzHX8Nq6Nw8RhAxSRIim74Wf7efeoVB+ordgaT/S+4B9NyQIGA==
X-Received: by 2002:a5d:4c4a:: with SMTP id n10mr10855435wrt.100.1640546355319; 
 Sun, 26 Dec 2021 11:19:15 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id k33sm17387725wms.21.2021.12.26.11.19.14
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 26 Dec 2021 11:19:14 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <83fsqfnxpl.fsf@HIDDEN>
Date: Sun, 26 Dec 2021 20:19:13 +0100
In-Reply-To: <83fsqfnxpl.fsf@HIDDEN> (Eli Zaretskii's message of "Sun, 26 Dec
 2021 18:21:42 +0200")
Message-ID: <87fsqfmaxa.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-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

Eli Zaretskii <eliz@HIDDEN> writes:

> (...) a few comments to the documentation parts:

Here is an updated patch taking your remarks into account:


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Extend-Outline-mode-with-default-visibility-state.patch

From ecf57d0fb33ba3d569ca8fb2933993e139bbf94e Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Wed, 8 Dec 2021 22:35:42 +0100
Subject: [PATCH] Extend Outline mode with default visibility state

* etc/NEWS: Announce support for default visibility state.

* lisp/outline.el (outline-mode, outline-minor-mode): Ensure default
visibility state is applied.
(outline-hide-sublevels): Add optional argument for function to call
on each heading.
(outline-default-state): Define the default visibility state.
(outline-apply-default-state): Apply default visibility state.
---
 etc/NEWS        |  10 +++
 lisp/outline.el | 190 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 197 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index cfea513cca..9a49ff8379 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -215,6 +215,16 @@ These will take you (respectively) to the next and previous "page".
 ---
 *** 'describe-char' now also outputs the name of emoji combinations.
 
+** Outline Mode
+
+*** Support for a default visibility state.
+Customize the option 'outline-default-state' to define what headings
+are visible when the mode is set.  When equal to a number, the option
+'outline-default-state-subtree-visibility' determines the visibility
+of the subtree starting at the corresponding level.  Values are
+provided to show a heading subtree unless the heading match a regexp,
+or its subtree has long lines or is long.
+
 ** Outline Minor Mode
 
 +++
diff --git a/lisp/outline.el b/lisp/outline.el
index 5e3d4e0e00..ad45e38946 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -354,7 +354,9 @@ outline-mode
               '(outline-font-lock-keywords t nil nil backward-paragraph))
   (setq-local imenu-generic-expression
 	      (list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
-  (add-hook 'change-major-mode-hook #'outline-show-all nil t))
+  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
+  (add-hook 'hack-local-variables-hook
+	    #'outline-apply-default-state))
 
 (defvar outline-minor-mode-map)
 
@@ -437,7 +439,9 @@ outline-minor-mode
 		  nil t)
         (setq-local line-move-ignore-invisible t)
 	;; Cause use of ellipses for invisible text.
-	(add-to-invisibility-spec '(outline . t)))
+	(add-to-invisibility-spec '(outline . t))
+        (add-hook 'hack-local-variables-hook
+	          #'outline-apply-default-state))
     (when (or outline-minor-mode-cycle outline-minor-mode-highlight)
       (if font-lock-fontified
           (font-lock-remove-keywords nil outline-font-lock-keywords))
@@ -1094,7 +1098,7 @@ outline-hide-sublevels
       (outline-map-region
        (lambda ()
 	 (if (<= (funcall outline-level) levels)
-	     (outline-show-heading)))
+             (outline-show-heading)))
        beg end)
       ;; Finally unhide any trailing newline.
       (goto-char (point-max))
@@ -1308,6 +1312,186 @@ outline-headers-as-kill
                     (insert "\n\n"))))))
           (kill-new (buffer-string)))))))
 
+(defcustom outline-default-state nil
+  "If non-nil, some headings are initially outlined.
+
+Note that the default state is applied when the major mode is set
+or when the command `outline-apply-default-state' is called
+interactively.
+
+When nil, headings visibility is left unchanged.
+
+If equal to `outline-show-all', all text of buffer is shown.
+
+If equal to `outline-show-only-headings', only headings are shown.
+
+If equal to a number, show only headings up to and including the
+corresponding level.  See
+`outline-default-state-subtree-visibility' to customize
+visibility of the subtree at the choosen level.
+
+If equal to a lambda function or function name, this function is
+expected to toggle headings visibility, and will be called after
+the mode is enabled."
+  :version "29.1"
+  :type '(choice (const :tag "Disabled" nil)
+                 (const :tag "Show all" outline-show-all)
+                 (const :tag "Only headings" outline-show-only-headings)
+                 (natnum :tag "Show headings up to level" :value 1)
+                 (function :tag "Custom function")))
+
+(defcustom outline-default-state-subtree-visibility nil
+  "Determines visibility of subtree starting at `outline-default-state' level.
+
+When nil, the subtree is hidden unconditionally.
+
+When equal to a list, each element should be one of the following:
+
+- A cons cell with CAR `match-regexp' and CDR a regexp, the
+  subtree will be hidden when the outline heading match the
+  regexp.
+
+- `subtree-has-long-lines' to only show the heading branches when
+   long lines are detected in its subtree (see
+   `outline-long-line-threshold' for the definition of long
+   lines).
+
+- `subtree-is-long' to only show the heading branches when its
+  subtree contains more than `outline-line-count-threshold'
+  lines.
+
+- A lambda function or function name which will be evaluated with
+  point at the beginning of the heading and the match data set
+  appropriately, the function being expected to toggle the
+  heading visibility."
+  :version "29.1"
+  :type '(choice (const :tag "Hide subtree" nil)
+                 (set :tag "Show subtree unless"
+                      (cons :tag "Heading match regexp"
+                            (const match-regexp)  string)
+                      (const :tag "Subtree has long lines"
+                             subtree-has-long-lines)
+                      (const :tag "Subtree is long"
+                             subtree-is-long)
+                      (cons :tag "Custom function"
+                            (const custom-function) function))))
+
+(defcustom outline-long-line-threshold 1000
+  "Minimal number of characters in a line for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defcustom outline-line-count-threshold 50
+  "Minimal number of lines for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defun outline-apply-default-state ()
+  "Apply the outline state defined by `outline-default-state'."
+  (interactive)
+  (cond
+   ((integerp outline-default-state)
+    (outline--show-headings-up-to-level outline-default-state))
+   ((when (functionp outline-default-state)
+      (funcall outline-default-state)))))
+
+(defun outline-show-only-headings ()
+  "Show only headings."
+  (interactive)
+  (outline-show-all)
+  (outline-hide-region-body (point-min) (point-max)))
+
+(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)
+
+(defun outline--show-headings-up-to-level (level)
+  "Show only headings up to a LEVEL level and call FUN on the leaves.
+
+Like `outline-hide-sublevels' but but call
+`outline-default-state-subtree-visibility' for each heading at
+level equal to LEVEL."
+  (if (not outline-default-state-subtree-visibility)
+      (outline-hide-sublevels level)
+    (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))))
+             (heading-regexp
+              (cdr-safe
+               (assoc 'match-regexp
+                      outline-default-state-subtree-visibility)))
+             (check-line-count
+              (memq 'subtree-is-long
+                    outline-default-state-subtree-visibility))
+             (check-long-lines
+              (memq 'subtree-has-long-lines
+                    outline-default-state-subtree-visibility))
+             (custom-function
+              (cdr-safe
+               (assoc 'custom-function
+                      outline-default-state-subtree-visibility))))
+        (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 ()
+             (let ((current-level (outline-level)))
+	       (when (< current-level level)
+                 (outline-show-heading)
+                 (outline-show-entry))
+               (when (= current-level level)
+                 (cond
+                  ((and heading-regexp
+                        (let ((beg (point))
+                              (end (progn (outline-end-of-heading) (point))))
+                          (string-match-p heading-regexp (buffer-substring beg end))))
+                   ;; hide entry when heading match regexp
+                   (outline-hide-entry))
+                  ((and check-line-count
+                        (save-excursion
+                          (let* ((beg (point))
+                                 (end (progn (outline-end-of-subtree) (point)))
+                                 (line-count (count-lines beg end)))
+                            (< outline-line-count-threshold line-count))))
+                   ;; show only branches when line count of subtree >
+                   ;; threshold
+                   (outline-show-branches))
+                  ((and check-long-lines
+                        (save-excursion
+                          (let ((beg (point))
+                                (end (progn (outline-end-of-subtree) (point))))
+                            (save-restriction
+                              (narrow-to-region beg end)
+                              (let ((so-long-skip-leading-comments nil)
+                                    (so-long-threshold outline-long-line-threshold)
+                                    (so-long-max-lines nil))
+                                (so-long-detected-long-line-p))))))
+                   ;; show only branches when long lines are detected
+                   ;; in subtree
+                   (outline-show-branches))
+                  (custom-function
+                   ;; call custom function if defined
+                   (funcall custom-function))
+                  (t
+                   ;; if no previous clause succeeds, show subtree
+                   (outline-show-subtree))))))
+         beg end)))
+    (run-hooks 'outline-view-change-hook)))
+
 (defun outline--cycle-state ()
   "Return the cycle state of current heading.
 Return either 'hide-all, 'headings-only, or 'show-all."
-- 
2.30.2


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



-- 
Matthias

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 26 Dec 2021 20:33:01 +0000
Resent-Message-ID: <handler.51809.B51809.164055074630728 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164055074630728
          (code B ref 51809); Sun, 26 Dec 2021 20:33:01 +0000
Received: (at 51809) by debbugs.gnu.org; 26 Dec 2021 20:32:26 +0000
Received: from localhost ([127.0.0.1]:41636 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n1aBu-0007zY-FX
	for submit <at> debbugs.gnu.org; Sun, 26 Dec 2021 15:32:26 -0500
Received: from mail-wm1-f53.google.com ([209.85.128.53]:52808)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n1aBs-0007zI-Mv
 for 51809 <at> debbugs.gnu.org; Sun, 26 Dec 2021 15:32:25 -0500
Received: by mail-wm1-f53.google.com with SMTP id g132so8601453wmg.2
 for <51809 <at> debbugs.gnu.org>; Sun, 26 Dec 2021 12:32: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=ENI60ZEOrnZ79lbOnhvmmDZpTo9n7kRjQUDQaZRDZuY=;
 b=BbFQU59/rA42LcLQ/P73o96JmgoDkZP9ozWoZVXxa0yD4BwJE5IEQxGiOtPnpizg5S
 TM83Je+xSZCGuSIUKqaBYkebiA+hARylPRwH3KJdyrP3bV5BFqvrlLcG+NIhHZ2vXqpX
 59d1ob3GSIjJ8W6k1ZAhfvHrGLOCPCufWFCKTvT3f2ZvPorgu+jCF8dLr7K+N5Hiy9Fr
 yR4x1Y90t33o9zXDBn84CVucy5syb2Dm1bBNqDOLQ3SgzAUnZx3YPd5PdTOEE6T6GFqR
 jDrV6vLaQMNuFHY8yBGpjg3/cLOIVFpWqJcMg83yyCeP56Kjp9Az/4qseMHgt4m6ATP8
 ySaQ==
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=ENI60ZEOrnZ79lbOnhvmmDZpTo9n7kRjQUDQaZRDZuY=;
 b=RuAQjqXl02hx/B0uovLwfBwHrE6JDrgcfFKWZXU5hu19MCi4dDkerI2IGHXewVet8G
 v55gb/DhERQctg+vZsApttS08Xpmi5xB3FuGOKgk5rUxzPZ3QK1leniuLWtdenI51ZLp
 y3oqTA3dKC6mQZ4Bf719ILtdfbeWs9//eveuWVY7tMHBqbqZmYqT4+qsk2WGJr2tvm75
 ioGnuzsq1CS4cSz0Oi1hki1Kk6lUSoJzLkMF3ipiSXdpTRLbfwKNuN/Kw3RKnPUHEuxk
 4lUjJVWGbil8tXLyWsHHdcA6v3aK9eUN1AFH2JdkLQC7c2SftZ9aVwVXzN+BpOj8N3nz
 yfZw==
X-Gm-Message-State: AOAM530DfOprDnDG2//uRR01VqTWDASQOSrwm+o41IFKBQ4HakAjfUgh
 MVvRLbnFI1QJDwwKM2kPx5+TvRpvt4g=
X-Google-Smtp-Source: ABdhPJxlNJiyUPMB7ApFhou7S91tpEPtPkGj10PuCEOsNCMZIu798ra8uThUHP+mYoig2xcj9e5j/A==
X-Received: by 2002:a05:600c:4f08:: with SMTP id
 l8mr11294375wmq.59.1640550738441; 
 Sun, 26 Dec 2021 12:32:18 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id b10sm13731371wrg.19.2021.12.26.12.32.17
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 26 Dec 2021 12:32:18 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN>
Date: Sun, 26 Dec 2021 21:32:17 +0100
In-Reply-To: <87r19zs662.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 26 Dec 2021 17:05:25 +0100")
Message-ID: <871r1zm7ji.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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 (-)

Matthias Meulien <orontee@HIDDEN> writes:

> There's a bug when used with diff-mode (where `outline-level' returns
> unexpected values), the starting point of that thread! I'll try to
> study this in the forthcoming days.

Fixed with (applied to the patch sent in reply to Eli's suggestions on
documentation):

diff --git a/lisp/outline.el b/lisp/outline.el
index ad45e38946..2dc9805b85 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1449,7 +1449,7 @@ outline--show-headings-up-to-level
         ;; Then unhide the top level headers.
         (outline-map-region
          (lambda ()
-             (let ((current-level (outline-level)))
+             (let ((current-level (funcall outline-level)))
 	       (when (< current-level level)
                  (outline-show-heading)
                  (outline-show-entry))


I am now back to the origin of this bug report (toggling visibility of
some diff hunks depending on long lines, chunks size, or file names) and
I see there's a major drawback with the outline mode default visibility
state approach: When outline minor mode is set through diff-mode-hook,
the buffer is emtpy and applying the default state visibility is a
no-op; It's a side-effect of the buffer content being generated
asynchronously...




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 26 Dec 2021 20:56:01 +0000
Resent-Message-ID: <handler.51809.B51809.1640552139937 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.1640552139937
          (code B ref 51809); Sun, 26 Dec 2021 20:56:01 +0000
Received: (at 51809) by debbugs.gnu.org; 26 Dec 2021 20:55:39 +0000
Received: from localhost ([127.0.0.1]:41697 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n1aYM-0000F2-U5
	for submit <at> debbugs.gnu.org; Sun, 26 Dec 2021 15:55:39 -0500
Received: from mail-wr1-f41.google.com ([209.85.221.41]:34316)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n1aYL-0000Ed-7n
 for 51809 <at> debbugs.gnu.org; Sun, 26 Dec 2021 15:55:37 -0500
Received: by mail-wr1-f41.google.com with SMTP id s1so28833308wrg.1
 for <51809 <at> debbugs.gnu.org>; Sun, 26 Dec 2021 12:55:37 -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=uyPAa1ThAg+97ewM6vtuowBMaz4klm8UEufT4FiH/gY=;
 b=OJULhCac+gra/QKkOPYlkhApt0qIo21vsBXEF6U4mOSaPc64goBQ9yDLX2xm1nqlTl
 BPlQV5K06ATbGYS6OP2zHv/CEJoAxp/Awu8Ukrbo+EE893iNXnlLpNwqFxr2pfFQQnln
 SZAz9yIdIlkCQ1RH4YbBHvBhzU6WUg+Q68E+R7br0oUBFXzeQVmlhm+/BTrOGbId6QJg
 WnxKgnMGrYiDx+zd5Cxd2dtBTmp1N2ZIXrXXUPdEj+KjuB5pJ3O5jQOE7LMjqGib0vMF
 TSESCq2cn2TuAqBUZ1SSw5+vND73E5PcQEe7m/vjL8nUq7AEyMaFYsGq/CsBeCyzAB42
 bkWw==
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=uyPAa1ThAg+97ewM6vtuowBMaz4klm8UEufT4FiH/gY=;
 b=zOJ6BgUPnNckrVL59c5HPTDetbevNhba8FRwSIzEMTxozhzuovSSIpg9dhQZ4mWAnt
 lLQGfu6rtG43SFf+UXJEs7LpOrb8E2QqZqj9bA74vdc7SikAfu4ECVlYHySn5YUEQQMZ
 WH4ocqH1dyxJVfv9xtn5JpIMDmQD5g11+4CVUhdQmBoxc2EbbwoQxWzQEeW06YgTVMVe
 G+kh5lgbQUPbvDjvPCtGhCKvzv9se8Z7icuIpnp1A0KuoedUEysbwGK9qetSDFBzaQMp
 8vJi67K3YstOXBSZoKS00T9pmByoeh3dtnQHHsb2ezPZrLi2wevLSpF6tQ5ctOAxCF6y
 PsGg==
X-Gm-Message-State: AOAM531PdOxW/Ic12c+jkhdDAbLg6mYGR+BtYefaxZVcU593oHwBNnpA
 jVkqDfy80pVOhCjg2Bih1CB1iFOm5aE=
X-Google-Smtp-Source: ABdhPJwR2klHc/PfQvzAHj7Y2fVJTw9AA3i1jQy785tkH/tI2QDhZAn/Gz1O67p6hqqfIR+3eVfUVQ==
X-Received: by 2002:a5d:61cf:: with SMTP id q15mr10363426wrv.623.1640552131362; 
 Sun, 26 Dec 2021 12:55:31 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id g18sm12355479wmq.5.2021.12.26.12.55.30
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 26 Dec 2021 12:55:30 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
Date: Sun, 26 Dec 2021 21:55:30 +0100
In-Reply-To: <871r1zm7ji.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 26 Dec 2021 21:32:17 +0100")
Message-ID: <87wnjrkrwd.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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 (-)

Matthias Meulien <orontee@HIDDEN> writes:

> I am now back to the origin of this bug report (toggling visibility of
> some diff hunks depending on long lines, chunks size, or file names) and
> I see there's a major drawback with the outline mode default visibility
> state approach: When outline minor mode is set through diff-mode-hook,
> the buffer is emtpy and applying the default state visibility is a
> no-op; It's a side-effect of the buffer content being generated
> asynchronously...

I fixed it using an advice to `vc-diff-finish', but wondering whether
there's a clean way to achieve the same...

For posterity, here is a sample configuration for *vc-diff* buffers to
hide hunks with long lines, long hunks or matching some regexp.

(add-hook 'diff-mode-hook #'(lambda ()
			      (setq diff-font-lock-prettify t
				    outline-default-state 1
				    outline-default-state-subtree-visibility
				    '(subtree-is-long
				      subtree-has-long-lines
				      (match-regexp . "NEWS\\|test")))
			      (outline-minor-mode)))

(defadvice vc-diff-finish (after ensure-outline-apply-default-state activate)
  (when outline-minor-mode
    (outline-apply-default-state)))




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 27 Dec 2021 19:54:02 +0000
Resent-Message-ID: <handler.51809.B51809.164063482526702 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164063482526702
          (code B ref 51809); Mon, 27 Dec 2021 19:54:02 +0000
Received: (at 51809) by debbugs.gnu.org; 27 Dec 2021 19:53:45 +0000
Received: from localhost ([127.0.0.1]:44333 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n1w41-0006wb-19
	for submit <at> debbugs.gnu.org; Mon, 27 Dec 2021 14:53:45 -0500
Received: from relay4-d.mail.gandi.net ([217.70.183.196]:34965)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n1w3y-0006wG-Nk
 for 51809 <at> debbugs.gnu.org; Mon, 27 Dec 2021 14:53:43 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 6B891E0006;
 Mon, 27 Dec 2021 19:53:34 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN>
Date: Mon, 27 Dec 2021 21:52:13 +0200
In-Reply-To: <87wnjrkrwd.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 26 Dec 2021 21:55:30 +0100")
Message-ID: <86tuethlle.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-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 am now back to the origin of this bug report (toggling visibility of
>> some diff hunks depending on long lines, chunks size, or file names) and
>> I see there's a major drawback with the outline mode default visibility
>> state approach: When outline minor mode is set through diff-mode-hook,
>> the buffer is emtpy and applying the default state visibility is a
>> no-op; It's a side-effect of the buffer content being generated
>> asynchronously...
>
> I fixed it using an advice to `vc-diff-finish',

This problem is not specific to diff-mode.  Like I demonstrated
earlier, xref requires using xref-after-update-hook,
so now it could look like this:

#+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-default-state 1)
            (outline-minor-mode)
            (outline-apply-default-state)))
#+end_src

> but wondering whether there's a clean way to achieve the same...

Some time ago in another bug report I proposed to add a hook
at the end of 'vc-diff-finish', so it will solve this problem.

PS: Please give me more time to test your patch thoroughly
in various modes.




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Dec 2021 08:10:01 +0000
Resent-Message-ID: <handler.51809.B51809.16406789552618 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.16406789552618
          (code B ref 51809); Tue, 28 Dec 2021 08:10:01 +0000
Received: (at 51809) by debbugs.gnu.org; 28 Dec 2021 08:09:15 +0000
Received: from localhost ([127.0.0.1]:44964 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n27Xm-0000gA-Pd
	for submit <at> debbugs.gnu.org; Tue, 28 Dec 2021 03:09:15 -0500
Received: from mail-wr1-f44.google.com ([209.85.221.44]:37482)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n27Xk-0000fw-80
 for 51809 <at> debbugs.gnu.org; Tue, 28 Dec 2021 03:09:13 -0500
Received: by mail-wr1-f44.google.com with SMTP id t26so36803010wrb.4
 for <51809 <at> debbugs.gnu.org>; Tue, 28 Dec 2021 00:09:12 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=from:to:subject:references:date:in-reply-to:message-id:user-agent
 :mime-version; bh=gdt6N3+zRhZ42h11PUS4NmiiS6xuRUT8GPIIA4/GoQE=;
 b=D9ZjlWSZH7DQtulQUEg2/eoCYfPtkOtp1ZRiBtndl4lGnuH8m+K2r6KRVBIU0LcwkK
 VFmt4OhEkGPnTV1+Qbavm86s9+xykYkUoyNFvcIaYwylncR6UNOpFCV50JiBnpE8lgDH
 EaVr1xWG4Y2igRmBRHzAd/hrcpWeOuKNp0WlInGZNnzcZ0+ax9t/PQmOuYCRPjVBgqQl
 VGluPTHbh3IMZXZ+LdPvRdrSXQe2zD12WCJtB3LUtQnZPnPyE/cKgflIh/pCJPjim88Q
 iHOOzLhOOho5oVtLoSfhGh8whP65IyQnitug8cc+xlLDKSLXBrm/AESqxyvrP7w1KGdW
 wfoQ==
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:references:date:in-reply-to
 :message-id:user-agent:mime-version;
 bh=gdt6N3+zRhZ42h11PUS4NmiiS6xuRUT8GPIIA4/GoQE=;
 b=uWPB3CMi9WK98kQr+KyuTDLZhs3tlbO5ipEeCrpEKdq12t8Whu/sQai29KfMur/uzt
 qJOxc59T9FxEa6XNTTHnb0jXNP8pl6rkPlKVG8JN91DmDECw9rsPboNZhteiiF8kJenJ
 TJVOi7lJPLn2Il9uMIDHoEoCtFXI+UKJoZVrUDLzTv3JT6ejptb38i9HkecHV6aCY3vT
 jy5YVHkjqUw7H10frklAi5PPRK1fyYRh4JxxVYEtZXuww1mVCBoeLoc69t2y0xXTzVvi
 HOzQ5gpQfatEQ6JtxXyRrSiP27GxhGRROD/9kvcZkwSx7bNfD8EpIFs/+ocXIFg1zcxa
 a3CA==
X-Gm-Message-State: AOAM532tcQL3SygksmM1uknZm9ebu+F1fyU1FLiY5x5bTBeXS9lbXj9V
 c1puR9Vzys/X/HOwQvBRpxmUJuvabao=
X-Google-Smtp-Source: ABdhPJx8b0RBunf0dUKB/2zWcABvxstdLkOAHb8KfDn2qiCkfSUKMiii/yMXJbT42yb4naM2qb/1Lw==
X-Received: by 2002:a5d:610c:: with SMTP id v12mr15262669wrt.410.1640678946371; 
 Tue, 28 Dec 2021 00:09:06 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:57c9:ca7e:b934:d778])
 by smtp.gmail.com with ESMTPSA id c2sm19037681wri.50.2021.12.28.00.09.05
 for <51809 <at> debbugs.gnu.org>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 28 Dec 2021 00:09:05 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN>
Date: Tue, 28 Dec 2021 09:09:04 +0100
In-Reply-To: <87lf1sw6ji.fsf@HIDDEN> (Matthias Meulien's message of "Sat,
 13 Nov 2021 14:04:33 +0100")
Message-ID: <877dbpw3q7.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-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 with docstring fix.


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Extend-Outline-mode-with-default-visibility-state.patch

From 167e7f9d8d26b075e01c3a8c8618da3a2138d145 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Wed, 8 Dec 2021 22:35:42 +0100
Subject: [PATCH] Extend Outline mode with default visibility state

* etc/NEWS: Announce support for default visibility state.

* lisp/outline.el (outline-mode, outline-minor-mode): Ensure default
visibility state is applied.
(outline-hide-sublevels): Add optional argument for function to call
on each heading.
(outline-default-state): Define the default visibility state.
(outline-apply-default-state): Apply default visibility state.
---
 etc/NEWS        |  10 +++
 lisp/outline.el | 190 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 197 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index cfea513cca..9a49ff8379 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -215,6 +215,16 @@ These will take you (respectively) to the next and previous "page".
 ---
 *** 'describe-char' now also outputs the name of emoji combinations.
 
+** Outline Mode
+
+*** Support for a default visibility state.
+Customize the option 'outline-default-state' to define what headings
+are visible when the mode is set.  When equal to a number, the option
+'outline-default-state-subtree-visibility' determines the visibility
+of the subtree starting at the corresponding level.  Values are
+provided to show a heading subtree unless the heading match a regexp,
+or its subtree has long lines or is long.
+
 ** Outline Minor Mode
 
 +++
diff --git a/lisp/outline.el b/lisp/outline.el
index 5e3d4e0e00..abb0d93adf 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -354,7 +354,9 @@ outline-mode
               '(outline-font-lock-keywords t nil nil backward-paragraph))
   (setq-local imenu-generic-expression
 	      (list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
-  (add-hook 'change-major-mode-hook #'outline-show-all nil t))
+  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
+  (add-hook 'hack-local-variables-hook
+	    #'outline-apply-default-state))
 
 (defvar outline-minor-mode-map)
 
@@ -437,7 +439,9 @@ outline-minor-mode
 		  nil t)
         (setq-local line-move-ignore-invisible t)
 	;; Cause use of ellipses for invisible text.
-	(add-to-invisibility-spec '(outline . t)))
+	(add-to-invisibility-spec '(outline . t))
+        (add-hook 'hack-local-variables-hook
+	          #'outline-apply-default-state))
     (when (or outline-minor-mode-cycle outline-minor-mode-highlight)
       (if font-lock-fontified
           (font-lock-remove-keywords nil outline-font-lock-keywords))
@@ -1094,7 +1098,7 @@ outline-hide-sublevels
       (outline-map-region
        (lambda ()
 	 (if (<= (funcall outline-level) levels)
-	     (outline-show-heading)))
+             (outline-show-heading)))
        beg end)
       ;; Finally unhide any trailing newline.
       (goto-char (point-max))
@@ -1308,6 +1312,186 @@ outline-headers-as-kill
                     (insert "\n\n"))))))
           (kill-new (buffer-string)))))))
 
+(defcustom outline-default-state nil
+  "If non-nil, some headings are initially outlined.
+
+Note that the default state is applied when the major mode is set
+or when the command `outline-apply-default-state' is called
+interactively.
+
+When nil, headings visibility is left unchanged.
+
+If equal to `outline-show-all', all text of buffer is shown.
+
+If equal to `outline-show-only-headings', only headings are shown.
+
+If equal to a number, show only headings up to and including the
+corresponding level.  See
+`outline-default-state-subtree-visibility' to customize
+visibility of the subtree at the choosen level.
+
+If equal to a lambda function or function name, this function is
+expected to toggle headings visibility, and will be called after
+the mode is enabled."
+  :version "29.1"
+  :type '(choice (const :tag "Disabled" nil)
+                 (const :tag "Show all" outline-show-all)
+                 (const :tag "Only headings" outline-show-only-headings)
+                 (natnum :tag "Show headings up to level" :value 1)
+                 (function :tag "Custom function")))
+
+(defcustom outline-default-state-subtree-visibility nil
+  "Determines visibility of subtree starting at `outline-default-state' level.
+
+When nil, the subtree is hidden unconditionally.
+
+When equal to a list, each element should be one of the following:
+
+- A cons cell with CAR `match-regexp' and CDR a regexp, the
+  subtree will be hidden when the outline heading match the
+  regexp.
+
+- `subtree-has-long-lines' to only show the heading branches when
+   long lines are detected in its subtree (see
+   `outline-long-line-threshold' for the definition of long
+   lines).
+
+- `subtree-is-long' to only show the heading branches when its
+  subtree contains more than `outline-line-count-threshold'
+  lines.
+
+- A lambda function or function name which will be evaluated with
+  point at the beginning of the heading and the match data set
+  appropriately, the function being expected to toggle the
+  heading visibility."
+  :version "29.1"
+  :type '(choice (const :tag "Hide subtree" nil)
+                 (set :tag "Show subtree unless"
+                      (cons :tag "Heading match regexp"
+                            (const match-regexp)  string)
+                      (const :tag "Subtree has long lines"
+                             subtree-has-long-lines)
+                      (const :tag "Subtree is long"
+                             subtree-is-long)
+                      (cons :tag "Custom function"
+                            (const custom-function) function))))
+
+(defcustom outline-long-line-threshold 1000
+  "Minimal number of characters in a line for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defcustom outline-line-count-threshold 50
+  "Minimal number of lines for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defun outline-apply-default-state ()
+  "Apply the outline state defined by `outline-default-state'."
+  (interactive)
+  (cond
+   ((integerp outline-default-state)
+    (outline--show-headings-up-to-level outline-default-state))
+   ((when (functionp outline-default-state)
+      (funcall outline-default-state)))))
+
+(defun outline-show-only-headings ()
+  "Show only headings."
+  (interactive)
+  (outline-show-all)
+  (outline-hide-region-body (point-min) (point-max)))
+
+(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)
+
+(defun outline--show-headings-up-to-level (level)
+  "Show only headings up to a LEVEL level.
+
+Like `outline-hide-sublevels' but, for each heading at level
+LEVEL, decides of subtree visibility according to
+`outline-default-state-subtree-visibility'."
+  (if (not outline-default-state-subtree-visibility)
+      (outline-hide-sublevels level)
+    (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))))
+             (heading-regexp
+              (cdr-safe
+               (assoc 'match-regexp
+                      outline-default-state-subtree-visibility)))
+             (check-line-count
+              (memq 'subtree-is-long
+                    outline-default-state-subtree-visibility))
+             (check-long-lines
+              (memq 'subtree-has-long-lines
+                    outline-default-state-subtree-visibility))
+             (custom-function
+              (cdr-safe
+               (assoc 'custom-function
+                      outline-default-state-subtree-visibility))))
+        (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 ()
+             (let ((current-level (funcall outline-level)))
+	       (when (< current-level level)
+                 (outline-show-heading)
+                 (outline-show-entry))
+               (when (= current-level level)
+                 (cond
+                  ((and heading-regexp
+                        (let ((beg (point))
+                              (end (progn (outline-end-of-heading) (point))))
+                          (string-match-p heading-regexp (buffer-substring beg end))))
+                   ;; hide entry when heading match regexp
+                   (outline-hide-entry))
+                  ((and check-line-count
+                        (save-excursion
+                          (let* ((beg (point))
+                                 (end (progn (outline-end-of-subtree) (point)))
+                                 (line-count (count-lines beg end)))
+                            (< outline-line-count-threshold line-count))))
+                   ;; show only branches when line count of subtree >
+                   ;; threshold
+                   (outline-show-branches))
+                  ((and check-long-lines
+                        (save-excursion
+                          (let ((beg (point))
+                                (end (progn (outline-end-of-subtree) (point))))
+                            (save-restriction
+                              (narrow-to-region beg end)
+                              (let ((so-long-skip-leading-comments nil)
+                                    (so-long-threshold outline-long-line-threshold)
+                                    (so-long-max-lines nil))
+                                (so-long-detected-long-line-p))))))
+                   ;; show only branches when long lines are detected
+                   ;; in subtree
+                   (outline-show-branches))
+                  (custom-function
+                   ;; call custom function if defined
+                   (funcall custom-function))
+                  (t
+                   ;; if no previous clause succeeds, show subtree
+                   (outline-show-subtree))))))
+         beg end)))
+    (run-hooks 'outline-view-change-hook)))
+
 (defun outline--cycle-state ()
   "Return the cycle state of current heading.
 Return either 'hide-all, 'headings-only, or 'show-all."
-- 
2.30.2


--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Dec 2021 19:04:02 +0000
Resent-Message-ID: <handler.51809.B51809.164071820731390 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164071820731390
          (code B ref 51809); Tue, 28 Dec 2021 19:04:02 +0000
Received: (at 51809) by debbugs.gnu.org; 28 Dec 2021 19:03:27 +0000
Received: from localhost ([127.0.0.1]:47407 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n2Hks-0008AD-Qm
	for submit <at> debbugs.gnu.org; Tue, 28 Dec 2021 14:03:27 -0500
Received: from relay4-d.mail.gandi.net ([217.70.183.196]:38999)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n2Hkq-00089y-P5
 for 51809 <at> debbugs.gnu.org; Tue, 28 Dec 2021 14:03:25 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 8C217E0008;
 Tue, 28 Dec 2021 19:03:17 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
In-Reply-To: <87r19zs662.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 26 Dec 2021 17:05:25 +0100")
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)
Date: Tue, 28 Dec 2021 20:32:22 +0200
Message-ID: <86zgokpoll.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
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 (-)

> @@ -353,7 +353,9 @@ outline-mode
> +  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
> +  (add-hook 'hack-local-variables-hook
> +	    #'outline-apply-default-state))
>
> @@ -436,7 +438,9 @@ outline-minor-mode
> +        (add-hook 'hack-local-variables-hook
> +	          #'outline-apply-default-state))

Are you sure about modifying the global value of hack-local-variables-hook
instead of the buffer-local hook with `nil t' at the end?

> Here is a file used to test this feature:
>
> # -*- mode: outline; -*-
> [...]
> # LocalVariables:
> # outline-default-state: 2
> # outline-default-state-subtree-visibility: ((match-regexp . "TOHIDE") subtree-has-long-lines subtree-is-long)
> # outline-long-line-threshold: 200
> # outline-line-count-threshold: 100
> # End:

When this feature will be used a lot, even variable names will affect
usability - with longer names usability deteriorates, and 40 characters of
'outline-default-state-subtree-visibility' takes half of the standard window width.
Would it be possible to find a shorter name?

Since it defines the rules, how about 'outline-default-rules'?
It has the same length as 'outline-default-state', so these names
will align nicely:

# LocalVariables:
# outline-default-state: 1
# outline-default-rules: ((match-regexp . "ChangeLog"))
# mode: outline-minor
# End:

Also outline-long-line-threshold and outline-line-count-threshold could share
the same prefix, maybe:

# outline-default-long-line: 200
# outline-default-line-count: 100




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Dec 2021 19:04:02 +0000
Resent-Message-ID: <handler.51809.B51809.164071821431408 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164071821431408
          (code B ref 51809); Tue, 28 Dec 2021 19:04:02 +0000
Received: (at 51809) by debbugs.gnu.org; 28 Dec 2021 19:03:34 +0000
Received: from localhost ([127.0.0.1]:47410 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n2Hl0-0008AW-1P
	for submit <at> debbugs.gnu.org; Tue, 28 Dec 2021 14:03:34 -0500
Received: from relay10.mail.gandi.net ([217.70.178.230]:60669)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n2Hku-0008A2-A2
 for 51809 <at> debbugs.gnu.org; Tue, 28 Dec 2021 14:03:28 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay10.mail.gandi.net (Postfix) with ESMTPSA id 26AE8240008;
 Tue, 28 Dec 2021 19:03:20 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN>
Date: Tue, 28 Dec 2021 20:37:52 +0200
In-Reply-To: <87wnjrkrwd.fsf@HIDDEN> (Matthias Meulien's message of "Sun,
 26 Dec 2021 21:55:30 +0100")
Message-ID: <86ilv8pnf3.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-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 am now back to the origin of this bug report (toggling visibility of
>> some diff hunks depending on long lines, chunks size, or file names) and
>> I see there's a major drawback with the outline mode default visibility
>> state approach: When outline minor mode is set through diff-mode-hook,
>> the buffer is emtpy and applying the default state visibility is a
>> no-op; It's a side-effect of the buffer content being generated
>> asynchronously...
>
> I fixed it using an advice to `vc-diff-finish', but wondering whether
> there's a clean way to achieve the same...
> [...]
> (defadvice vc-diff-finish (after ensure-outline-apply-default-state activate)
>   (when outline-minor-mode
>     (outline-apply-default-state)))

After bug#52855 will be closed, it should be possible to do this by:

  (add-hook 'vc-diff-finish-functions 'outline-apply-default-state)

Also xref works nicely, although I don't know why it requires
`outline-apply-default-state' after enabling `outline-minor-mode':

#+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-default-state 1
                        outline-default-state-subtree-visibility '((match-regexp . "ChangeLog\\|test/manual/etags")))
            (outline-minor-mode +1)
            (outline-apply-default-state)))
#+end_src




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Dec 2021 21:46:01 +0000
Resent-Message-ID: <handler.51809.B51809.164072794722958 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164072794722958
          (code B ref 51809); Tue, 28 Dec 2021 21:46:01 +0000
Received: (at 51809) by debbugs.gnu.org; 28 Dec 2021 21:45:47 +0000
Received: from localhost ([127.0.0.1]:47627 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n2KHy-0005yD-Np
	for submit <at> debbugs.gnu.org; Tue, 28 Dec 2021 16:45:47 -0500
Received: from mail-wr1-f48.google.com ([209.85.221.48]:44843)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n2KHw-0005y0-Q1
 for 51809 <at> debbugs.gnu.org; Tue, 28 Dec 2021 16:45:45 -0500
Received: by mail-wr1-f48.google.com with SMTP id k18so3918406wrg.11
 for <51809 <at> debbugs.gnu.org>; Tue, 28 Dec 2021 13:45:44 -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=gdcoaAJlJe61MxWe6/P2oQhuVBFVxmnEgfoyzaVxCFQ=;
 b=mqmAGsOkGXBwso1HwH6VM1qnK5Ctuzjkz5mIZcbRC9oLSKUGx347auQNPDzw4CGLCP
 9ltW1kIfFz/XZqtPNIJdhXhKjEM/GbE68nN3GdH1AUfdLg1hGSq/i6D82V2tsC5qRJGk
 aA1oIFS6GJFQH+VYHKnAUsU+9I0/dfS6HrzFQCuAtd6p4ZU5iNTLswp/TOvfa8CPk0ZT
 Fz7t38OtP+saP/EAPLOVHWOdfHId28PSCdLXaRPGfJHqbLjTo4eX3y9/Prqbx2UhBcPg
 Qs7QVf55Xqg+VeQCZd3xDe13fY6bT7t13+AJB8ERTKSqtne6rAVlOa+j3czGd2DIyBhs
 eJlw==
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=gdcoaAJlJe61MxWe6/P2oQhuVBFVxmnEgfoyzaVxCFQ=;
 b=OaX6Du8CaJiskASMbyzPKFK9hSYEEtikVb6L6GDFiX+RazWson1mKPWmid50T/5a8S
 MbCtvHAfzgnBkEnYTuFYtDJYvVMiObIY3MyZjJ2JZgkrYz7QkCar4kc6SmKLo78X2ids
 x4mU2z+6HpsBlTsX54O19vv43cU0ZAn72yvUIBPWls1YrYb53aO9SQ/H+9ErWfF6hdT3
 /8SNBuhaM0glmu06P67Mym5HcPa3l4RSGlEszmLFqiiGWI8kA1ww8QdiIaGLDi82gnxP
 AaTT+CbpmK9Y5bZnbeug4h5efQLvlbFsKRymBDAJFWvy7Jx0sYFa2d03e5r6hcNQ5dbd
 PB3Q==
X-Gm-Message-State: AOAM532HDBjMhIbb9vRDqjjZsmE0ukEAWDlkU2+z7QWASm+5Cu0jxAUL
 bWGTPsnukcdXaT1No5Yo5WyOZhePn+g=
X-Google-Smtp-Source: ABdhPJwx2cI6J/1w9i3o0w81llGYfAgW1bWLsvsg8cQ2vBuu+gnE+v5FqjnQJkdxV2ceUqwa10+cAA==
X-Received: by 2002:adf:f907:: with SMTP id b7mr17822161wrr.5.1640727938747;
 Tue, 28 Dec 2021 13:45:38 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id k19sm21669773wmo.29.2021.12.28.13.45.37
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 28 Dec 2021 13:45:37 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <86zgokpoll.fsf@HIDDEN>
Date: Tue, 28 Dec 2021 22:45:37 +0100
In-Reply-To: <86zgokpoll.fsf@HIDDEN> (Juri Linkov's message of "Tue, 
 28 Dec 2021 20:32:22 +0200")
Message-ID: <87v8z8v1xa.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-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:

>> @@ -353,7 +353,9 @@ outline-mode
>> +  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
>> +  (add-hook 'hack-local-variables-hook
>> +	    #'outline-apply-default-state))
>>
>> @@ -436,7 +438,9 @@ outline-minor-mode
>> +        (add-hook 'hack-local-variables-hook
>> +	          #'outline-apply-default-state))
>
> Are you sure about modifying the global value of hack-local-variables-hook
> instead of the buffer-local hook with `nil t' at the end?

Ah, ah, my bad. Many thanks!

> (...) When this feature will be used a lot, even variable names will
> affect usability - with longer names usability deteriorates, and 40
> characters of 'outline-default-state-subtree-visibility' takes half of
> the standard window width.  Would it be possible to find a shorter
> name?

Good point.

> Since it defines the rules, how about 'outline-default-rules'?

LGTM.

> (...) Also outline-long-line-threshold and
> outline-line-count-threshold could share the same prefix, maybe:
>
> # outline-default-long-line: 200
> # outline-default-line-count: 100

Adopted!


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Extend-Outline-mode-with-default-visibility-state.patch

From 6f8fb8b142c913405d9e00732ffbdecb8331ddb7 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Wed, 8 Dec 2021 22:35:42 +0100
Subject: [PATCH] Extend Outline mode with default visibility state

* etc/NEWS: Announce support for default visibility state.

* lisp/outline.el (outline-mode, outline-minor-mode): Ensure default
visibility state is applied.
(outline-hide-sublevels): Add optional argument for function to call
on each heading.
(outline-default-state): Define the default visibility state.
(outline-apply-default-state): Apply default visibility state.
---
 etc/NEWS        |  10 +++
 lisp/outline.el | 181 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 188 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index cfea513cca..9a49ff8379 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -215,6 +215,16 @@ These will take you (respectively) to the next and previous "page".
 ---
 *** 'describe-char' now also outputs the name of emoji combinations.
 
+** Outline Mode
+
+*** Support for a default visibility state.
+Customize the option 'outline-default-state' to define what headings
+are visible when the mode is set.  When equal to a number, the option
+'outline-default-state-subtree-visibility' determines the visibility
+of the subtree starting at the corresponding level.  Values are
+provided to show a heading subtree unless the heading match a regexp,
+or its subtree has long lines or is long.
+
 ** Outline Minor Mode
 
 +++
diff --git a/lisp/outline.el b/lisp/outline.el
index 5e3d4e0e00..1a878dee04 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -354,7 +354,8 @@ outline-mode
               '(outline-font-lock-keywords t nil nil backward-paragraph))
   (setq-local imenu-generic-expression
 	      (list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
-  (add-hook 'change-major-mode-hook #'outline-show-all nil t))
+  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
+  (add-hook 'hack-local-variables-hook #'outline-apply-default-state nil t))
 
 (defvar outline-minor-mode-map)
 
@@ -437,7 +438,9 @@ outline-minor-mode
 		  nil t)
         (setq-local line-move-ignore-invisible t)
 	;; Cause use of ellipses for invisible text.
-	(add-to-invisibility-spec '(outline . t)))
+	(add-to-invisibility-spec '(outline . t))
+        (add-hook 'hack-local-variables-hook
+                  #'outline-apply-default-state nil t))
     (when (or outline-minor-mode-cycle outline-minor-mode-highlight)
       (if font-lock-fontified
           (font-lock-remove-keywords nil outline-font-lock-keywords))
@@ -1094,7 +1097,7 @@ outline-hide-sublevels
       (outline-map-region
        (lambda ()
 	 (if (<= (funcall outline-level) levels)
-	     (outline-show-heading)))
+             (outline-show-heading)))
        beg end)
       ;; Finally unhide any trailing newline.
       (goto-char (point-max))
@@ -1308,6 +1311,178 @@ outline-headers-as-kill
                     (insert "\n\n"))))))
           (kill-new (buffer-string)))))))
 
+(defcustom outline-default-state nil
+  "If non-nil, some headings are initially outlined.
+
+Note that the default state is applied when the major mode is set
+or when the command `outline-apply-default-state' is called
+interactively.
+
+When nil, headings visibility is left unchanged.
+
+If equal to `outline-show-all', all text of buffer is shown.
+
+If equal to `outline-show-only-headings', only headings are shown.
+
+If equal to a number, show only headings up to and including the
+corresponding level.  See `outline-default-rules' to customize
+visibility of the subtree at the choosen level.
+
+If equal to a lambda function or function name, this function is
+expected to toggle headings visibility, and will be called after
+the mode is enabled."
+  :version "29.1"
+  :type '(choice (const :tag "Disabled" nil)
+                 (const :tag "Show all" outline-show-all)
+                 (const :tag "Only headings" outline-show-only-headings)
+                 (natnum :tag "Show headings up to level" :value 1)
+                 (function :tag "Custom function")))
+
+(defcustom outline-default-rules nil
+  "Determines visibility of subtree starting at `outline-default-state' level.
+
+When nil, the subtree is hidden unconditionally.
+
+When equal to a list, each element should be one of the following:
+
+- A cons cell with CAR `match-regexp' and CDR a regexp, the
+  subtree will be hidden when the outline heading match the
+  regexp.
+
+- `subtree-has-long-lines' to only show the heading branches when
+   long lines are detected in its subtree (see
+   `outline-default-long-line' for the definition of long lines).
+
+- `subtree-is-long' to only show the heading branches when its
+  subtree contains more than `outline-default-line-count' lines.
+
+- A lambda function or function name which will be evaluated with
+  point at the beginning of the heading and the match data set
+  appropriately, the function being expected to toggle the
+  heading visibility."
+  :version "29.1"
+  :type '(choice (const :tag "Hide subtree" nil)
+                 (set :tag "Show subtree unless"
+                      (cons :tag "Heading match regexp"
+                            (const match-regexp)  string)
+                      (const :tag "Subtree has long lines"
+                             subtree-has-long-lines)
+                      (const :tag "Subtree is long"
+                             subtree-is-long)
+                      (cons :tag "Custom function"
+                            (const custom-function) function))))
+
+(defcustom outline-default-long-line 1000
+  "Minimal number of characters in a line for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of characters"))
+
+(defcustom outline-default-line-count 50
+  "Minimal number of lines for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defun outline-apply-default-state ()
+  "Apply the outline state defined by `outline-default-state'."
+  (interactive)
+  (cond
+   ((integerp outline-default-state)
+    (outline--show-headings-up-to-level outline-default-state))
+   ((when (functionp outline-default-state)
+      (funcall outline-default-state)))))
+
+(defun outline-show-only-headings ()
+  "Show only headings."
+  (interactive)
+  (outline-show-all)
+  (outline-hide-region-body (point-min) (point-max)))
+
+(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)
+
+(defun outline--show-headings-up-to-level (level)
+  "Show only headings up to a LEVEL level.
+
+Like `outline-hide-sublevels' but, for each heading at level
+LEVEL, decides of subtree visibility according to
+`outline-default-rules'."
+  (if (not outline-default-rules)
+      (outline-hide-sublevels level)
+    (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))))
+             (heading-regexp
+              (cdr-safe
+               (assoc 'match-regexp outline-default-rules)))
+             (check-line-count
+              (memq 'subtree-is-long outline-default-rules))
+             (check-long-lines
+              (memq 'subtree-has-long-lines outline-default-rules))
+             (custom-function
+              (cdr-safe
+               (assoc 'custom-function outline-default-rules))))
+        (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 ()
+             (let ((current-level (funcall outline-level)))
+	       (when (< current-level level)
+                 (outline-show-heading)
+                 (outline-show-entry))
+               (when (= current-level level)
+                 (cond
+                  ((and heading-regexp
+                        (let ((beg (point))
+                              (end (progn (outline-end-of-heading) (point))))
+                          (string-match-p heading-regexp (buffer-substring beg end))))
+                   ;; hide entry when heading match regexp
+                   (outline-hide-entry))
+                  ((and check-line-count
+                        (save-excursion
+                          (let ((beg (point))
+                                (end (progn (outline-end-of-subtree) (point))))
+                            (<= outline-default-line-count (count-lines beg end)))))
+                   ;; show only branches when line count of subtree >
+                   ;; threshold
+                   (outline-show-branches))
+                  ((and check-long-lines
+                        (save-excursion
+                          (let ((beg (point))
+                                (end (progn (outline-end-of-subtree) (point))))
+                            (save-restriction
+                              (narrow-to-region beg end)
+                              (let ((so-long-skip-leading-comments nil)
+                                    (so-long-threshold outline-default-long-line)
+                                    (so-long-max-lines nil))
+                                (so-long-detected-long-line-p))))))
+                   ;; show only branches when long lines are detected
+                   ;; in subtree
+                   (outline-show-branches))
+                  (custom-function
+                   ;; call custom function if defined
+                   (funcall custom-function))
+                  (t
+                   ;; if no previous clause succeeds, show subtree
+                   (outline-show-subtree))))))
+         beg end)))
+    (run-hooks 'outline-view-change-hook)))
+
 (defun outline--cycle-state ()
   "Return the cycle state of current heading.
 Return either 'hide-all, 'headings-only, or 'show-all."
-- 
2.30.2


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


-- 
Matthias

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Dec 2021 21:47:02 +0000
Resent-Message-ID: <handler.51809.B51809.164072800823068 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164072800823068
          (code B ref 51809); Tue, 28 Dec 2021 21:47:02 +0000
Received: (at 51809) by debbugs.gnu.org; 28 Dec 2021 21:46:48 +0000
Received: from localhost ([127.0.0.1]:47631 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n2KIy-000600-E6
	for submit <at> debbugs.gnu.org; Tue, 28 Dec 2021 16:46:48 -0500
Received: from mail-wr1-f44.google.com ([209.85.221.44]:46777)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n2KIw-0005zn-Nw
 for 51809 <at> debbugs.gnu.org; Tue, 28 Dec 2021 16:46:47 -0500
Received: by mail-wr1-f44.google.com with SMTP id i22so40590958wrb.13
 for <51809 <at> debbugs.gnu.org>; Tue, 28 Dec 2021 13:46:46 -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=zyZSoeuDMbN+1UtuUGmZozvLR20rjeXQk+3Ls7+rVsE=;
 b=A3Wziw48JXOnjkrFpdJHGCJL8ZYr0YFysBlPUVIlVkPIU2KxVAd+qjmQjKF6fiF26y
 k8vP6/t5p1zmLH2Y/Q3OdWkvXNurOopC9MDloizRPOZzJEnyBzeDXXccaqsmO8sgVvpr
 GiF00zByaNjzL1Xc6XZqcxE3jZCPt9uR/ofM+hQSImxTvXior5yWIhYIFwN6y3dFidwt
 GEqMVLDigWlCuckPlHEA2eSx1WT7M60omdgEVp85NbdYPCfITnata8CMcdkiVKurowbr
 hMepjg/fX9RM3gJOF28TvrTv6gNacux7O2zU1NWz3O96yQ56NBdV7eb8tPRzNwzuZVLF
 vPHA==
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=zyZSoeuDMbN+1UtuUGmZozvLR20rjeXQk+3Ls7+rVsE=;
 b=IVzSTnv4nPBstnMxPjtjYAfVyYFt0zOKCheDNS1j1D8V+F76Zhi3YsvwgcGY4JQYMs
 MqnxIQ3mQZSm86Bpk0QfMnZSM/qLs3WvMf9cW2MvlT1sGDcnfO2/rdgCvPG36UmfLsuU
 mYDPyPZMSJjpatkfFve/j9Sp/B0Ay4Xcpcrvn3lV8787Ul+kUKKfMnwV16bKKHck0p+9
 stC3Qx5nqF46/DpNKvHXHbVkQa1BplGyxzU9EpAmndi0oWxFYUFiqvjOVW+5WFadWzoX
 bnfDSmBqT8z0qpVWBCfa7Ig9yo7heFXykLUUGDSelx9TUQfHLXD5kqXaTFXXec7xiQJo
 FnDg==
X-Gm-Message-State: AOAM531Bx9HCRQbWr/0Tt651oPF+KK7x2Mx1fknosGIN1FkNn1RKPjRI
 XZ++HJsvn9jG2Yjv5n4hwAQ28FcaVMQ=
X-Google-Smtp-Source: ABdhPJz5KjM89EVeXhNs/VP9KBx80U1Zn3Ymg4Jte1R986+nG3VlsXQQpt+Ws3VW3vEEiB1q1qxfQQ==
X-Received: by 2002:adf:fc83:: with SMTP id g3mr17941976wrr.255.1640728001187; 
 Tue, 28 Dec 2021 13:46:41 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id h4sm19332263wrf.93.2021.12.28.13.46.40
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 28 Dec 2021 13:46:40 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN> <86ilv8pnf3.fsf@HIDDEN>
Date: Tue, 28 Dec 2021 22:46:40 +0100
In-Reply-To: <86ilv8pnf3.fsf@HIDDEN> (Juri Linkov's message of "Tue, 
 28 Dec 2021 20:37:52 +0200")
Message-ID: <87r19wv1vj.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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:

> (...) Also xref works nicely, although I don't know why it requires
> `outline-apply-default-state' after enabling `outline-minor-mode':

Same here. I'll have a look.
-- 
Matthias




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 28 Dec 2021 22:29:02 +0000
Resent-Message-ID: <handler.51809.B51809.164073052027007 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164073052027007
          (code B ref 51809); Tue, 28 Dec 2021 22:29:02 +0000
Received: (at 51809) by debbugs.gnu.org; 28 Dec 2021 22:28:40 +0000
Received: from localhost ([127.0.0.1]:47663 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n2KxT-00071W-Mv
	for submit <at> debbugs.gnu.org; Tue, 28 Dec 2021 17:28:39 -0500
Received: from mail-wr1-f44.google.com ([209.85.221.44]:39459)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n2KxS-00071K-39
 for 51809 <at> debbugs.gnu.org; Tue, 28 Dec 2021 17:28:38 -0500
Received: by mail-wr1-f44.google.com with SMTP id s1so40807604wra.6
 for <51809 <at> debbugs.gnu.org>; Tue, 28 Dec 2021 14:28:38 -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=aMa2Vq88Si5TONexhYXkJVTUI/P57YQi/3G/L+Hd9/o=;
 b=l6MHL57tKANiLPQAhYQp9GnbKwRXdQk/FuwBzAOlgSDHYupRhBbsnQSWBpjF2bSqaE
 cIL+mH2ZtREWwz+TG7+RaerHhnAQH+4WXXigplchOMeGeresNwt99rvt+T3kyylJFYzG
 yA2QHsvqlC6gFQlC/c50bA5MVXrqPX9TTp1O8y6Cm1MVaeWKXRrA5ntaNmiXL/tCqFfm
 SWBO4/t/mSd3jLUBzNHJA5t2THbe2uI9WpwHsvCDRYvInCw683ysXbvloRXJ+ayqhoMu
 7HqlMAphCdUnDlchRg9FDgsRZnw5itbEgada8UKAvhQsKg7M0ZI4efYQ/2Lo1nuDj87C
 uMxw==
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=aMa2Vq88Si5TONexhYXkJVTUI/P57YQi/3G/L+Hd9/o=;
 b=w1rEB5MU19OgS61QDuRUsG2r29wLRqKqkKyc/k9g8zBpt+R/6OT8BOvNQdSD0da+LM
 jt3b2VPGyB1uQz46TX4EhrMQ7sivhts0xhwCuo1WezW34HUeszA6MpAOVH0raf76ShbM
 sWHbjgMLCSpeixvjRA6z2Z+sWTzJh1eogLz1CwIyAUh7EWfHIuM8Tn7KMPghU2LYHM77
 oA3oUq3f0NAF9WTTv3vzVP+iWFrPOAgLgM9LmcJL7g399qVm7AmVvZ8YcX/+6/1ZPDl6
 yo1WQnc2uNF21QsG8DKZglS2siqWoC+ouiK7oG5w9BVgEvw6nPclAIyOPtnXk7NHgi11
 zvOQ==
X-Gm-Message-State: AOAM533ulQf+EiF3kuho329+VM/OFK5F2dE6wB9qvZOrPitab0Wn90iE
 KoD3VvgAF2lwL7vbSMe4fKygH0/v2Io=
X-Google-Smtp-Source: ABdhPJyM591TKs7Op0uM8t8/CWZ2RU0ZTEVJre1EajckPt5mntWORU5DCuV6DOqhEir+Tqb7dugowg==
X-Received: by 2002:a5d:64c3:: with SMTP id f3mr17802952wri.295.1640730512236; 
 Tue, 28 Dec 2021 14:28:32 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id l26sm18836055wrz.44.2021.12.28.14.28.31
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Tue, 28 Dec 2021 14:28:31 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN> <86ilv8pnf3.fsf@HIDDEN>
Date: Tue, 28 Dec 2021 23:28:31 +0100
In-Reply-To: <86ilv8pnf3.fsf@HIDDEN> (Juri Linkov's message of "Tue, 
 28 Dec 2021 20:37:52 +0200")
Message-ID: <87k0fouzxs.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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:

> (...)  Also xref works nicely, although I don't know why it requires
> `outline-apply-default-state' after enabling `outline-minor-mode':

It's a mistake to rely on `hack-local-variables-hook' to call
`outline-apply-default-state' when Outline minor mode is enabled since
`hack-local-variables-hook' is run after processing a file's local
variable specs.

An explicit call to `outline-apply-default-state' in the implementation
of outline-minor-mode fix the problem:

diff --git a/lisp/outline.el b/lisp/outline.el
index 1a878dee04..65956b9dae 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -439,8 +439,7 @@ outline-minor-mode
         (setq-local line-move-ignore-invisible t)
 	;; Cause use of ellipses for invisible text.
 	(add-to-invisibility-spec '(outline . t))
-        (add-hook 'hack-local-variables-hook
-                  #'outline-apply-default-state nil t))
+        (outline-apply-default-state))
     (when (or outline-minor-mode-cycle outline-minor-mode-highlight)
       (if font-lock-fontified
           (font-lock-remove-keywords nil outline-font-lock-keywords))

I'll send an updated patch after some time using this.
-- 
Matthias




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Tue, 11 Jan 2022 17:48:01 +0000
Resent-Message-ID: <handler.51809.B51809.16419232274408 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.16419232274408
          (code B ref 51809); Tue, 11 Jan 2022 17:48:01 +0000
Received: (at 51809) by debbugs.gnu.org; 11 Jan 2022 17:47:07 +0000
Received: from localhost ([127.0.0.1]:55472 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n7LEg-00018s-Ju
	for submit <at> debbugs.gnu.org; Tue, 11 Jan 2022 12:47:06 -0500
Received: from relay3-d.mail.gandi.net ([217.70.183.195]:44551)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>) id 1n7LEb-000106-85
 for 51809 <at> debbugs.gnu.org; Tue, 11 Jan 2022 12:47:05 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id F062460002;
 Tue, 11 Jan 2022 17:46:53 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN> <86ilv8pnf3.fsf@HIDDEN>
 <87k0fouzxs.fsf@HIDDEN>
Date: Tue, 11 Jan 2022 19:46:05 +0200
In-Reply-To: <87k0fouzxs.fsf@HIDDEN> (Matthias Meulien's message of "Tue,
 28 Dec 2021 23:28:31 +0100")
Message-ID: <86sftumahu.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-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 (-)

>> (...)  Also xref works nicely, although I don't know why it requires
>> `outline-apply-default-state' after enabling `outline-minor-mode':
>
> It's a mistake to rely on `hack-local-variables-hook' to call
> `outline-apply-default-state' when Outline minor mode is enabled since
> `hack-local-variables-hook' is run after processing a file's local
> variable specs.

There is also such a case possible where the file begins with a prop-line:

  # -*- mode: outline-minor; -*-

and ends with the Local Variables section, e.g.:

  # outline-default-state: 2

`hack-local-variables-hook' can handle such case in `outline-minor-mode'.

> I'll send an updated patch after some time using this.

Now you can take in use a new hook added in bug#52855 that allows
applying the default state after vc-diff finishes:

  (add-hook 'vc-diff-finish-functions 'outline-apply-default-state)




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Fri, 14 Jan 2022 16:42:01 +0000
Resent-Message-ID: <handler.51809.B51809.164217848823556 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164217848823556
          (code B ref 51809); Fri, 14 Jan 2022 16:42:01 +0000
Received: (at 51809) by debbugs.gnu.org; 14 Jan 2022 16:41:28 +0000
Received: from localhost ([127.0.0.1]:37951 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n8Pdn-00067s-LE
	for submit <at> debbugs.gnu.org; Fri, 14 Jan 2022 11:41:28 -0500
Received: from mail-wr1-f46.google.com ([209.85.221.46]:35837)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n8Pdk-00067a-Jo
 for 51809 <at> debbugs.gnu.org; Fri, 14 Jan 2022 11:41:26 -0500
Received: by mail-wr1-f46.google.com with SMTP id e9so16602768wra.2
 for <51809 <at> debbugs.gnu.org>; Fri, 14 Jan 2022 08: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=wTzyuGS3/Y69mPp8YSLoxSLfwwfrMNtOZbR87Y05FcA=;
 b=LcZjGXJiCDFSQXGtT3cTJiuDjsk54EVvGCTtO2jNbAIz8GxOPpHQkniC1W0ZoDWIkQ
 2VhxqrPXdhMS2eA/QEu/I78H/VLbsQVxvWAuSU9siOXFX5wD+Nk4iU80rZMzgH8iYSza
 ZV2uDtB1buQjElqlFFq5b7exCCr55NYRoLARBczWlAAyQQRojLHivEnesvmsd2NKzHKm
 IPOvt2LQj61lWbJ77cKKsSAbYFM1qk8NlLDVGjCbzQi5XERL0RgUHfDhY7f6Ah3IuPeU
 y6ijLHVEXknAevp9hZ1prFNc4rnP86LIMVB0ERzRgyV6U2oMlJssAbSq5cmG92v5Ckcm
 mrZg==
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=wTzyuGS3/Y69mPp8YSLoxSLfwwfrMNtOZbR87Y05FcA=;
 b=5rgk2Pm+jb7dF9szPRLPR/cA4xTwxhc6J1PV+3oxDAGq7VrFL5y7NsCCy72784AXgD
 U7x8A6IdJ+PbNz+u8ybVwDZKxPcffSPMaVnGAVUzS7Q+4upl5y/x7iQ/nLTE9jx2Qo4v
 V5MuryqeHdSVgiqmNhfDsHOoB7pHbSZxkh6Y6jh1K9UJmWmmSQbWNBiOqyHhAXOCf702
 gn1v6evLw6JYkyyFqbxf/lc6n+zLFR+4j9EBDhB6nPFgWbwM38lDjvQUdBvkSkwGghuK
 aPRKRDnx8xcgk3HdqPvrZWyL8zY9+SUhG3d00MsiAG/1ePMYXuHYELgOdemr66RczN0N
 RfCQ==
X-Gm-Message-State: AOAM532xIvH5uhYecIgt427FDOcQYeyN0Tu82/4QQa/5F3Kh1xqi+wHT
 4igjd4p91k4mQlIDCf3Jk8IiJs8Gjtw=
X-Google-Smtp-Source: ABdhPJyhBAmKUdggnOJ9ziEMX+bZ1Shso9lXoV5/3BZkJkvMzbwfuKzy5IVQCjjnbIaH+Cq6itNlHA==
X-Received: by 2002:a05:6000:12cc:: with SMTP id
 l12mr9049058wrx.290.1642178478565; 
 Fri, 14 Jan 2022 08:41:18 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id bk2sm5518565wrb.65.2022.01.14.08.41.17
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 14 Jan 2022 08:41:17 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN> <86ilv8pnf3.fsf@HIDDEN>
 <87k0fouzxs.fsf@HIDDEN> <86sftumahu.fsf@HIDDEN>
Date: Fri, 14 Jan 2022 17:41:16 +0100
In-Reply-To: <86sftumahu.fsf@HIDDEN> (Juri Linkov's message of "Tue, 
 11 Jan 2022 19:46:05 +0200")
Message-ID: <87pmouw9qr.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-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; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi Juri,

Juri Linkov <juri@HIDDEN> writes:

>>> (...)  Also xref works nicely, although I don't know why it requires
>>> `outline-apply-default-state' after enabling `outline-minor-mode':
>>
>> It's a mistake to rely on `hack-local-variables-hook' to call
>> `outline-apply-default-state' when Outline minor mode is enabled since
>> `hack-local-variables-hook' is run after processing a file's local
>> variable specs.
>
> There is also such a case possible where the file begins with a prop-line:
>
>   # -*- mode: outline-minor; -*-
>
> and ends with the Local Variables section, e.g.:
>
>   # outline-default-state: 2
>
> `hack-local-variables-hook' can handle such case in `outline-minor-mode'.
>

This usage of "mode:" looks quite exotic to me. Isn't outine-minor a
minor mode? According to the documentation:

   The special variable/value pair =E2=80=98mode: MODENAME;=E2=80=99, if pr=
esent,
   specifies a major mode (without the =E2=80=9C-mode=E2=80=9D suffix).

I prefer not support this if possible.

>> I'll send an updated patch after some time using this.
>
> Now you can take in use a new hook added in bug#52855 that allows
> applying the default state after vc-diff finishes:
>
>   (add-hook 'vc-diff-finish-functions 'outline-apply-default-state)

Thanks, I updated my configuration to the following:

(add-hook 'diff-mode-hook #'(lambda ()
			      (setq outline-default-state 1
				    outline-default-rules
				    '(subtree-is-long
				      subtree-has-long-lines
				      (match-regexp . "NEWS\\|test\\|package-lock\\.json\\|poetry\\.loc=
k")))))

(add-hook 'vc-diff-finish-functions
	  #'(lambda ()
	      (when outline-minor-mode
		(outline-apply-default-state))))

(add-hook 'xref-after-update-hook
          #'(lambda ()
              (setq outline-regexp (if (eq xref-file-name-display 'abs)
                                       "/" "[^ 0-9]")
                    outline-default-state 1
                    outline-default-rules '((match-regexp . "ChangeLog\\|te=
st/manual/etags")))
              (outline-minor-mode)))

Here is an updated patch (just rebased my local branch, some minor
conflicts appeared in outline.el):


--=-=-=
Content-Type: text/x-diff
Content-Disposition: inline;
 filename=0001-Extend-Outline-mode-with-default-visibility-state.patch

From 46934ba08d597a4d0d6e9d6c3918e5eabc1ec613 Mon Sep 17 00:00:00 2001
From: Matthias Meulien <orontee@HIDDEN>
Date: Wed, 8 Dec 2021 22:35:42 +0100
Subject: [PATCH] Extend Outline mode with default visibility state

* etc/NEWS: Announce support for default visibility state.

* lisp/outline.el (outline-mode, outline-minor-mode): Ensure default
visibility state is applied.
(outline-hide-sublevels): Add optional argument for function to call
on each heading.
(outline-default-state): Define the default visibility state.
(outline-apply-default-state): Apply default visibility state.
---
 etc/NEWS        |  10 +++
 lisp/outline.el | 180 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 187 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ea9ba49892..49b5db9b1a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -243,6 +243,16 @@ These will take you (respectively) to the next and previous "page".
 ---
 *** 'describe-char' now also outputs the name of emoji combinations.
 
+** Outline Mode
+
+*** Support for a default visibility state.
+Customize the option 'outline-default-state' to define what headings
+are visible when the mode is set.  When equal to a number, the option
+'outline-default-state-subtree-visibility' determines the visibility
+of the subtree starting at the corresponding level.  Values are
+provided to show a heading subtree unless the heading match a regexp,
+or its subtree has long lines or is long.
+
 ** Outline Minor Mode
 
 +++
diff --git a/lisp/outline.el b/lisp/outline.el
index 4027142c94..bca0f3bef8 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -351,7 +351,8 @@ outline-mode
               '(outline-font-lock-keywords t nil nil backward-paragraph))
   (setq-local imenu-generic-expression
 	      (list (list nil (concat "^\\(?:" outline-regexp "\\).*$") 0)))
-  (add-hook 'change-major-mode-hook #'outline-show-all nil t))
+  (add-hook 'change-major-mode-hook #'outline-show-all nil t)
+  (add-hook 'hack-local-variables-hook #'outline-apply-default-state nil t))
 
 (defvar outline-minor-mode-map)
 
@@ -434,7 +435,8 @@ outline-minor-mode
 		  nil t)
         (setq-local line-move-ignore-invisible t)
 	;; Cause use of ellipses for invisible text.
-	(add-to-invisibility-spec '(outline . t)))
+	(add-to-invisibility-spec '(outline . t))
+        (outline-apply-default-state))
     (when outline-minor-mode-highlight
       (if font-lock-fontified
           (font-lock-remove-keywords nil outline-font-lock-keywords))
@@ -1089,7 +1091,7 @@ outline-hide-sublevels
       (outline-map-region
        (lambda ()
 	 (if (<= (funcall outline-level) levels)
-	     (outline-show-heading)))
+             (outline-show-heading)))
        beg end)
       ;; Finally unhide any trailing newline.
       (goto-char (point-max))
@@ -1303,6 +1305,178 @@ outline-headers-as-kill
                     (insert "\n\n"))))))
           (kill-new (buffer-string)))))))
 
+(defcustom outline-default-state nil
+  "If non-nil, some headings are initially outlined.
+
+Note that the default state is applied when the major mode is set
+or when the command `outline-apply-default-state' is called
+interactively.
+
+When nil, headings visibility is left unchanged.
+
+If equal to `outline-show-all', all text of buffer is shown.
+
+If equal to `outline-show-only-headings', only headings are shown.
+
+If equal to a number, show only headings up to and including the
+corresponding level.  See `outline-default-rules' to customize
+visibility of the subtree at the choosen level.
+
+If equal to a lambda function or function name, this function is
+expected to toggle headings visibility, and will be called after
+the mode is enabled."
+  :version "29.1"
+  :type '(choice (const :tag "Disabled" nil)
+                 (const :tag "Show all" outline-show-all)
+                 (const :tag "Only headings" outline-show-only-headings)
+                 (natnum :tag "Show headings up to level" :value 1)
+                 (function :tag "Custom function")))
+
+(defcustom outline-default-rules nil
+  "Determines visibility of subtree starting at `outline-default-state' level.
+
+When nil, the subtree is hidden unconditionally.
+
+When equal to a list, each element should be one of the following:
+
+- A cons cell with CAR `match-regexp' and CDR a regexp, the
+  subtree will be hidden when the outline heading match the
+  regexp.
+
+- `subtree-has-long-lines' to only show the heading branches when
+   long lines are detected in its subtree (see
+   `outline-default-long-line' for the definition of long lines).
+
+- `subtree-is-long' to only show the heading branches when its
+  subtree contains more than `outline-default-line-count' lines.
+
+- A lambda function or function name which will be evaluated with
+  point at the beginning of the heading and the match data set
+  appropriately, the function being expected to toggle the
+  heading visibility."
+  :version "29.1"
+  :type '(choice (const :tag "Hide subtree" nil)
+                 (set :tag "Show subtree unless"
+                      (cons :tag "Heading match regexp"
+                            (const match-regexp)  string)
+                      (const :tag "Subtree has long lines"
+                             subtree-has-long-lines)
+                      (const :tag "Subtree is long"
+                             subtree-is-long)
+                      (cons :tag "Custom function"
+                            (const custom-function) function))))
+
+(defcustom outline-default-long-line 1000
+  "Minimal number of characters in a line for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of characters"))
+
+(defcustom outline-default-line-count 50
+  "Minimal number of lines for a heading to be outlined."
+  :version "29.1"
+  :type '(natnum :tag "Number of lines"))
+
+(defun outline-apply-default-state ()
+  "Apply the outline state defined by `outline-default-state'."
+  (interactive)
+  (cond
+   ((integerp outline-default-state)
+    (outline--show-headings-up-to-level outline-default-state))
+   ((when (functionp outline-default-state)
+      (funcall outline-default-state)))))
+
+(defun outline-show-only-headings ()
+  "Show only headings."
+  (interactive)
+  (outline-show-all)
+  (outline-hide-region-body (point-min) (point-max)))
+
+(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)
+
+(defun outline--show-headings-up-to-level (level)
+  "Show only headings up to a LEVEL level.
+
+Like `outline-hide-sublevels' but, for each heading at level
+LEVEL, decides of subtree visibility according to
+`outline-default-rules'."
+  (if (not outline-default-rules)
+      (outline-hide-sublevels level)
+    (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))))
+             (heading-regexp
+              (cdr-safe
+               (assoc 'match-regexp outline-default-rules)))
+             (check-line-count
+              (memq 'subtree-is-long outline-default-rules))
+             (check-long-lines
+              (memq 'subtree-has-long-lines outline-default-rules))
+             (custom-function
+              (cdr-safe
+               (assoc 'custom-function outline-default-rules))))
+        (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 ()
+             (let ((current-level (funcall outline-level)))
+	       (when (< current-level level)
+                 (outline-show-heading)
+                 (outline-show-entry))
+               (when (= current-level level)
+                 (cond
+                  ((and heading-regexp
+                        (let ((beg (point))
+                              (end (progn (outline-end-of-heading) (point))))
+                          (string-match-p heading-regexp (buffer-substring beg end))))
+                   ;; hide entry when heading match regexp
+                   (outline-hide-entry))
+                  ((and check-line-count
+                        (save-excursion
+                          (let ((beg (point))
+                                (end (progn (outline-end-of-subtree) (point))))
+                            (<= outline-default-line-count (count-lines beg end)))))
+                   ;; show only branches when line count of subtree >
+                   ;; threshold
+                   (outline-show-branches))
+                  ((and check-long-lines
+                        (save-excursion
+                          (let ((beg (point))
+                                (end (progn (outline-end-of-subtree) (point))))
+                            (save-restriction
+                              (narrow-to-region beg end)
+                              (let ((so-long-skip-leading-comments nil)
+                                    (so-long-threshold outline-default-long-line)
+                                    (so-long-max-lines nil))
+                                (so-long-detected-long-line-p))))))
+                   ;; show only branches when long lines are detected
+                   ;; in subtree
+                   (outline-show-branches))
+                  (custom-function
+                   ;; call custom function if defined
+                   (funcall custom-function))
+                  (t
+                   ;; if no previous clause succeeds, show subtree
+                   (outline-show-subtree))))))
+         beg end)))
+    (run-hooks 'outline-view-change-hook)))
+
 (defun outline--cycle-state ()
   "Return the cycle state of current heading.
 Return either 'hide-all, 'headings-only, or 'show-all."
-- 
2.30.2


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


What would be the next step? Should we stop here or introduce some
customization in Diff mode to help people discover how the "outline
default state feature" can be used there (not convinced myself it'd be
usefull)?
-- 
Matthias

--=-=-=--




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Juri Linkov <juri@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sun, 16 Jan 2022 18:15:02 +0000
Resent-Message-ID: <handler.51809.B51809.164235689625114 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: patch
To: Matthias Meulien <orontee@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164235689625114
          (code B ref 51809); Sun, 16 Jan 2022 18:15:02 +0000
Received: (at 51809) by debbugs.gnu.org; 16 Jan 2022 18:14:56 +0000
Received: from localhost ([127.0.0.1]:44225 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n9A3M-0006Wz-E1
	for submit <at> debbugs.gnu.org; Sun, 16 Jan 2022 13:14:56 -0500
Received: from relay9-d.mail.gandi.net ([217.70.183.199]:40741)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>)
 id 1n9A3K-0006Wg-Jq; Sun, 16 Jan 2022 13:14:55 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by mail.gandi.net (Postfix) with ESMTPSA id 2CD88FF805;
 Sun, 16 Jan 2022 18:14:46 +0000 (UTC)
From: Juri Linkov <juri@HIDDEN>
Organization: LINKOV.NET
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN> <86ilv8pnf3.fsf@HIDDEN>
 <87k0fouzxs.fsf@HIDDEN> <86sftumahu.fsf@HIDDEN>
 <87pmouw9qr.fsf@HIDDEN>
Date: Sun, 16 Jan 2022 20:14:15 +0200
In-Reply-To: <87pmouw9qr.fsf@HIDDEN> (Matthias Meulien's message of "Fri,
 14 Jan 2022 17:41:16 +0100")
Message-ID: <86bl0b35vs.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-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 (-)

tags 51809 + patch fixed
thanks

Hi Matthias,

>>   # -*- mode: outline-minor; -*-
>
> This usage of "mode:" looks quite exotic to me. Isn't outine-minor a
> minor mode? According to the documentation:
>
>    The special variable/value pair ‘mode: MODENAME;’, if present,
>    specifies a major mode (without the “-mode” suffix).
>
> I prefer not support this if possible.

You are right, it rather should be more like:

  -*- mode: text; mode: outline-minor; -*-

that is supported.

> Here is an updated patch (just rebased my local branch, some minor
> conflicts appeared in outline.el):

Thanks for working on this patch!  I've tested it thoroughly,
and everything works nicely, so I pushed it to master.

> What would be the next step? Should we stop here or introduce some
> customization in Diff mode to help people discover how the "outline
> default state feature" can be used there (not convinced myself it'd be
> usefull)?

Maybe more documentation about using this in diff-mode
could be added to the docstrings and to the manual?




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


Received: (at control) by debbugs.gnu.org; 16 Jan 2022 18:14:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 16 13:14:56 2022
Received: from localhost ([127.0.0.1]:44227 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n9A3M-0006X1-KZ
	for submit <at> debbugs.gnu.org; Sun, 16 Jan 2022 13:14:56 -0500
Received: from relay9-d.mail.gandi.net ([217.70.183.199]:40741)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <juri@HIDDEN>)
 id 1n9A3K-0006Wg-Jq; Sun, 16 Jan 2022 13:14:55 -0500
Received: (Authenticated sender: juri@HIDDEN)
 by mail.gandi.net (Postfix) with ESMTPSA id 2CD88FF805;
 Sun, 16 Jan 2022 18:14:46 +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>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN> <86ilv8pnf3.fsf@HIDDEN>
 <87k0fouzxs.fsf@HIDDEN> <86sftumahu.fsf@HIDDEN>
 <87pmouw9qr.fsf@HIDDEN>
Date: Sun, 16 Jan 2022 20:14:15 +0200
In-Reply-To: <87pmouw9qr.fsf@HIDDEN> (Matthias Meulien's message of "Fri,
 14 Jan 2022 17:41:16 +0100")
Message-ID: <86bl0b35vs.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: control
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 (-)

tags 51809 + patch fixed
thanks

Hi Matthias,

>>   # -*- mode: outline-minor; -*-
>
> This usage of "mode:" looks quite exotic to me. Isn't outine-minor a
> minor mode? According to the documentation:
>
>    The special variable/value pair ‘mode: MODENAME;’, if present,
>    specifies a major mode (without the “-mode” suffix).
>
> I prefer not support this if possible.

You are right, it rather should be more like:

  -*- mode: text; mode: outline-minor; -*-

that is supported.

> Here is an updated patch (just rebased my local branch, some minor
> conflicts appeared in outline.el):

Thanks for working on this patch!  I've tested it thoroughly,
and everything works nicely, so I pushed it to master.

> What would be the next step? Should we stop here or introduce some
> customization in Diff mode to help people discover how the "outline
> default state feature" can be used there (not convinced myself it'd be
> usefull)?

Maybe more documentation about using this in diff-mode
could be added to the docstrings and to the manual?




Message sent to bug-gnu-emacs@HIDDEN:


X-Loop: help-debbugs@HIDDEN
Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers
Resent-From: Matthias Meulien <orontee@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Mon, 17 Jan 2022 21:11:02 +0000
Resent-Message-ID: <handler.51809.B51809.164245386117285 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 51809
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords: fixed patch
To: Juri Linkov <juri@HIDDEN>
Cc: 51809 <at> debbugs.gnu.org
Received: via spool by 51809-submit <at> debbugs.gnu.org id=B51809.164245386117285
          (code B ref 51809); Mon, 17 Jan 2022 21:11:02 +0000
Received: (at 51809) by debbugs.gnu.org; 17 Jan 2022 21:11:01 +0000
Received: from localhost ([127.0.0.1]:48278 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1n9ZHI-0004Uj-Uc
	for submit <at> debbugs.gnu.org; Mon, 17 Jan 2022 16:11:01 -0500
Received: from mail-wm1-f48.google.com ([209.85.128.48]:54226)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <orontee@HIDDEN>) id 1n9ZHF-0004UU-0e
 for 51809 <at> debbugs.gnu.org; Mon, 17 Jan 2022 16:11:00 -0500
Received: by mail-wm1-f48.google.com with SMTP id k5so14102959wmj.3
 for <51809 <at> debbugs.gnu.org>; Mon, 17 Jan 2022 13:10:57 -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=tm0JdP+lAu/3cfOVbpHpa5TKdKuW4sZTwtcRSH/YGog=;
 b=H8jiOXHvrZil66iQETQ0o2s3n6W/f3YSytNJv8/o02verKZ9J5ysSYnhDed9inZ9O6
 kMEtDSMtPN8E9Mu/dGm9wmjRaXhRoNnaW0vz0XzjrY/NMicpEUd8MasTBbBZakcxvxaO
 BMHIQFmQcVRenYOjxKzgzeR8OUX3PSAvnQAnbuBAckwIrE7D1wjezlwoBJDwtQAkiH6F
 nIrYYpBhsqx7CxmuFC0LzvaTSEQUIP1VVvb2UEMFRBfrqRU5gkgx8OTrCjKrUrRQ3b0p
 GT7cvvVCey7Zn1zZhswEZ4w2FjO9ZseFlPL1CsrmqhSVeCtUl8W10ko0U2dpzCh1eHsi
 AsSg==
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=tm0JdP+lAu/3cfOVbpHpa5TKdKuW4sZTwtcRSH/YGog=;
 b=ErbU07L1kOhgLxvscOVRAV9OQ6cWjFlLbvhI7scRVAb+JNLSyP97mxDVRaRK8RlIql
 406HHTMRV2eHBRo89V8uBGqXrayZ9EnsKQ5CFM+rf2zmu24vA5ssJR0DelvhvKd1rXZz
 euC03N7PqTLJ+xQtITzukXS7uwxoF7UTJiZUtRcKwQnvmUBA02VrVrAv+rgFNF+QT8PC
 /NeKPlUUD+kv0TRcMj2g2NqHLhU7q6oabSXMty6RH8iiW9vDntW84oPLEPebIdY737F6
 eehwg+9cb7NinCDtrpujr19jwC8flculTS+K4CP5niG44rzSi7afpZVQQskePbKIfyOi
 Vgig==
X-Gm-Message-State: AOAM531Zo2pVFeZcYT5PnWQ8VKhI+IgMUdIC/Y9sbdmiv487DvWFhduf
 gnnoOQINrABxBs4heQ7aOj1Ibh1Ecvc=
X-Google-Smtp-Source: ABdhPJyjXlCndNJoIcclkC+cx2OkRb5WuXthNiNdAWiQGReONkoai6v4dBPf3WMDtm1o9owfAGDEJw==
X-Received: by 2002:a5d:64a5:: with SMTP id m5mr4469940wrp.503.1642453851225; 
 Mon, 17 Jan 2022 13:10:51 -0800 (PST)
Received: from carbon.localdomain ([2a01:e0a:245:c850:98f5:429a:aa8e:95bb])
 by smtp.gmail.com with ESMTPSA id 10sm410008wmc.44.2022.01.17.13.10.50
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 17 Jan 2022 13:10:50 -0800 (PST)
From: Matthias Meulien <orontee@HIDDEN>
References: <87lf1sw6ji.fsf@HIDDEN> <86h7cgdk4v.fsf@HIDDEN>
 <87ee7kvshn.fsf@HIDDEN> <87a6i7x5iq.fsf@HIDDEN>
 <86k0hbam7r.fsf@HIDDEN> <878rxrmy7q.fsf@HIDDEN>
 <86y256uc0v.fsf@HIDDEN> <87r1ajknsr.fsf@HIDDEN>
 <86ilvu6w6k.fsf@HIDDEN> <871r2hc51a.fsf@HIDDEN>
 <87r19zs662.fsf@HIDDEN> <871r1zm7ji.fsf@HIDDEN>
 <87wnjrkrwd.fsf@HIDDEN> <86ilv8pnf3.fsf@HIDDEN>
 <87k0fouzxs.fsf@HIDDEN> <86sftumahu.fsf@HIDDEN>
 <87pmouw9qr.fsf@HIDDEN>
Date: Mon, 17 Jan 2022 22:10:50 +0100
In-Reply-To: <87pmouw9qr.fsf@HIDDEN> (Matthias Meulien's message of "Fri,
 14 Jan 2022 17:41:16 +0100")
Message-ID: <87a6fuvzj9.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
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 (-)

Matthias Meulien <orontee@HIDDEN> writes:

> (...)  What would be the next step? Should we stop here or introduce
> some customization in Diff mode to help people discover how the
> "outline default state feature" can be used there (not convinced
> myself it'd be usefull)?

I see one problem: Once one has some default state configured for Diff
mode, it applies to patch embedded in Gnus Article buffers, but there
the outline-minor-mode keymap isn't active and there's no way to toggle
headings visibility... No idea how to improve this situation...





Last modified: Mon, 17 Jan 2022 21:15:02 UTC

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