From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Paul W. Rankin" via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#41198: 28.0.50; heading cycling command for outline Date: Sun, 15 Nov 2020 15:50:31 +1000 Message-ID: <73ee5b37b78bdc410554aebbc7a4c31b@skeletons.cc> References: <452A6049-893A-4E7E-8349-541D276FAD19@gmail.com> Reply-To: "Paul W. Rankin" Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7088"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Purely Mail via Roundcube/1.4.7 To: 41198@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 15 06:51:28 2020 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 1keAwg-0001h1-Mv for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Nov 2020 06:51:27 +0100 Original-Received: from localhost ([::1]:38324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1keAwf-0001yF-Ar for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 15 Nov 2020 00:51:25 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1keAwI-0001y1-Rr for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2020 00:51:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40870) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1keAwI-0006ec-I7 for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2020 00:51:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1keAwI-0005xD-GO for bug-gnu-emacs@gnu.org; Sun, 15 Nov 2020 00:51:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <452A6049-893A-4E7E-8349-541D276FAD19@gmail.com> Resent-From: "Paul W. Rankin" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Nov 2020 05:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41198 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 41198-submit@debbugs.gnu.org id=B41198.160541944222861 (code B ref 41198); Sun, 15 Nov 2020 05:51:02 +0000 Original-Received: (at 41198) by debbugs.gnu.org; 15 Nov 2020 05:50:42 +0000 Original-Received: from localhost ([127.0.0.1]:52416 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1keAvy-0005wf-Gb for submit@debbugs.gnu.org; Sun, 15 Nov 2020 00:50:42 -0500 Original-Received: from sendmail.purelymail.com ([34.202.193.197]:55898) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1keAvv-0005wR-QY for 41198@debbugs.gnu.org; Sun, 15 Nov 2020 00:50:41 -0500 DKIM-Signature: a=rsa-sha256; b=FNIqOMHY7tEF5F4AyNSX9anw0IQoaVnqKmyDB/DedPXMhbPWVYAbD03lo9aBHfk+/3XYflgbUH8O1oAhQ94E/2VdSijIcobO53Zv6Lb6x9kczMUrvkb4T0khNLJFirZBW96j5ws2GFW2pzMgvpOiXkhj1veXCsu9vdpgSiN6ri4Q5okKlB9yzEfgV48nocUS1wFXi9Um50p8UQS5EK5M65AF9VfonStie2Y+6uuhcjFaVRU/EXLAaFL9XTyIr4D2wIbsXg9royu1MzxtOTw/1lndtov3skkvLJrUAqiUNC2mtoSv3Jixtwk0MvkTgEds4aPZV4HVclnTtCHIVtHkFw==; s=purelymail1; d=paulwrankin.com; v=1; bh=ckQZp96dGn+F8n0sf+F2bwCnGECSxZkg6SIyOyyUy1I=; h=Received:From:To; DKIM-Signature: a=rsa-sha256; b=pFK4r/2yOOlGhhQd6w9vW7DDonkOpfzRHwsffSkjzsjEfPXn5GTe/ZZ3FYO6SgUpTTIX2256CwgZ0GatyRoofBI3+eSOgWHVTxOgSMEmyvEUYlmqLA70sB4pFbU2YBBrbrmAPDWX32d7S/0WkHE3laycKHj611RKS+BF7kjfrxBZ5Tw7uiEnm15UqW5iynNAKF5gaMiqckoLqYAbN34f0sLRBBbkD433NeZlUN+FRijXdR7D24Mcgz3BMAie0NGwhJirHw8pfH6dk7lHYhsBlhzSayYO8paNWjtFkPdgfA2X7iHFIA+O72M8XUszn74lPkqV32PwhdQ22hB5GykxBQ==; s=purelymail1; d=purelymail.com; v=1; bh=ckQZp96dGn+F8n0sf+F2bwCnGECSxZkg6SIyOyyUy1I=; h=Feedback-ID:Received:From:To; Feedback-ID: 791:353:null:purelymail X-Pm-Original-To: 41198@debbugs.gnu.org Original-Received: by ip-172-30-0-247.ec2.internal (JAMES SMTP Server ) with ESMTPA ID -2077965078 for <41198@debbugs.gnu.org>; Sun, 15 Nov 2020 05:50:32 +0000 (UTC) X-Sender: hello@paulwrankin.com X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail 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:193349 Archived-At: Hello, Sorry to revisit this but there are a few edge cases with the new=20 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=20 final subheading ends at the end-of-subtree - 1. This means that the=20 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=20 outline in a top-level state, if the user navigates to the last=20 top-level heading and presses TAB for outline-cycle, the expectation is=20 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=E2=80=99t work: what if the= re is ;; one folded subheading? - ((and (eq (overlay-end (car ov-list)) end) + ((and (<=3D 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=20 'outline are not guaranteed to be overlays for collapsed outline=20 headings. This is true if a lisp program has used outline-flag-region=20 for something other than an outline heading. I had done this for=20 collapsing a major mode's notes markup: [[ here's a note ]] -> [[...]] This is simply solved by testing each overlay-start with=20 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)=20 '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=E2=80=99t work: what if the= re is ;; one folded subheading? ((and (<=3D 0 (- end (overlay-end (car ov-list))) 1) n.b. This will fail if the user/program has changed=20 outline-heading-end-regexp to have multiple newlines, because=20 outline-on-heading-p only checks if it's looking at outline-regexp from=20 the beginning of that line. 3. When a buffer contains outline headings of only < 1 (e.g. all=20 headings are level 3) calling outline-cycle-buffer to show only=20 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=20 headings before allowing cycling to top-level. --=20 Paul W. Rankin https://www.paulwrankin.com The single best thing you can do for the world is delete your social=20 media accounts.