summaryrefslogtreecommitdiff
path: root/lisp/reveal.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2004-10-31 22:52:54 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2004-10-31 22:52:54 +0000
commit40a45facf30e2ddf7ae3172946cef66d9fa9d4f7 (patch)
treeb43de42dedc944caf4e636a9f2342202e770a477 /lisp/reveal.el
parente0dc0c55b07dc64a13a90865beb403bad7dac672 (diff)
(reveal-last-tick): New var.
(reveal-post-command): Use it to avoid closing overlays when we're appending text to them.
Diffstat (limited to 'lisp/reveal.el')
-rw-r--r--lisp/reveal.el79
1 files changed, 47 insertions, 32 deletions
diff --git a/lisp/reveal.el b/lisp/reveal.el
index 2809db23e2e..393400071a6 100644
--- a/lisp/reveal.el
+++ b/lisp/reveal.el
@@ -1,6 +1,6 @@
;;; reveal.el --- Automatically reveal hidden text at point
-;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+;; Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc.
;; Author: Stefan Monnier <monnier@cs.yale.edu>
;; Keywords: outlines
@@ -59,6 +59,9 @@
(defvar reveal-open-spots nil)
(make-variable-buffer-local 'reveal-open-spots)
+(defvar reveal-last-tick nil)
+(make-variable-buffer-local 'reveal-last-tick)
+
;; Actual code
(defun reveal-post-command ()
@@ -90,16 +93,16 @@
(overlays-at (point))))
(push (cons (selected-window) ol) reveal-open-spots)
(setq old-ols (delq ol old-ols))
- (let ((open (overlay-get ol 'reveal-toggle-invisible)))
+ (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv)
(when (or open
- (let ((inv (overlay-get ol 'invisible)))
- (and inv (symbolp inv)
- (or (setq open (or (get inv 'reveal-toggle-invisible)
- (overlay-get ol 'isearch-open-invisible-temporary)))
- (overlay-get ol 'isearch-open-invisible)
- (and (consp buffer-invisibility-spec)
- (assq inv buffer-invisibility-spec)))
- (overlay-put ol 'reveal-invisible inv))))
+ (and (setq inv (overlay-get ol 'invisible))
+ (symbolp inv)
+ (or (setq open (or (get inv 'reveal-toggle-invisible)
+ (overlay-get ol 'isearch-open-invisible-temporary)))
+ (overlay-get ol 'isearch-open-invisible)
+ (and (consp buffer-invisibility-spec)
+ (assq inv buffer-invisibility-spec)))
+ (overlay-put ol 'reveal-invisible inv)))
(if (null open)
(overlay-put ol 'invisible nil)
;; Use the provided opening function and repeat (since the
@@ -113,27 +116,39 @@
(setq repeat nil)
(overlay-put ol 'invisible nil))))))))
;; Close old overlays.
- (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: %s !!" err)))
+ (overlay-put ol 'invisible inv))))))))
(error (message "Reveal: %s" err)))))
;;;###autoload
@@ -171,5 +186,5 @@ With zero or negative ARG turn mode off."
(provide 'reveal)
-;;; arch-tag: 96ba0242-2274-4ed7-8e10-26bc0707b4d8
+;; arch-tag: 96ba0242-2274-4ed7-8e10-26bc0707b4d8
;;; reveal.el ends here