From: Yuan Fu <casouri@gmail.com>
To: Stefan Kangas <stefan@marxist.se>
Cc: 41130@debbugs.gnu.org, 41198@debbugs.gnu.org
Subject: bug#41130: bug#41198: 27.0.60; [PATCH] heading cycling command for outline
Date: Tue, 19 May 2020 21:37:26 -0400 [thread overview]
Message-ID: <92D944EF-6BF9-4635-AC05-4B51B386D5C7@gmail.com> (raw)
In-Reply-To: <CADwFkmn-iisoE7x7xH5sXG4AEH=qx6qS2vq26cuU3X38xxkZWQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3233 bytes --]
> On May 19, 2020, at 6:36 PM, Stefan Kangas <stefan@marxist.se> wrote:
>
> Yuan Fu <casouri@gmail.com> writes:
>
>>> In Bug#41130, I also suggest to add the same keybinding as in org-mode:
>>> TAB and S-TAB. Could you add such keybindings to outline-mode-map in
>>> your patch?
>>
>> It seems that the outline-mode bindings all live under C-c. Maybe C-c
>> TAB and C-c S-TAB? Should I ask on emacs-devel for for suggestions?
>
> I think it is better to use the same keys as org-mode, since one
> important motivation for this feature is precisely to align the
> outline-mode keybindings with org-mode. This aspect would be
> significantly diminished by using other keys, IMHO.
>
> My impression was that also there was consensus around (or at least no
> objections to) that idea the last time we discussed it. I would
> therefore propose to just add TAB and S-TAB to the patch, but allow a
> week or two before pushing to give others a chance to comment here.
>
> But, if you really want to, of course you could also ask on emacs-devel.
> Worst case, we get to have another round of bikeshedding. ;-)
I added TAB and S-TAB bindings. Though S-TAB appears to be <backtab> on my machine (Mac) for both terminal and GUI so I bound that instead. Is that so for other machines? To reduce the possible allergy, I made the TAB binding conditional—only invokes outline-cycle when point is on a heading.
A minor thing: if the motivation is to align with Org mode, should I change the text message to align with Org mode? It prints “show all”, “hide all”, etc (because they make sense), but Org mode prints stuff like “CHILDREN”, “SUBTREE”, etc.
>
>>> I think we also need ChangeLog in the commit message, an entry in NEWS,
>>> and updates to the manual.
>>
>> I updated NEWS and the manual. For ChangeLog, I thought that’s
>> automatically generated from commit messages?
>
> That is my understanding too.
>
> But I only saw a diff attached, not a patch with a commit message. That
> is what I tried to say, but I could've been more clear.
>
> (CONTRIBUTE suggests using `git format-patch -1' to email a patch, which
> includes the commit message.)
Ah sorry, I switched to a new way to generate patches and didn’t notice that the commit message is gone. It is included this time.
>
>> +@findex outline-cycle
>> +@findex outline-cycle-buffer
>> + Outline also provides two convenience commands to cycle the
>> +visibility of each heading and the whole buffer. @code{outline-cycle}
>> +cycles the current heading between "hide all", "subheadings", and
>> +"show all" state. @code{outline-cycle-buffer} cycles the whole buffer
>> +between "only top-level headings", "all headings and subheadings", and
>> +"show all" states.
> [...]
>> +*** New commands to cycle heading visibility.
>> +'outline-cycle' cycles the current heading between "hide all",
>> +"subheadings", and "show all" state. 'outline-cycle-buffer' cycles the
>> +whole buffer between "only top-level headings", "all headings and
>> +subheadings", and "show all" states.
>
> Looks good to me (but should refer to the above keybindings if they're
> added).
Yuan
[-- Attachment #2: outline.patch --]
[-- Type: application/octet-stream, Size: 6151 bytes --]
From 243d6dec5c33c7add2fd12fe0da3e49a134cf0a9 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Sun, 10 May 2020 17:10:32 -0400
Subject: [PATCH] Add cycling commands to outline
* lisp/outline.el (outline--cycle-state, outline-has-subheading-p,
outline-cycle, outline-cycle-buffer): New functions.
(outline-mode-map): Add key bindings for the two new commands.
(outline--cycle-buffer-state): New variable.
* doc/emacs/text.text (Outline Visibility): Add 'outline-cycle' and
'outline-cycle-buffer'.
* etc/NEWS (Outline): Record the change.
---
doc/emacs/text.texi | 10 ++++++
etc/NEWS | 9 ++++++
lisp/outline.el | 77 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+)
diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi
index 281e24421c..9c2822ce15 100644
--- a/doc/emacs/text.texi
+++ b/doc/emacs/text.texi
@@ -1207,6 +1207,16 @@ Outline Visibility
it completely reveals all the @var{n} top levels and the body lines
before the first heading.
+@findex outline-cycle
+@findex outline-cycle-buffer
+ Outline also provides two convenience commands to cycle the
+visibility of each section and the whole buffer. Typing @kbd{TAB} on
+a heading invokes @code{outline-cycle}, which cycles the current
+section between "hide all", "subheadings", and "show all" state.
+Typing @kbd{S-TAB} invokes @code{outline-cycle-buffer}, which cycles
+the whole buffer between "only top-level headings", "all headings and
+subheadings", and "show all" states.
+
@anchor{Outline Search}
@findex reveal-mode
@vindex search-invisible
diff --git a/etc/NEWS b/etc/NEWS
index 025d5c14a7..72057af94d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -288,6 +288,15 @@ prefix on the Subject line in various languages.
These new navigation commands are bound to 'n' and 'p' in
'apropos-mode'.
+** Outline
+
+*** New commands to cycle heading visibility
+
+Typing 'TAB' on a heading cycles the current section between "hide
+all", "subheadings", and "show all" state. Typing 'S-TAB' anywhere in
+the buffer cycles the whole buffer between "only top-level headings",
+"all headings and subheadings", and "show all" states.
+
\f
* New Modes and Packages in Emacs 28.1
diff --git a/lisp/outline.el b/lisp/outline.el
index 28ea8a86e6..0d792dd28c 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -179,6 +179,12 @@ outline-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-c" outline-mode-prefix-map)
(define-key map [menu-bar] outline-mode-menu-bar-map)
+ ;; Only takes effect if the point is on a heading.
+ (define-key map (kbd "TAB")
+ `(menu-item "" outline-cycle
+ :filter ,(lambda (cmd)
+ (when (outline-on-heading-p) cmd))))
+ (define-key map (kbd "<backtab>") #'outline-cycle-buffer)
map))
(defvar outline-font-lock-keywords
@@ -1118,6 +1124,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
+ "Internal 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)
--
2.26.1
[-- Attachment #3: Type: text/plain, Size: 1 bytes --]
next prev parent reply other threads:[~2020-05-20 1:37 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 [this message]
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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=92D944EF-6BF9-4635-AC05-4B51B386D5C7@gmail.com \
--to=casouri@gmail.com \
--cc=41130@debbugs.gnu.org \
--cc=41198@debbugs.gnu.org \
--cc=stefan@marxist.se \
/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 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.