From 1cc58ab68909515513f80d2681c0187c32766246 Mon Sep 17 00:00:00 2001
From: Greg Sexton <gregsexton@gmail.com>
Date: Sat, 22 Nov 2014 10:26:26 +0000
Subject: [PATCH] Make isearch reveal folds

---
 origami.el | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/origami.el b/origami.el
index 3072c8d..36132f9 100644
--- a/origami.el
+++ b/origami.el
@@ -41,20 +41,34 @@
 
 (defun origami-create-overlay (beg end offset buffer)
   (when (> (- end beg) 0)
-    (make-overlay (+ beg offset) end buffer)))
+    (let ((ov (make-overlay (+ beg offset) end buffer)))
+      (overlay-put ov 'isearch-open-invisible 'origami-isearch-show)
+      (overlay-put ov 'isearch-open-invisible-temporary
+                   (lambda (ov hide-p) (if hide-p (origami-hide-overlay ov)
+                                         (origami-show-overlay ov))))
+      ov)))
+
+(defun origami-hide-overlay (ov)
+  ;; TODO: make all of this customizable
+  (overlay-put ov 'invisible 'origami)
+  (overlay-put ov 'display "...")
+  (overlay-put ov 'face 'font-lock-comment-delimiter-face))
+
+(defun origami-show-overlay (ov)
+  (overlay-put ov 'invisible nil)
+  (overlay-put ov 'display nil)
+  (overlay-put ov 'face nil))
 
 (defun origami-hide-node-overlay (node)
   (-when-let (ov (origami-fold-data node))
-    ;; TODO: make all of this customizable
-    (overlay-put ov 'invisible 'origami)
-    (overlay-put ov 'display "...")
-    (overlay-put ov 'face 'font-lock-comment-delimiter-face)))
+    (origami-hide-overlay ov)))
 
 (defun origami-show-node-overlay (node)
   (-when-let (ov (origami-fold-data node))
-    (overlay-put ov 'invisible nil)
-    (overlay-put ov 'display nil)
-    (overlay-put ov 'face nil)))
+    (origami-show-overlay ov)))
+
+(defun origami-isearch-show (ov)
+  (origami-show-node (current-buffer) (point)))
 
 (defun origami-hide-overlay-from-fold-tree-fn (node)
   (origami-fold-postorder-each node 'origami-hide-node-overlay))