all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#41198: 27.0.60; [PATCH] heading cycling command for outline
@ 2020-05-12  1:52 Yuan Fu
  2020-05-19  2:45 ` bug#41130: " Stefan Kangas
  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
  0 siblings, 2 replies; 64+ messages in thread
From: Yuan Fu @ 2020-05-12  1:52 UTC (permalink / raw)
  To: 41198

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

Add two commands that cycles a heading (like that in Org mode) in outline-mode:

- outline-cycle: cycles between “hide all”, “sub headings” and “show all” state. They are called “FOLDED”, “CHILDREN”, “SUBTREE” in Org mode. 
- outline-cycle-buffer: cycles between “only top level headings”, “all headings”, “show all” states

Could this be useful?

Yuan


[-- Attachment #2: outline.patch --]
[-- Type: application/octet-stream, Size: 3350 bytes --]

diff --git a/lisp/outline.el b/lisp/outline.el
index 28ea8a86e6..99a24deed0 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1118,6 +1118,77 @@ outline-headers-as-kill
                     (insert "\n\n"))))))
           (kill-new (buffer-string)))))))
 
+(defun outline--cycle-state ()
+  "Return the cycle state of current heading.
+Return either 'hide-all, 'headings-only, or 'show-all."
+  (save-excursion
+    (let (start end ov-list heading-end)
+      (outline-back-to-heading)
+      (setq start (point))
+      (outline-end-of-heading)
+      (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))
+             'hide-all)
+            (t 'headings-only)))))
+
+(defun outline-has-subheading-p ()
+  "Return t if this heading has subheadings, nil otherwise."
+  (save-excursion
+    (outline-back-to-heading)
+    (< (save-excursion (outline-next-heading) (point))
+       (save-excursion (outline-end-of-subtree) (point)))))
+
+(defun outline-cycle ()
+  "Cycle between “hide all”, “headings only” and “show all”.
+
+“Hide all” means hide all subheadings and their bodies.
+“Headings only” means show sub headings but not their bodies.
+“Show all” means show all subheadings and their bodies."
+  (interactive)
+  (pcase (outline--cycle-state)
+    ('hide-all (if (outline-has-subheading-p)
+                   (progn (outline-show-children)
+                          (message "Only headings"))
+                 (outline-show-subtree)
+                 (message "Show all")))
+    ('headings-only (outline-show-subtree)
+                    (message "Show all"))
+    ('show-all (outline-hide-subtree)
+               (message "Hide all"))))
+
+(defvar-local outline--cycle-buffer-state 'show-all
+  "Interval variable used for tracking buffer cycle state.")
+
+(defun outline-cycle-buffer ()
+  "Cycle the whole buffer like in ‘outline-cycle’."
+  (interactive)
+  (pcase outline--cycle-buffer-state
+    ('show-all (save-excursion
+                 (let ((start-point (point)))
+                   (while (not (eq (point) start-point))
+                     (outline-up-heading 1))
+                   (outline-hide-sublevels
+                    (progn (outline-back-to-heading)
+                           (funcall 'outline-level)))))
+               (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"))))
+
 (provide 'outline)
 (provide 'noutline)
 

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





^ permalink raw reply related	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2020-12-16  4:02 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.