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: Mon, 29 Nov 2021 19:06:40 +0200 Organization: LINKOV.NET Message-ID: <86y256uc0v.fsf@mail.linkov.net> 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> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34459"; 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 Mon Nov 29 18:23:42 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 1mrkNP-0008ed-RI for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 29 Nov 2021 18:23:39 +0100 Original-Received: from localhost ([::1]:33940 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mrkNN-0005DL-Qf for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 29 Nov 2021 12:23:38 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mrkMr-0004lE-Ce for bug-gnu-emacs@gnu.org; Mon, 29 Nov 2021 12:23:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mrkMo-0002Ye-6e for bug-gnu-emacs@gnu.org; Mon, 29 Nov 2021 12:23:04 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mrkMo-0003xK-3n for bug-gnu-emacs@gnu.org; Mon, 29 Nov 2021 12:23: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: Mon, 29 Nov 2021 17:23: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.163820657315180 (code B ref 51809); Mon, 29 Nov 2021 17:23:02 +0000 Original-Received: (at 51809) by debbugs.gnu.org; 29 Nov 2021 17:22:53 +0000 Original-Received: from localhost ([127.0.0.1]:39218 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mrkMf-0003wh-9f for submit@debbugs.gnu.org; Mon, 29 Nov 2021 12:22:53 -0500 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:39473) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mrkMQ-0003w2-IV for 51809@debbugs.gnu.org; Mon, 29 Nov 2021 12:22:39 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id B9717E000B; Mon, 29 Nov 2021 17:22:31 +0000 (UTC) In-Reply-To: <878rxrmy7q.fsf@gmail.com> (Matthias Meulien's message of "Sun, 14 Nov 2021 00:29:13 +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:221045 Archived-At: 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))