Implement 2-state cycling for headings without child subheadings (#54)

* Implement 2-state cycling for headings without child subheadings

* Move variable initialization into let binding
master
yuhan0 7 years ago committed by alphapapa
parent a7b3370648
commit cdb9c95e11
  1. 32
      outshine.el

@ -1601,13 +1601,14 @@ condition among the following:
- SHOW ALL: Show everything. - SHOW ALL: Show everything.
2. When point is at the beginning of a headline, rotate the 2. When point is at the beginning of a headline, rotate the
subtree starting at this line through 3 different states: subtree starting at this line through 2 or 3 different states:
- FOLDED: Only the main headline is shown. - FOLDED: Only the main headline is shown.
- CHILDREN: The main headline and its direct children are shown. - CHILDREN: The main headline and its direct children are shown.
From this state, you can move to one of the children From this state, you can move to one of the children
and zoom in further. and zoom in further.
* If the heading has no direct children, this state
is skipped entirely.
- SUBTREE: Show the entire subtree, including body text. - SUBTREE: Show the entire subtree, including body text.
3. Otherwise, execute `indent-relative', like TAB normally does. 3. Otherwise, execute `indent-relative', like TAB normally does.
@ -1631,12 +1632,14 @@ variables: `outshine-cycle-emulate-tab` and
;; At a heading: rotate between three different views ;; At a heading: rotate between three different views
((save-excursion (beginning-of-line 1) (looking-at outline-regexp)) ((save-excursion (beginning-of-line 1) (looking-at outline-regexp))
(outline-back-to-heading) (outline-back-to-heading)
(let ((goal-column 0) eoh eol eos) (let* ((goal-column 0)
;; First, some boundaries ;; First, some boundaries
(save-excursion (eol (save-excursion (outshine-next-line) (point)))
(save-excursion (outshine-next-line) (setq eol (point))) (eoh (save-excursion (outline-end-of-heading) (point)))
(outline-end-of-heading) (setq eoh (point)) (eos (save-excursion (outline-end-of-subtree) (point)))
(outline-end-of-subtree) (setq eos (point))) (has-children ;; nil if no other heading between heading and end of subtree
(save-excursion (end-of-line)
(re-search-forward outline-regexp eos 'noerror))))
;; Find out what to do next and set `this-command' ;; Find out what to do next and set `this-command'
(cond (cond
((= eos eoh) ((= eos eoh)
@ -1644,11 +1647,14 @@ variables: `outshine-cycle-emulate-tab` and
(outshine--cycle-message "EMPTY ENTRY")) (outshine--cycle-message "EMPTY ENTRY"))
((>= eol eos) ((>= eol eos)
;; Entire subtree is hidden in one line: open it ;; Entire subtree is hidden in one line: open it
(outline-show-entry) (if has-children
(outline-show-children) (progn
(outshine--cycle-message "CHILDREN") (outline-show-entry)
(setq (outline-show-children)
this-command 'outshine-cycle-children)) (outshine--cycle-message "CHILDREN")
(setq this-command 'outshine-cycle-children))
(outline-show-subtree)
(outshine--cycle-message "SUBTREE (NO CHILDREN)")))
((eq last-command 'outshine-cycle-children) ((eq last-command 'outshine-cycle-children)
;; We just showed the children, now show everything. ;; We just showed the children, now show everything.
(outline-show-subtree) (outline-show-subtree)

Loading…
Cancel
Save