     (when buffer
       (switch-to-buffer buffer))))
 
-;; TODO: completion-ignore-case
-;;       (let ((completion-ignore-case (blah))) ...
-;;       read-file-name-completion-ignore-case
-;; TODO: highlight opened buffers in filesystem explorer
+;; TODO:
+;; - completion-ignore-case
+;;   (let ((completion-ignore-case (blah))) ...
+;;   read-file-name-completion-ignore-case
+;; - highlight opened buffers in filesystem explorer
+;; - fuzzy matching
+;; - FIX: type nonsense directory name, /, then foo, then TAB
+;;     Wrong type argument: blah blah
+;; - completions -> matches
+
+
+;; Start LiquidMetal
+;;
+;; STEVE document where from
+
+(defconst LM--score-no-match 0.0)
+(defconst LM--score-match 1.0)
+(defconst LM--score-trailing 0.8)
+(defconst LM--score-trailing-but-started 0.90)
+(defconst LM--score-buffer 0.85)
+
+(defun LM-score (str abbrev)
+  (cond ((string= abbrev "")
+         LM--score-trailing)
+        ((> (length abbrev) (length str))
+         LM--score-no-match)
+        (t
+
+         (let* ((scores (LM--build-score-array str abbrev))
+                (sum (reduce '+ scores)))
+           (/ sum (length scores))))))
+
+(defun* LM--build-score-array (str abbrev)
+  (let ((scores (make-vector (length str) LM--score-no-match))
+        (lower (downcase str))
+        (last-index -1)
+        (started-p nil))
+    (loop for c across (downcase abbrev)
+          for i = (position c lower :start (1+ last-index))
+          do
+        (when (null i)
+          (fillarray scores LM--score-no-match)
+          (return-from LM--build-score-array scores))
+        (when (= i 0)
+          (setq started-p t))
+        (cond ((and (> i 0)
+                    (let ((C (aref str (1- i))))
+                      (or (char-equal C ?\ )
+                          (char-equal C ?\t)
+                          (char-equal C ?/)
+                          (char-equal C ?.)
+                          (char-equal C ?_)
+                          (char-equal C ?-))))
+               (aset scores (1- i) LM--score-match)
+               (fill scores LM--score-buffer :start (1+ last-index) :end (1- i)))
+              ((and (>= (aref str i) ?A)
+                    (<= (aref str i) ?Z)
+               (fill scores LM--score-buffer :start (1+ last-index) :end i)))
+              (t
+               (fill scores LM--score-no-match :start (1+ last-index) :end i)))
+        (aset scores i LM--score-match)
+        (setq last-index i))
+
+    (let ((trailing-score
+           (if started-p
+               LM--score-trailing-but-started
+             LM--score-trailing)))
+      (fill scores trailing-score :start (1+ last-index))
+      scores)))
+
+;; End LiquidMetal
+
+
+(defun lusty-highlight-next ()
+  (interactive)
+  (incf lusty--highlighted-index)
+  (lusty-update-completion-buffer))
+(defun lusty-highlight-previous ()
+  (interactive)
+  (decf lusty--highlighted-index)
+  (when (minusp lusty--highlighted-index)
+    (setq lusty--highlighted-index 0))
+  (lusty-update-completion-buffer))
+
+(defun lusty-sort-by-fuzzy-score (strings abbrev)
+  (if (or (string= abbrev "")
+          (string= abbrev "."))
+      (sort strings 'string<)
+    (let* ((all-entries (mapcar (lambda (s) (cons s (LM-score s abbrev)))
+                                strings))
+           (filtered (remove-if (lambda (c) (zerop (cdr c)))
+                                all-entries))
+           (sorted (sort filtered
+                         (lambda (a b) (< (cdr b) (cdr a))))))
+      (mapcar 'car sorted))))
 
 (defun lusty-normalize-dir (dir)
   "Clean up the given directory path."

(require 'advice)
(require 'cl)

;; Used only for the completion algorithms in these functions:
;; - iswitchb-get-matched-buffers
;; - iswitchb-set-common-completion
(require 'iswitchb)

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


                       ido-text
                     (minibuffer-contents-no-properties)))
         (buffers (lusty-filter-buffers (buffer-list)))
         (matches
          (lusty-sort-by-fuzzy-score 
           buffers
           contents))
         (openable-p
          ;; Only one entry.
          (let ((first-entry (car matches)))
            (and (stringp first-entry)
                 (endp (cdr matches))))))
    (values matches openable-p)))

(defun lusty-file-explorer-matches ()
  (let* ((path (minibuffer-contents-no-properties))
         (dir (lusty-normalize-dir (file-name-directory path)))
         (file-portion (file-name-nondirectory path))
         (matches
          ;; TODO: let bind read-file-name-completion-ignore-case 
          ;; based on whether file-portion includes uppercase
          (and dir
               (lusty-sort-by-fuzzy-score 
                (lusty-filter-files
                 file-portion
                 (directory-files dir nil nil t))
                file-portion)))
         (openable-p
          ;; Only one entry and not a directory.
          (let ((first-entry (car matches)))
            (and (stringp first-entry)
                 (endp (cdr matches))
                 (let ((new-path (concat dir first-entry)))
                   (not (file-directory-p new-path))))))
         (unique-completion
          ;; STEVE review
          ;; Only one entry and not a directory.
          ;; STEVE why not a directory?
          (let ((first-entry (car matches)))
            (and (stringp first-entry)
                 (endp (cdr matches))
                 (let ((new-path (concat dir first-entry)))
                   (and (not (file-directory-p new-path))
                        new-path))))))
    (values matches openable-p)))

(defun lusty-propertize-path (path)
  "Propertize the given PATH like so: <dir></><dir></><file>
