From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers Date: Sat, 13 Nov 2021 21:29:12 +0200 Organization: LINKOV.NET Message-ID: <86k0hbam7r.fsf@mail.linkov.net> References: <87lf1sw6ji.fsf@gmail.com> <86h7cgdk4v.fsf@mail.linkov.net> <87ee7kvshn.fsf@gmail.com> <87a6i7x5iq.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2536"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 51809@debbugs.gnu.org To: Matthias Meulien Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 13 20:31:20 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mlykC-0000WB-Bk for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Nov 2021 20:31:20 +0100 Original-Received: from localhost ([::1]:46108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlykB-0006RO-G8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Nov 2021 14:31:19 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlyju-0006QO-H7 for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 14:31:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlyju-00041B-83 for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 14:31:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mlyju-0006f1-57 for bug-gnu-emacs@gnu.org; Sat, 13 Nov 2021 14:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Nov 2021 19:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51809 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51809-submit@debbugs.gnu.org id=B51809.163683181325540 (code B ref 51809); Sat, 13 Nov 2021 19:31:02 +0000 Original-Received: (at 51809) by debbugs.gnu.org; 13 Nov 2021 19:30:13 +0000 Original-Received: from localhost ([127.0.0.1]:48102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlyj7-0006dr-Ho for submit@debbugs.gnu.org; Sat, 13 Nov 2021 14:30:13 -0500 Original-Received: from relay8-d.mail.gandi.net ([217.70.183.201]:56395) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mlyj5-0006cT-Hf for 51809@debbugs.gnu.org; Sat, 13 Nov 2021 14:30:12 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 25C7E1BF205; Sat, 13 Nov 2021 19:30:03 +0000 (UTC) In-Reply-To: <87a6i7x5iq.fsf@gmail.com> (Matthias Meulien's message of "Sat, 13 Nov 2021 19:41:17 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219834 Archived-At: >>> (...) 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)))))