diff options
| author | Paul W. Rankin | 2020-11-24 06:08:59 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2020-11-24 06:08:59 +0100 |
| commit | 5a823a2a0c3eca60dd3939fba67df1bbe5a1b715 (patch) | |
| tree | 241c97c7e88bbca196bd5ff95a01e44ec371db1f | |
| parent | e2acb8fef4a40b94f7c43c7548453b997353e006 (diff) | |
| download | emacs-5a823a2a0c3eca60dd3939fba67df1bbe5a1b715.tar.gz emacs-5a823a2a0c3eca60dd3939fba67df1bbe5a1b715.zip | |
Handle outline overlays better when cycling in outline.el
* lisp/outline.el (outline--cycle-state): Only consider outline
overlays that are on outline headings; when subtree end is
point-max, return overlay-end +1 because final subtree overlay
only reaches point-max -1 (bug#41198).
(outline-cycle-buffer): Check that buffer has top-level headings
before calling outline-hide-sublevels 1 thus preventing
disconcerting buffer state of content reduced to single "..."
| -rw-r--r-- | lisp/outline.el | 59 |
1 files changed, 37 insertions, 22 deletions
diff --git a/lisp/outline.el b/lisp/outline.el index 47e6528859f..9b11b86b9d2 100644 --- a/lisp/outline.el +++ b/lisp/outline.el | |||
| @@ -1121,14 +1121,19 @@ Return either 'hide-all, 'headings-only, or 'show-all." | |||
| 1121 | (setq heading-end (point)) | 1121 | (setq heading-end (point)) |
| 1122 | (outline-end-of-subtree) | 1122 | (outline-end-of-subtree) |
| 1123 | (setq end (point)) | 1123 | (setq end (point)) |
| 1124 | (setq ov-list (cl-remove-if-not | 1124 | (setq ov-list |
| 1125 | (lambda (o) (eq (overlay-get o 'invisible) 'outline)) | 1125 | (seq-filter |
| 1126 | (overlays-in start end))) | 1126 | (lambda (o) |
| 1127 | (cond ((eq ov-list nil) 'show-all) | 1127 | (and (eq (overlay-get o 'invisible) 'outline) |
| 1128 | ;; (eq (length ov-list) 1) wouldn’t work: what if there is | 1128 | (save-excursion |
| 1129 | ;; one folded subheading? | 1129 | (goto-char (overlay-start o)) |
| 1130 | ((and (eq (overlay-end (car ov-list)) end) | 1130 | (outline-on-heading-p t)))) |
| 1131 | (eq (overlay-start (car ov-list)) heading-end)) | 1131 | (overlays-in start end))) |
| 1132 | (cond ((null ov-list) 'show-all) | ||
| 1133 | ((and (or (= end (point-max) | ||
| 1134 | (1+ (overlay-end (car ov-list)))) | ||
| 1135 | (= (overlay-end (car ov-list)) end)) | ||
| 1136 | (= (overlay-start (car ov-list)) heading-end)) | ||
| 1132 | 'hide-all) | 1137 | 'hide-all) |
| 1133 | (t 'headings-only))))) | 1138 | (t 'headings-only))))) |
| 1134 | 1139 | ||
| @@ -1168,20 +1173,30 @@ Return either 'hide-all, 'headings-only, or 'show-all." | |||
| 1168 | (defun outline-cycle-buffer () | 1173 | (defun outline-cycle-buffer () |
| 1169 | "Cycle the whole buffer like in `outline-cycle'." | 1174 | "Cycle the whole buffer like in `outline-cycle'." |
| 1170 | (interactive) | 1175 | (interactive) |
| 1171 | (pcase outline--cycle-buffer-state | 1176 | (let (has-top-level) |
| 1172 | ('show-all | 1177 | (save-excursion |
| 1173 | (outline-hide-sublevels 1) | 1178 | (goto-char (point-min)) |
| 1174 | (setq outline--cycle-buffer-state 'top-level) | 1179 | (while (not (or has-top-level (eobp))) |
| 1175 | (message "Top level headings")) | 1180 | (when (outline-on-heading-p t) |
| 1176 | ('top-level | 1181 | (when (= (funcall outline-level) 1) |
| 1177 | (outline-show-all) | 1182 | (setq has-top-level t))) |
| 1178 | (outline-hide-region-body (point-min) (point-max)) | 1183 | (outline-next-heading))) |
| 1179 | (setq outline--cycle-buffer-state 'all-heading) | 1184 | (cond |
| 1180 | (message "All headings")) | 1185 | ((and (eq outline--cycle-buffer-state 'show-all) |
| 1181 | ('all-heading | 1186 | has-top-level) |
| 1182 | (outline-show-all) | 1187 | (outline-hide-sublevels 1) |
| 1183 | (setq outline--cycle-buffer-state 'show-all) | 1188 | (setq outline--cycle-buffer-state 'top-level) |
| 1184 | (message "Show all")))) | 1189 | (message "Top level headings")) |
| 1190 | ((or (eq outline--cycle-buffer-state 'show-all) | ||
| 1191 | (eq outline--cycle-buffer-state 'top-level)) | ||
| 1192 | (outline-show-all) | ||
| 1193 | (outline-hide-region-body (point-min) (point-max)) | ||
| 1194 | (setq outline--cycle-buffer-state 'all-heading) | ||
| 1195 | (message "All headings")) | ||
| 1196 | (t | ||
| 1197 | (outline-show-all) | ||
| 1198 | (setq outline--cycle-buffer-state 'show-all) | ||
| 1199 | (message "Show all"))))) | ||
| 1185 | 1200 | ||
| 1186 | (provide 'outline) | 1201 | (provide 'outline) |
| 1187 | (provide 'noutline) | 1202 | (provide 'noutline) |