diff options
author | Yuan Fu <casouri@gmail.com> | 2020-10-19 10:45:14 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2020-10-19 10:45:14 +0200 |
commit | 422fdabe7bcaa9eac9aa5ae688ccf9f30cf6765c (patch) | |
tree | 117362464f2f46d4810e28d3e00c2b4a6137062f /lisp/outline.el | |
parent | 9f9e3bc24b1ee44b13ebb41293f6dd012ce2298e (diff) | |
download | emacs-422fdabe7bcaa9eac9aa5ae688ccf9f30cf6765c.tar.gz emacs-422fdabe7bcaa9eac9aa5ae688ccf9f30cf6765c.tar.bz2 emacs-422fdabe7bcaa9eac9aa5ae688ccf9f30cf6765c.zip |
Handle "Before first headings" error in outline-cycle
* lisp/outline.el (outline-before-first-heading): New error.
(outline-back-to-heading): Signal the new error.
(outline-cycle): Ignore the error.
(outline-cycle-buffer): Simply pass 1 to 'outline-hide-sublevels'
(bug#41130).
Diffstat (limited to 'lisp/outline.el')
-rw-r--r-- | lisp/outline.el | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/lisp/outline.el b/lisp/outline.el index a4ce9afb445..b9806bc187e 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -402,6 +402,8 @@ at the end of the buffer." If POS is nil, use `point' instead." (eq (get-char-property (or pos (point)) 'invisible) 'outline)) +(define-error 'outline-before-first-heading "Before first heading") + (defun outline-back-to-heading (&optional invisible-ok) "Move to previous heading line, or beg of this line if it's a heading. Only visible heading lines are considered, unless INVISIBLE-OK is non-nil." @@ -412,7 +414,7 @@ Only visible heading lines are considered, unless INVISIBLE-OK is non-nil." (while (not found) (or (re-search-backward (concat "^\\(?:" outline-regexp "\\)") nil t) - (error "Before first heading")) + (signal 'outline-before-first-heading nil)) (setq found (and (or invisible-ok (not (outline-invisible-p))) (point))))) (goto-char found) @@ -1167,19 +1169,21 @@ Return either 'hide-all, 'headings-only, or 'show-all." `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")))) + (condition-case nil + (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"))) + (outline-before-first-heading nil))) (defvar-local outline--cycle-buffer-state 'show-all "Internal variable used for tracking buffer cycle state.") @@ -1189,13 +1193,7 @@ Return either 'hide-all, 'headings-only, or 'show-all." (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))))) + (outline-hide-sublevels 1) (setq outline--cycle-buffer-state 'top-level) (message "Top level headings")) ('top-level |