Commit 46795335 authored by Dave Love's avatar Dave Love
Browse files

(hide-region-body): Bind

outline-view-change-hook to nil while making repeated calls to
outline-flag-region.  Run it once at the end.
(hide-other, hide-sublevels, show-children): Likewise.
parent 6480a693
...@@ -496,21 +496,26 @@ Show the heading too, if it is currently invisible." ...@@ -496,21 +496,26 @@ Show the heading too, if it is currently invisible."
(defun hide-region-body (start end) (defun hide-region-body (start end)
"Hide all body lines in the region, but not headings." "Hide all body lines in the region, but not headings."
(save-excursion ;; Nullify the hook to avoid repeated calls to `outline-flag-region'
(save-restriction ;; wasting lots of time running `lazy-lock-fontify-after-outline'
(narrow-to-region start end) ;; and run the hook finally.
(goto-char (point-min)) (let (outline-view-change-hook)
(if (outline-on-heading-p) (save-excursion
(outline-end-of-heading)) (save-restriction
(while (not (eobp)) (narrow-to-region start end)
(outline-flag-region (point) (goto-char (point-min))
(progn (outline-next-preface) (point)) t) (if (outline-on-heading-p)
(if (not (eobp)) (outline-end-of-heading))
(progn (while (not (eobp))
(forward-char (outline-flag-region (point)
(if (looking-at "\n\n") (progn (outline-next-preface) (point)) t)
2 1)) (if (not (eobp))
(outline-end-of-heading))))))) (progn
(forward-char
(if (looking-at "\n\n")
2 1))
(outline-end-of-heading)))))))
(run-hooks 'outline-view-change-hook))
(defun show-all () (defun show-all ()
"Show all of the text in the buffer." "Show all of the text in the buffer."
...@@ -540,31 +545,36 @@ Show the heading too, if it is currently invisible." ...@@ -540,31 +545,36 @@ Show the heading too, if it is currently invisible."
(if (< levels 1) (if (< levels 1)
(error "Must keep at least one level of headers")) (error "Must keep at least one level of headers"))
(setq levels (1- levels)) (setq levels (1- levels))
(save-excursion (let (outline-view-change-hook)
(goto-char (point-min)) (save-excursion
;; Keep advancing to the next top-level heading. (goto-char (point-min))
(while (or (and (bobp) (outline-on-heading-p)) ;; Keep advancing to the next top-level heading.
(outline-next-heading)) (while (or (and (bobp) (outline-on-heading-p))
(let ((end (save-excursion (outline-end-of-subtree) (point)))) (outline-next-heading))
;; Hide everything under that. (let ((end (save-excursion (outline-end-of-subtree) (point))))
(outline-flag-region (point) end t) ;; Hide everything under that.
;; Show the first LEVELS levels under that. (outline-flag-region (point) end t)
(if (> levels 0) ;; Show the first LEVELS levels under that.
(show-children levels)) (if (> levels 0)
;; Move to the next, since we already found it. (show-children levels))
(goto-char end))))) ;; Move to the next, since we already found it.
(goto-char end)))))
(run-hooks 'outline-view-change-hook))
(defun hide-other () (defun hide-other ()
"Hide everything except current body and parent and top-level headings." "Hide everything except current body and parent and top-level headings."
(interactive) (interactive)
(hide-sublevels 1) (hide-sublevels 1)
(save-excursion (let (outline-view-change-hook)
(outline-back-to-heading t) (save-excursion
(show-entry) (outline-back-to-heading t)
(while (condition-case nil (progn (outline-up-heading 1) t) (error nil)) (show-entry)
(outline-flag-region (1- (point)) (while (condition-case nil (progn (outline-up-heading 1) t)
(save-excursion (forward-line 1) (point)) (error nil))
nil)))) (outline-flag-region (1- (point))
(save-excursion (forward-line 1) (point))
nil))))
(run-hooks 'outline-view-change-hook))
(defun outline-flag-subtree (flag) (defun outline-flag-subtree (flag)
(save-excursion (save-excursion
...@@ -610,27 +620,29 @@ Default is enough to cause the following heading to appear." ...@@ -610,27 +620,29 @@ Default is enough to cause the following heading to appear."
(if (eobp) (if (eobp)
1 1
(max 1 (- (funcall outline-level) start-level))))))) (max 1 (- (funcall outline-level) start-level)))))))
(save-excursion (let (outline-view-change-hook)
(save-restriction (save-excursion
(outline-back-to-heading) (save-restriction
(setq level (+ level (funcall outline-level))) (outline-back-to-heading)
(narrow-to-region (point) (setq level (+ level (funcall outline-level)))
(progn (outline-end-of-subtree) (narrow-to-region (point)
(if (eobp) (point-max) (1+ (point))))) (progn (outline-end-of-subtree)
(goto-char (point-min)) (if (eobp) (point-max) (1+ (point)))))
(while (and (not (eobp)) (goto-char (point-min))
(progn (while (and (not (eobp))
(outline-next-heading) (progn
(not (eobp)))) (outline-next-heading)
(if (<= (funcall outline-level) level) (not (eobp))))
(save-excursion (if (<= (funcall outline-level) level)
(outline-flag-region (save-excursion (save-excursion
(forward-char -1) (outline-flag-region (save-excursion
(if (bolp) (forward-char -1)
(forward-char -1)) (if (bolp)
(point)) (forward-char -1))
(progn (outline-end-of-heading) (point)) (point))
nil))))))) (progn (outline-end-of-heading) (point))
nil)))))))
(run-hooks 'outline-view-change-hook))
(defun outline-up-heading (arg) (defun outline-up-heading (arg)
"Move to the heading line of which the present line is a subheading. "Move to the heading line of which the present line is a subheading.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment