- (dolist (ol old-ols)
- (when (and (eq (current-buffer) (overlay-buffer ol))
- (not (rassq ol reveal-open-spots)))
- (if (and (>= (point) (save-excursion
- (goto-char (overlay-start ol))
- (line-beginning-position 1)))
- (<= (point) (save-excursion
- (goto-char (overlay-end ol))
- (line-beginning-position 2))))
- ;; Still near the overlay: keep it open.
- (push (cons (selected-window) ol) reveal-open-spots)
- ;; Really close it.
- (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv)
- (if (or open
- (and (setq inv (overlay-get ol 'reveal-invisible))
- (setq open (or (get inv 'reveal-toggle-invisible)
- (overlay-get ol 'isearch-open-invisible-temporary)))))
- (condition-case err
- (funcall open ol t)
- (error (message "!!Reveal-hide: %s !!" err)))
- (overlay-put ol 'invisible inv)))))))
+ (if (not (eq reveal-last-tick
+ (setq reveal-last-tick (buffer-modified-tick))))
+ ;; The buffer was modified since last command: let's refrain from
+ ;; closing any overlay because it tends to behave poorly when
+ ;; inserting text at the end of an overlay (basically the overlay
+ ;; should be rear-advance when it's open, but things like
+ ;; outline-minor-mode make it non-rear-advance because it's
+ ;; a better choice when it's closed).
+ (dolist (ol old-ols)
+ (push (cons (selected-window) ol) reveal-open-spots))
+ ;; The last command was only a point motion or some such
+ ;; non-buffer-modifying command. Let's close whatever can be closed.
+ (dolist (ol old-ols)
+ (when (and (eq (current-buffer) (overlay-buffer ol))
+ (not (rassq ol reveal-open-spots)))
+ (if (and (>= (point) (save-excursion
+ (goto-char (overlay-start ol))
+ (line-beginning-position 1)))
+ (<= (point) (save-excursion
+ (goto-char (overlay-end ol))
+ (line-beginning-position 2))))
+ ;; Still near the overlay: keep it open.
+ (push (cons (selected-window) ol) reveal-open-spots)
+ ;; Really close it.
+ (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv)
+ (if (or open
+ (and (setq inv (overlay-get ol 'reveal-invisible))
+ (setq open (or (get inv 'reveal-toggle-invisible)
+ (overlay-get ol 'isearch-open-invisible-temporary)))))
+ (condition-case err
+ (funcall open ol t)
+ (error (message "!!Reveal-hide (funcall %s %s t): %s !!"
+ open ol err)))
+ (overlay-put ol 'invisible inv))))))))