+(defvar hs-headline nil
+ "Text of the line where a hidden block begins, set during isearch.
+You can display this in the mode line by adding the symbol `hs-headline'
+to the variable `mode-line-format'. For example,
+
+ (unless (memq 'hs-headline mode-line-format)
+ (setq mode-line-format
+ (append '(\"-\" hs-headline) mode-line-format)))
+
+Note that `mode-line-format' is buffer-local.")
+
+;;---------------------------------------------------------------------------
+;; system dependency
+
+; ;; xemacs compatibility
+; (when (string-match "xemacs\\|lucid" emacs-version)
+; ;; use pre-packaged compatiblity layer
+; (require 'overlay))
+;
+; ;; xemacs and emacs-19 compatibility
+; (when (or (not (fboundp 'add-to-invisibility-spec))
+; (not (fboundp 'remove-from-invisibility-spec)))
+; ;; `buffer-invisibility-spec' mutators snarfed from Emacs 20.3 lisp/subr.el
+; (defun add-to-invisibility-spec (arg)
+; (cond
+; ((or (null buffer-invisibility-spec) (eq buffer-invisibility-spec t))
+; (setq buffer-invisibility-spec (list arg)))
+; (t
+; (setq buffer-invisibility-spec
+; (cons arg buffer-invisibility-spec)))))
+; (defun remove-from-invisibility-spec (arg)
+; (when buffer-invisibility-spec
+; (setq buffer-invisibility-spec
+; (delete arg buffer-invisibility-spec)))))
+
+;; hs-match-data
+(defalias 'hs-match-data 'match-data)
+
+;;---------------------------------------------------------------------------
+;; support functions
+
+(defun hs-discard-overlays (from to)
+ "Delete hideshow overlays in region defined by FROM and TO."
+ (when (< to from)
+ (setq from (prog1 to (setq to from))))
+ (let ((ovs (overlays-in from to)))
+ (while ovs
+ (let ((ov (car ovs)))
+ (when (overlay-get ov 'hs)
+ (delete-overlay ov)))
+ (setq ovs (cdr ovs)))))
+
+(defun hs-isearch-show (ov)
+ "Delete overlay OV, and set `hs-headline' to nil.
+
+This function is meant to be used as the `isearch-open-invisible'
+property of an overlay."
+ (setq hs-headline nil)
+ (delete-overlay ov))
+
+(defun hs-isearch-show-temporary (ov hide-p)
+ "Hide or show overlay OV, and set `hs-headline', all depending on HIDE-P.
+If HIDE-P is non-nil, `hs-headline' is set to nil and overlay OV is hidden.
+Otherwise, `hs-headline' is set to the line of text at the head of OV, and
+OV is shown.
+
+This function is meant to be used as the `isearch-open-invisible-temporary'
+property of an overlay."
+ (setq hs-headline
+ (if hide-p
+ nil
+ (or hs-headline
+ (let ((start (overlay-start ov)))
+ (buffer-substring
+ (save-excursion (goto-char start)
+ (beginning-of-line)
+ (skip-chars-forward " \t")
+ (point))
+ start)))))
+ (force-mode-line-update)
+ (overlay-put ov 'invisible (and hide-p 'hs)))