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: 41198@debbugs.gnu.org
Subject: bug#41198: 28.0.50; heading cycling command for outline
Date: Sun, 15 Nov 2020 15:50:31 +1000	[thread overview]
Message-ID: <73ee5b37b78bdc410554aebbc7a4c31b@skeletons.cc> (raw)
In-Reply-To: <452A6049-893A-4E7E-8349-541D276FAD19@gmail.com>

Hello,

Sorry to revisit this but there are a few edge cases with the new 
outline-cycle and outline-cycle-buffer commands...


1. In command outline-hide-sublevels#L901 we see:

       ;; Finally unhide any trailing newline.
       (goto-char (point-max))
       (if (and (bolp) (not (bobp)) (outline-invisible-p (1- (point))))
           (outline-flag-region (1- (point)) (point) nil))))

When calling this function the overlay created to hide the buffer's 
final subheading ends at the end-of-subtree - 1. This means that the 
following code in outline--cycle-state#L1130 fails with an off-by-1:

             ((and (eq (overlay-end (car ov-list)) end)
                   (eq (overlay-start (car ov-list)) heading-end))

The result of this is that when calling outline-cycle-buffer to set the 
outline in a top-level state, if the user navigates to the last 
top-level heading and presses TAB for outline-cycle, the expectation is 
to show that heading's subheadings, but the result is show all.

To fix, if leaving outline-hide-sublevels alone, a workaround would be:

diff --git a/lisp/outline.el b/lisp/outline.el
index 47e6528859..054d2cb62b 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1127,7 +1127,7 @@ outline--cycle-state
        (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)
+            ((and (<= 0 (- end (overlay-end (car ov-list))) 1)
                    (eq (overlay-start (car ov-list)) heading-end))
               'hide-all)
              (t 'headings-only)))))


2. This may sound strange, but overlays with an invisible property of 
'outline are not guaranteed to be overlays for collapsed outline 
headings. This is true if a lisp program has used outline-flag-region 
for something other than an outline heading. I had done this for 
collapsing a major mode's notes markup:

     [[ here's a note ]] -> [[...]]

This is simply solved by testing each overlay-start with 
outline-on-heading-p:

diff --git a/lisp/outline.el b/lisp/outline.el
index 054d2cb62b..a05cf87d4e 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1121,10 +1121,15 @@ 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)
+      (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 ((eq ov-list nil) 'show-all)
              ;; (eq (length ov-list) 1) wouldn’t work: what if there is
              ;; one folded subheading?
              ((and (<= 0 (- end (overlay-end (car ov-list))) 1)

n.b. This will fail if the user/program has changed 
outline-heading-end-regexp to have multiple newlines, because 
outline-on-heading-p only checks if it's looking at outline-regexp from 
the beginning of that line.


3. When a buffer contains outline headings of only < 1 (e.g. all 
headings are level 3) calling outline-cycle-buffer to show only 
top-level headings will results in an unexpected buffer state of:

     ...

This is fixed with a simple test of whether the buffer has top-level 
headings before allowing cycling to top-level.


-- 
Paul W. Rankin
https://www.paulwrankin.com

The single best thing you can do for the world is delete your social 
media accounts.





  parent reply	other threads:[~2020-11-15  5:50 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 ` Paul W. Rankin via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2020-11-16 21:59   ` bug#41198: 28.0.50; " Lars Ingebrigtsen
2020-11-17  2:47     ` Paul W. Rankin via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=73ee5b37b78bdc410554aebbc7a4c31b@skeletons.cc \
    --to=bug-gnu-emacs@gnu.org \
    --cc=41198@debbugs.gnu.org \
    --cc=hello@paulwrankin.com \
    /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).