unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Paul W. Rankin" via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 41198@debbugs.gnu.org
Subject: bug#41198: 28.0.50; heading cycling command for outline
Date: Tue, 17 Nov 2020 12:47:33 +1000	[thread overview]
Message-ID: <ae8446194f8c94617aa392a7825aebc4@skeletons.cc> (raw)
In-Reply-To: <87a6vhvu7g.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 899 bytes --]

On 2020-11-17 07:59, Lars Ingebrigtsen wrote:
> 
> The patches look OK to me, but look like they've been slightly mangled
> during transmission, so could you include them as a single patch as an
> attachment?  (And adding a ChangeLog-format text would also be nice.)

2x patches attached with changelog.

I took a more precise approach with outline--cycle-state, where the +1 
case is only handled when the subtree end is point-max, otherwise the 
overlay-end must equal end of subtree point in all other cases.

I rewrote outline-cycle-buffer; it now first checks that the buffer has 
top-level headings before attempting to show only top-level headings, 
thus avoiding the disconcerting state where all buffer content is 
reduced to "...". If buffer has no outline headings, we still get an 
annoying message toggle from "All headings" to "Show all".

Also this avoids using pcase, which is awful.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-outline.el-better-handing-of-outline-overlays-w.patch --]
[-- Type: text/x-diff; name=0001-lisp-outline.el-better-handing-of-outline-overlays-w.patch, Size: 1902 bytes --]

From c589e4055aad93aceefe0ebb3281c008c82a0b46 Mon Sep 17 00:00:00 2001
From: "Paul W. Rankin" <pwr@skeletons.cc>
Date: Tue, 17 Nov 2020 12:42:47 +1000
Subject: [PATCH 1/2] * lisp/outline.el: better handing of outline overlays
 when cycling

(outline--cycle-state): only consider outline overlays that are on
  outline headings; when subtree end is point-max, return overlay-end +1
  because final subtree overlay only reaches point-max -1.
---
 lisp/outline.el | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/lisp/outline.el b/lisp/outline.el
index 47e6528859..8cc8a3cd89 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1121,14 +1121,19 @@ outline--cycle-state
       (setq heading-end (point))
       (outline-end-of-subtree)
       (setq end (point))
-      (setq ov-list (cl-remove-if-not
-                     (lambda (o) (eq (overlay-get o 'invisible) 'outline))
-                     (overlays-in start end)))
-      (cond ((eq ov-list nil) 'show-all)
-            ;; (eq (length ov-list) 1) wouldn’t work: what if there is
-            ;; one folded subheading?
-            ((and (eq (overlay-end (car ov-list)) end)
-                  (eq (overlay-start (car ov-list)) heading-end))
+      (setq ov-list
+            (seq-filter
+             (lambda (o)
+               (and (eq (overlay-get o 'invisible) 'outline)
+                    (save-excursion
+                      (goto-char (overlay-start o))
+                      (outline-on-heading-p t))))
+             (overlays-in start end)))
+      (cond ((null ov-list) 'show-all)
+            ((and (or (= end (point-max)
+                         (1+ (overlay-end (car ov-list))))
+                      (= (overlay-end (car ov-list)) end))
+                  (= (overlay-start (car ov-list)) heading-end))
              'hide-all)
             (t 'headings-only)))))
 
-- 
2.29.2


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-lisp-outline.el-avoid-hiding-all-buffer-content.patch --]
[-- Type: text/x-diff; name=0002-lisp-outline.el-avoid-hiding-all-buffer-content.patch, Size: 2252 bytes --]

From 680210c64545389502e7a2d05ec0c98e7b25c24b Mon Sep 17 00:00:00 2001
From: "Paul W. Rankin" <pwr@skeletons.cc>
Date: Tue, 17 Nov 2020 12:44:44 +1000
Subject: [PATCH 2/2] * lisp/outline.el: avoid hiding all buffer content

(outline-cycle-buffer): check that buffer has top-level headings
  before calling outline-hide-sublevels 1 thus preventing disconcerting
  buffer state of content reduced to single "..."
---
 lisp/outline.el | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/lisp/outline.el b/lisp/outline.el
index 8cc8a3cd89..9b11b86b9d 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1173,20 +1173,30 @@ outline--cycle-buffer-state
 (defun outline-cycle-buffer ()
   "Cycle the whole buffer like in `outline-cycle'."
   (interactive)
-  (pcase outline--cycle-buffer-state
-    ('show-all
-     (outline-hide-sublevels 1)
-     (setq outline--cycle-buffer-state 'top-level)
-     (message "Top level headings"))
-    ('top-level
-     (outline-show-all)
-     (outline-hide-region-body (point-min) (point-max))
-     (setq outline--cycle-buffer-state 'all-heading)
-     (message "All headings"))
-    ('all-heading
-     (outline-show-all)
-     (setq outline--cycle-buffer-state 'show-all)
-     (message "Show all"))))
+  (let (has-top-level)
+    (save-excursion
+      (goto-char (point-min))
+      (while (not (or has-top-level (eobp)))
+        (when (outline-on-heading-p t)
+          (when (= (funcall outline-level) 1)
+            (setq has-top-level t)))
+        (outline-next-heading)))
+    (cond
+     ((and (eq outline--cycle-buffer-state 'show-all)
+           has-top-level)
+      (outline-hide-sublevels 1)
+      (setq outline--cycle-buffer-state 'top-level)
+      (message "Top level headings"))
+     ((or (eq outline--cycle-buffer-state 'show-all)
+          (eq outline--cycle-buffer-state 'top-level))
+      (outline-show-all)
+      (outline-hide-region-body (point-min) (point-max))
+      (setq outline--cycle-buffer-state 'all-heading)
+      (message "All headings"))
+     (t
+      (outline-show-all)
+      (setq outline--cycle-buffer-state 'show-all)
+      (message "Show all")))))
 
 (provide 'outline)
 (provide 'noutline)
-- 
2.29.2


  reply	other threads:[~2020-11-17  2:47 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12  1:52 bug#41198: 27.0.60; [PATCH] heading cycling command for outline Yuan Fu
2020-05-19  2:45 ` bug#41130: " Stefan Kangas
2020-05-19 18:31   ` Yuan Fu
2020-05-19 22:36     ` Stefan Kangas
2020-05-20  1:37       ` Yuan Fu
2020-05-07 20:53         ` bug#41130: outline-mode: Add new commands like org-cycle and org=global-cycle Stefan Kangas
2020-05-07 21:03           ` Stefan Kangas
2020-05-12 22:52           ` Juri Linkov
2020-05-19  3:00             ` bug#41130: outline-mode: Add new commands like org-cycle and org-global-cycle Stefan Kangas
2020-05-19 22:04               ` Juri Linkov
2020-05-24  7:29                 ` Bastien
2020-05-24 14:35                   ` Eli Zaretskii
2020-05-24 16:26                     ` Bastien
2020-05-24 16:39                       ` Eli Zaretskii
2020-05-24 17:09                         ` Dmitry Gutov
2020-05-25  8:50                           ` Bastien
2020-06-23 22:27                             ` Basil L. Contovounesios
2020-09-06  8:22                               ` Bastien
2020-05-13  7:13           ` bug#41130: outline-mode: Add new commands like org-cycle and org=global-cycle Tassilo Horn
2020-05-13 16:54             ` Robert Pluim
2020-05-13 18:51               ` Tassilo Horn
2020-05-19  3:06             ` Stefan Kangas
2020-05-20 14:12           ` bug#41130: bug#41198: 27.0.60; [PATCH] heading cycling command for outline Howard Melman
2020-05-20 21:34             ` Stefan Kangas
2020-05-24  7:26           ` bug#41130: outline-mode: Add new commands like org-cycle and org=global-cycle Bastien
2020-05-24 14:49             ` Philip K.
2020-05-24 16:30               ` Bastien
2020-08-17 22:30           ` bug#41130: outline-mode: Add new commands like org-cycle and org-global-cycle Howard Melman
2020-08-18  4:30             ` Eli Zaretskii
2020-10-13  3:16         ` bug#41130: bug#41198: 27.0.60; [PATCH] heading cycling command for outline Lars Ingebrigtsen
2020-10-13 13:16           ` bug#41198: " Yuan Fu
2020-10-14 19:24           ` Juri Linkov
2020-10-15  7:02             ` Lars Ingebrigtsen
2020-10-15  7:52               ` Robert Pluim
2020-10-15 23:33             ` bug#41198: " Yuan Fu
2020-10-16  3:12               ` Yuan Fu
2020-10-16  4:59               ` bug#41198: " Lars Ingebrigtsen
2020-10-16  8:25                 ` bug#41130: " Robert Pluim
2020-10-16  8:20               ` Juri Linkov
2020-10-16 19:27                 ` Yuan Fu
2020-10-17  6:36                   ` Lars Ingebrigtsen
2020-10-17 20:30                     ` Juri Linkov
2020-10-18  0:28                       ` bug#41198: " Yuan Fu
2020-10-18  8:36                         ` Lars Ingebrigtsen
2020-10-18 20:23                           ` Yuan Fu
2020-10-19  8:45                             ` Lars Ingebrigtsen
2020-11-15  5:50 ` bug#41198: 28.0.50; " Paul W. Rankin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-11-16 21:59   ` Lars Ingebrigtsen
2020-11-17  2:47     ` Paul W. Rankin via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2020-11-24  5:09       ` Lars Ingebrigtsen
2020-11-25 19:24         ` Juri Linkov
2020-11-26 10:13           ` Lars Ingebrigtsen
2020-11-27  8:29             ` Juri Linkov
2020-11-27 18:39               ` Drew Adams
2020-11-28  1:58               ` Paul W. Rankin via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-12-10 19:08                 ` Howard Melman
2020-12-12 20:57                   ` Juri Linkov
2020-12-14 20:31                   ` Juri Linkov
2020-12-15  0:09                     ` Howard Melman
2020-12-15  3:46                     ` Pankaj Jangid
2020-12-15  9:10                       ` Juri Linkov
2020-12-15 10:42                         ` Pankaj Jangid
2020-12-15 20:23                           ` Juri Linkov
2020-12-16  4:02                             ` Pankaj Jangid

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae8446194f8c94617aa392a7825aebc4@skeletons.cc \
    --to=bug-gnu-emacs@gnu.org \
    --cc=41198@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=pwr@skeletons.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).