       (setq entries (nthcdr n-rows entries)))
     (nreverse sublists)))
 
+(defun lusty--define-mode-map ()
+  ;; Re-generated every run so that it can inherit new functions.
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map minibuffer-local-map)
+    ;; STEVE: perhaps RET should be:
+    ;; - if buffer explorer, same as \t
+    ;; - if file explorer, opens current name (or recurses if existing dir)
+    (define-key map (kbd "RET") 'lusty-select-entry)
+    (define-key map "\t" 'lusty-select-entry)
+    (define-key map "\C-n" 'lusty-highlight-next)
+    (define-key map "\C-p" 'lusty-highlight-previous)
+    (setq lusty-mode-map map))
+  (run-hooks 'lusty-setup-hook))
+
 (defun lusty--run (read-fn)
-  (add-hook 'post-command-hook 'lusty--post-command-function t)
   (let ((lusty--highlighted-index 0)
         (lusty--previous-printed-matches '()))
+    (add-hook 'post-command-hook 'lusty--post-command-function t)
     (unwind-protect 
         (save-window-excursion
           (funcall read-fn ">> "))

;; Used only for its faces (for color-theme).
(require 'font-lock)

(defvar lusty-match-face font-lock-function-name-face)
(defvar lusty-directory-face font-lock-type-face)
(defvar lusty-slash-face font-lock-keyword-face)

(defun lusty-buffer-explorer ()
  "Launch the buffer mode of LustyExplorer."
  (interactive)
  (lusty--define-mode-map)
  (let* ((lusty--active-mode :buffer-explorer)
         (minibuffer-local-completion-map lusty-mode-map)
         (buffer (lusty--run 'read-buffer)))
    (when buffer
      (switch-to-buffer buffer))))

;;;###autoload
(defun lusty-highlight-next ()
  "Highlight the next entry in *Lusty-Matches*."
  (interactive)
  (incf lusty--highlighted-index)
  (lusty-refresh-matches-buffer))

;;;###autoload
(defun lusty-highlight-previous ()
  "Highlight the previous entry in *Lusty-Matches*."
  (interactive)
