@@ -1704,49 +1704,61 @@ LEVEL, decides of subtree visibility according to
1704
1704
Every hash key is a list whose elements compose a complete path
1705
1705
of headings descending from the top level down to the bottom level.
1706
1706
This is useful to save the hidden outlines and restore them later
1707
- after reverting the buffer."
1708
- (let ((paths (make-hash-table :test #'equal ))
1709
- current-path)
1707
+ after reverting the buffer. Also return the outline where point
1708
+ was located before reverting the buffer."
1709
+ (let* ((paths (make-hash-table :test #'equal ))
1710
+ path current-path
1711
+ (current-heading-p (outline-on-heading-p ))
1712
+ (current-beg (when current-heading-p (pos-bol)))
1713
+ (current-end (when current-heading-p (pos-eol))))
1710
1714
(outline-map-region
1711
1715
(lambda ()
1712
1716
(let* ((level (funcall outline-level))
1713
1717
(heading (buffer-substring-no-properties (pos-bol) (pos-eol))))
1714
- (while (and current- path (>= (cdar current- path) level))
1715
- (pop current- path))
1716
- (push (cons heading level) current- path)
1718
+ (while (and path (>= (cdar path) level))
1719
+ (pop path))
1720
+ (push (cons heading level) path)
1717
1721
(when (save-excursion
1718
1722
(outline-end-of-heading )
1719
1723
(seq-some (lambda (o ) (eq (overlay-get o 'invisible )
1720
1724
'outline ))
1721
1725
(overlays-at (point ))))
1722
- (setf (gethash (mapcar #'car current-path) paths) t ))))
1726
+ (setf (gethash (mapcar #'car path) paths) t ))
1727
+ (when (and current-heading-p (<= current-beg (point ) current-end))
1728
+ (setq current-path (mapcar #'car path)))))
1723
1729
(point-min ) (point-max ))
1724
- paths))
1730
+ ( list paths current-path) ))
1725
1731
1726
- (defun outline-hidden-headings-restore-paths (paths )
1732
+ (defun outline-hidden-headings-restore-paths (paths current-path )
1727
1733
" Restore hidden outlines from a hash of hidden headings.
1728
1734
This is useful after reverting the buffer to restore the outlines
1729
- hidden by `outline-hidden-headings-paths' ."
1730
- (let (current-path outline-view-change-hook)
1735
+ hidden by `outline-hidden-headings-paths' . Also restore point
1736
+ on the same outline where point was before reverting the buffer."
1737
+ (let (path current-point outline-view-change-hook)
1731
1738
(outline-map-region
1732
1739
(lambda ()
1733
1740
(let* ((level (funcall outline-level))
1734
1741
(heading (buffer-substring (pos-bol) (pos-eol))))
1735
- (while (and current-path (>= (cdar current-path) level))
1736
- (pop current-path))
1737
- (push (cons heading level) current-path)
1738
- (when (gethash (mapcar #'car current-path) paths)
1739
- (outline-hide-subtree))))
1740
- (point-min ) (point-max ))))
1742
+ (while (and path (>= (cdar path) level))
1743
+ (pop path))
1744
+ (push (cons heading level) path)
1745
+ (when (gethash (mapcar #'car path) paths)
1746
+ (outline-hide-subtree))
1747
+ (when (and current-path (equal current-path (mapcar #'car path)))
1748
+ (setq current-point (point )))))
1749
+ (point-min ) (point-max ))
1750
+ (when current-point (goto-char current-point))))
1741
1751
1742
1752
(defun outline-revert-buffer-restore-visibility ()
1743
1753
" Preserve visibility when reverting buffer under `outline-minor-mode' .
1744
1754
This function restores the visibility of outlines after the buffer
1745
1755
under `outline-minor-mode' is reverted by `revert-buffer' ."
1746
1756
(let ((paths (outline-hidden-headings-paths)))
1747
- (unless (hash-table-empty-p paths)
1757
+ (unless (and (hash-table-empty-p (nth 0 paths))
1758
+ (null (nth 1 paths)))
1748
1759
(lambda ()
1749
- (outline-hidden-headings-restore-paths paths)))))
1760
+ (outline-hidden-headings-restore-paths
1761
+ (nth 0 paths) (nth 1 paths))))))
1750
1762
1751
1763
(defun outline-revert-buffer-rehighlight ()
1752
1764
" Rehighlight outlines when reverting buffer under `outline-minor-mode' .
0 commit comments