 ;;
 
 
+;;
+;; XEmacs compatibility functions
+;;
+
+(unless (fboundp 'minibufferp)
+  (defun minibufferp ()
+    (eq (window-buffer (minibuffer-window))
+        (current-buffer))))
+
+(unless (fboundp 'minibuffer-contents-no-properties)
+  (defun minibuffer-contents-no-properties ()
+    (with-current-buffer (window-buffer (minibuffer-window))
+      (let ((start (1+ (length lusty-prompt)))
+            (end (point-max)))
+        (if (>= end start)
+            (buffer-substring-no-properties start end)
+          "")))))
+
+(unless (fboundp 'minibuffer-prompt-end)
+  (defun minibuffer-prompt-end ()
+    (1+ (length lusty-prompt))))
+
+(unless (fboundp 'line-number-at-pos)
+  (defun line-number-at-pos (&optional pos)
+    (line-number pos)))
+
+;; Cribbed from cal-fit-window-to-buffer
+(unless (fboundp 'fit-window-to-buffer)
+  (defun fit-window-to-buffer (owin max-height)
+    (interactive)
+    (if owin
+	(delete-other-windows))
+    (when (> (length (window-list nil 'nomini)) 1)
+      (let* ((window (selected-window))
+	     (buf (window-buffer window))
+	     (height (window-displayed-height (selected-window)))
+	     (new-height
+              (min (with-current-buffer buf
+                     (count-lines (point-min) (point-max)))
+                   max-height))
+	     (diff (- new-height height)))
+	(unless (zerop diff)
+	  (enlarge-window diff))
+	(let ((end (with-current-buffer buf (point-max))))
+	  (while (and (> (length (window-list nil 'nomini)) 1)
+		      (not (pos-visible-in-window-p end)))
+	    (enlarge-window 1)))))))
+
+
 (provide 'lusty-explorer)
 
 ;;; lusty-explorer.el ends here.

    (add-hook 'post-command-hook 'lusty--post-command-function t)
    (unwind-protect
        (save-window-excursion
          (funcall read-fn ">> "))
      (remove-hook 'post-command-hook 'lusty--post-command-function)
      (setq lusty--previous-minibuffer-contents nil
            lusty--initial-window-config nil))))

                             (next-window (selected-window) :skip-mini)
                           (selected-window)))
         (lowest-window current-window)
         (bottom-edge (fourth (window-pixel-edges current-window)))
         (last-window (previous-window current-window :skip-mini))
         (window-search-p t))
    (while window-search-p
      (let* ((this-window (next-window current-window :skip-mini))
             (next-bottom-edge (fourth (window-pixel-edges this-window))))
        (when (< bottom-edge next-bottom-edge)
          (setq bottom-edge next-bottom-edge)
          (setq lowest-window this-window))
        (setq current-window this-window)
        (when (eq last-window this-window)
          (setq window-search-p nil))))
    lowest-window))

(defun lusty--setup-matches-window ()
