+
+;;; Called when opening an overlay, and we are still in isearch.
+(defun isearch-open-overlay-temporary (ov)
+ (if (not (null (overlay-get ov 'isearch-open-invisible-temporary)))
+ ;; Some modes would want to open the overlays temporary during
+ ;; isearch in their own way, they should set the
+ ;; `isearch-open-invisible-temporary' to a function doing this.
+ (funcall (overlay-get ov 'isearch-open-invisible-temporary) ov nil)
+ ;; Store the values for the `invisible' and `intangible'
+ ;; properties, and then set them to nil. This way the text hidden
+ ;; by this overlay becomes visible.
+
+ ;; Do we realy need to set the `intangible' property to t? Can we
+ ;; have the point inside an overlay with an `intangible' property?
+ ;; In 19.34 this does not exist so I cannot test it.
+ (overlay-put ov 'isearch-invisible (overlay-get ov 'invisible))
+ (overlay-put ov 'isearch-intangible (overlay-get ov 'intangible))
+ (overlay-put ov 'invisible nil)
+ (overlay-put ov 'intangible nil)))
+
+
+;;; This is called at the end of isearch. I will open the overlays
+;;; that contain the latest match. Obviously in case of a C-g the
+;;; point returns to the original location which surely is not contain
+;;; in any of these overlays, se we are safe in this case too.
+(defun isearch-open-necessary-overlays (ov)
+ (let ((inside-overlay (and (> (point) (overlay-start ov))
+ (< (point) (overlay-end ov))))
+ ;; If this exists it means that the overlay was opened using
+ ;; this function, not by us tweaking the overlay properties.
+ (fct-temp (overlay-get ov 'isearch-open-invisible-temporary)))
+ (when (or inside-overlay (not fct-temp))
+ ;; restore the values for the `invisible' and `intangible'
+ ;; properties
+ (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
+ (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible))
+ (overlay-put ov 'isearch-invisible nil)
+ (overlay-put ov 'isearch-intangible nil))
+ (if inside-overlay
+ (funcall (overlay-get ov 'isearch-open-invisible) ov)
+ (if fct-temp
+ (funcall fct-temp ov t)))))
+
+;;; This is called when exiting isearch. It closes the temporary
+;;; opened overlays, except the ones that contain the latest match.
+(defun isearch-clean-overlays ()
+ (when isearch-opened-overlays
+ ;; Use a cycle instead of a mapcar here?
+ (mapcar
+ (function isearch-open-necessary-overlays) isearch-opened-overlays)
+ (setq isearch-opened-overlays nil)))
+
+;;; Verify if the current match is outside of each element of
+;;; `isearch-opened-overlays', if so close that overlay.
+(defun isearch-close-unecessary-overlays (begin end)
+ (let ((ov-list isearch-opened-overlays)
+ ov
+ inside-overlay
+ fct-temp)
+ (setq isearch-opened-overlays nil)
+ (while ov-list
+ (setq ov (car ov-list))
+ (setq ov-list (cdr ov-list))
+ (setq inside-overlay (or (and (> begin (overlay-start ov))
+ (< begin (overlay-end ov)))
+ (and (> end (overlay-start ov))
+ (< end (overlay-end ov)))))
+ ;; If this exists it means that the overlay was opened using
+ ;; this function, not by us tweaking the overlay properties.
+ (setq fct-temp (overlay-get ov 'isearch-open-invisible-temporary))
+ (if inside-overlay
+ (setq isearch-opened-overlays (cons ov isearch-opened-overlays))
+ (if fct-temp
+ (funcall fct-temp ov t)
+ (overlay-put ov 'invisible (overlay-get ov 'isearch-invisible))
+ (overlay-put ov 'intangible (overlay-get ov 'isearch-intangible))
+ (overlay-put ov 'isearch-invisible nil)
+ (overlay-put ov 'isearch-intangible nil))))))
+