From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matthias Meulien Newsgroups: gmane.emacs.bugs Subject: bug#51809: 29.0.50; [PATCH] Support for outline default state in Diff buffers Date: Sat, 11 Dec 2021 19:18:44 +0100 Message-ID: <87r1ajknsr.fsf@gmail.com> References: <87lf1sw6ji.fsf@gmail.com> <86h7cgdk4v.fsf@mail.linkov.net> <87ee7kvshn.fsf@gmail.com> <87a6i7x5iq.fsf@gmail.com> <86k0hbam7r.fsf@mail.linkov.net> <878rxrmy7q.fsf@gmail.com> <86y256uc0v.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29590"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 51809@debbugs.gnu.org To: Juri Linkov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 11 19:19:12 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 1mw6xj-0007Tf-MA for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Dec 2021 19:19:11 +0100 Original-Received: from localhost ([::1]:37108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mw6xi-0008Er-7P for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Dec 2021 13:19:10 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:38688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mw6xa-0008EL-Q0 for bug-gnu-emacs@gnu.org; Sat, 11 Dec 2021 13:19:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38412) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mw6xa-0001UL-Hf for bug-gnu-emacs@gnu.org; Sat, 11 Dec 2021 13:19:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mw6xa-00069J-DZ for bug-gnu-emacs@gnu.org; Sat, 11 Dec 2021 13:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Matthias Meulien Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Dec 2021 18:19: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.163924674023628 (code B ref 51809); Sat, 11 Dec 2021 18:19:02 +0000 Original-Received: (at 51809) by debbugs.gnu.org; 11 Dec 2021 18:19:00 +0000 Original-Received: from localhost ([127.0.0.1]:49958 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mw6xX-000692-Io for submit@debbugs.gnu.org; Sat, 11 Dec 2021 13:18:59 -0500 Original-Received: from mail-wm1-f41.google.com ([209.85.128.41]:54130) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mw6xT-00068S-0d for 51809@debbugs.gnu.org; Sat, 11 Dec 2021 13:18:57 -0500 Original-Received: by mail-wm1-f41.google.com with SMTP id y196so9102142wmc.3 for <51809@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) Original-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) In-Reply-To: <86y256uc0v.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 29 Nov 2021 19:06:40 +0200") 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:222133 Archived-At: --=-=-= Content-Type: text/plain Hi Juri, Juri Linkov 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 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 --=-=-=--