diff options
| -rw-r--r-- | lisp/reveal.el | 79 |
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 @@ | |||
| 1 | ;;; reveal.el --- Automatically reveal hidden text at point | 1 | ;;; reveal.el --- Automatically reveal hidden text at point |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2000, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Stefan Monnier <monnier@cs.yale.edu> | 5 | ;; Author: Stefan Monnier <monnier@cs.yale.edu> |
| 6 | ;; Keywords: outlines | 6 | ;; Keywords: outlines |
| @@ -59,6 +59,9 @@ | |||
| 59 | (defvar reveal-open-spots nil) | 59 | (defvar reveal-open-spots nil) |
| 60 | (make-variable-buffer-local 'reveal-open-spots) | 60 | (make-variable-buffer-local 'reveal-open-spots) |
| 61 | 61 | ||
| 62 | (defvar reveal-last-tick nil) | ||
| 63 | (make-variable-buffer-local 'reveal-last-tick) | ||
| 64 | |||
| 62 | ;; Actual code | 65 | ;; Actual code |
| 63 | 66 | ||
| 64 | (defun reveal-post-command () | 67 | (defun reveal-post-command () |
| @@ -90,16 +93,16 @@ | |||
| 90 | (overlays-at (point)))) | 93 | (overlays-at (point)))) |
| 91 | (push (cons (selected-window) ol) reveal-open-spots) | 94 | (push (cons (selected-window) ol) reveal-open-spots) |
| 92 | (setq old-ols (delq ol old-ols)) | 95 | (setq old-ols (delq ol old-ols)) |
| 93 | (let ((open (overlay-get ol 'reveal-toggle-invisible))) | 96 | (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv) |
| 94 | (when (or open | 97 | (when (or open |
| 95 | (let ((inv (overlay-get ol 'invisible))) | 98 | (and (setq inv (overlay-get ol 'invisible)) |
| 96 | (and inv (symbolp inv) | 99 | (symbolp inv) |
| 97 | (or (setq open (or (get inv 'reveal-toggle-invisible) | 100 | (or (setq open (or (get inv 'reveal-toggle-invisible) |
| 98 | (overlay-get ol 'isearch-open-invisible-temporary))) | 101 | (overlay-get ol 'isearch-open-invisible-temporary))) |
| 99 | (overlay-get ol 'isearch-open-invisible) | 102 | (overlay-get ol 'isearch-open-invisible) |
| 100 | (and (consp buffer-invisibility-spec) | 103 | (and (consp buffer-invisibility-spec) |
| 101 | (assq inv buffer-invisibility-spec))) | 104 | (assq inv buffer-invisibility-spec))) |
| 102 | (overlay-put ol 'reveal-invisible inv)))) | 105 | (overlay-put ol 'reveal-invisible inv))) |
| 103 | (if (null open) | 106 | (if (null open) |
| 104 | (overlay-put ol 'invisible nil) | 107 | (overlay-put ol 'invisible nil) |
| 105 | ;; Use the provided opening function and repeat (since the | 108 | ;; Use the provided opening function and repeat (since the |
| @@ -113,27 +116,39 @@ | |||
| 113 | (setq repeat nil) | 116 | (setq repeat nil) |
| 114 | (overlay-put ol 'invisible nil)))))))) | 117 | (overlay-put ol 'invisible nil)))))))) |
| 115 | ;; Close old overlays. | 118 | ;; Close old overlays. |
| 116 | (dolist (ol old-ols) | 119 | (if (not (eq reveal-last-tick |
| 117 | (when (and (eq (current-buffer) (overlay-buffer ol)) | 120 | (setq reveal-last-tick (buffer-modified-tick)))) |
| 118 | (not (rassq ol reveal-open-spots))) | 121 | ;; The buffer was modified since last command: let's refrain from |
| 119 | (if (and (>= (point) (save-excursion | 122 | ;; closing any overlay because it tends to behave poorly when |
| 120 | (goto-char (overlay-start ol)) | 123 | ;; inserting text at the end of an overlay (basically the overlay |
| 121 | (line-beginning-position 1))) | 124 | ;; should be rear-advance when it's open, but things like |
| 122 | (<= (point) (save-excursion | 125 | ;; outline-minor-mode make it non-rear-advance because it's |
| 123 | (goto-char (overlay-end ol)) | 126 | ;; a better choice when it's closed). |
| 124 | (line-beginning-position 2)))) | 127 | (dolist (ol old-ols) |
| 125 | ;; Still near the overlay: keep it open. | 128 | (push (cons (selected-window) ol) reveal-open-spots)) |
| 126 | (push (cons (selected-window) ol) reveal-open-spots) | 129 | ;; The last command was only a point motion or some such |
| 127 | ;; Really close it. | 130 | ;; non-buffer-modifying command. Let's close whatever can be closed. |
| 128 | (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv) | 131 | (dolist (ol old-ols) |
| 129 | (if (or open | 132 | (when (and (eq (current-buffer) (overlay-buffer ol)) |
| 130 | (and (setq inv (overlay-get ol 'reveal-invisible)) | 133 | (not (rassq ol reveal-open-spots))) |
| 131 | (setq open (or (get inv 'reveal-toggle-invisible) | 134 | (if (and (>= (point) (save-excursion |
| 132 | (overlay-get ol 'isearch-open-invisible-temporary))))) | 135 | (goto-char (overlay-start ol)) |
| 133 | (condition-case err | 136 | (line-beginning-position 1))) |
| 134 | (funcall open ol t) | 137 | (<= (point) (save-excursion |
| 135 | (error (message "!!Reveal-hide: %s !!" err))) | 138 | (goto-char (overlay-end ol)) |
| 136 | (overlay-put ol 'invisible inv))))))) | 139 | (line-beginning-position 2)))) |
| 140 | ;; Still near the overlay: keep it open. | ||
| 141 | (push (cons (selected-window) ol) reveal-open-spots) | ||
| 142 | ;; Really close it. | ||
| 143 | (let ((open (overlay-get ol 'reveal-toggle-invisible)) inv) | ||
| 144 | (if (or open | ||
| 145 | (and (setq inv (overlay-get ol 'reveal-invisible)) | ||
| 146 | (setq open (or (get inv 'reveal-toggle-invisible) | ||
| 147 | (overlay-get ol 'isearch-open-invisible-temporary))))) | ||
| 148 | (condition-case err | ||
| 149 | (funcall open ol t) | ||
| 150 | (error (message "!!Reveal-hide: %s !!" err))) | ||
| 151 | (overlay-put ol 'invisible inv)))))))) | ||
| 137 | (error (message "Reveal: %s" err))))) | 152 | (error (message "Reveal: %s" err))))) |
| 138 | 153 | ||
| 139 | ;;;###autoload | 154 | ;;;###autoload |
| @@ -171,5 +186,5 @@ With zero or negative ARG turn mode off." | |||
| 171 | 186 | ||
| 172 | (provide 'reveal) | 187 | (provide 'reveal) |
| 173 | 188 | ||
| 174 | ;;; arch-tag: 96ba0242-2274-4ed7-8e10-26bc0707b4d8 | 189 | ;; arch-tag: 96ba0242-2274-4ed7-8e10-26bc0707b4d8 |
| 175 | ;;; reveal.el ends here | 190 | ;;; reveal.el ends here |