anchor.diff:  	  (nconc chars (list (code-char i)))))
       chars))
   
  -(defun filename-clean (filename)
  +(defmethod filename-clean ((filename list))
     "convert a raw filename to a simplified one that can be searched for"
     (let ((acceptable-chars (get-char-range)))
       (remove-if-not (lambda (item) (member item acceptable-chars)) (to-list (string-downcase (to-string filename))))))
   
  -(defun select-files-in-search-buffer (files search-buffer)
  +(defun select-files-in-search-buffer (all-files search-buffer)
     "return a list of selected files by comparing simplified filenames with the search buffer"
  -  (remove-if-not (lambda (file) (equal search-buffer (subseq (filename-clean file) 0 (length search-buffer)))) files))
  -
  -(defun get-file-colors (mode selected-files selected this-file file-list)
  +  (remove-if-not (lambda (file) (equal search-buffer (subseq (filename-clean file) 0 (length search-buffer)))) all-files))
  +
  +(defmethod get-file-colors ((mode symbol) (selected-files list) (selected-index integer) (this-file list) (file-list list))
  +  "return a cons cell containing the foreground and background colors for the given file"
     (cond
  -    ((and (eq mode 'search) (member this-file selected-files) *show-deselected-files*)
  +    ((and (eq mode 'search) (member this-file selected-files :test #'equal) *show-deselected-files*)
        (cons (tb-const "TB_BLACK") (tb-const "TB_WHITE")))
  -    ((and (eq mode 'normal) (eq this-file (nth selected file-list)))
  +    ((and (eq mode 'normal) (equal this-file (nth selected-index file-list)))
        (cons (tb-const "TB_BLACK") (tb-const "TB_WHITE")))
       (t
  -     (cons (tb-const "TB_WHITE") 0))))
  +     (cons 0 0))))
   
   (defun show-this-file-p (this-file selected-files)
     (or *show-deselected-files* (member this-file selected-files :test #'equal) (null selected-files)))
  
positive.code:   "takes a path as a *list* and determines whether the path identifies a file"
    (plusp (length (trivial-shell:shell-command (concatenate 'string "if [ -f " (to-string path) " ]; then echo 1; fi")))))
  
  (defun ls (&optional (path *current-directory*))
    "takes an optional path as a *list* and returns a list of list of characters that correspond to a directory listing"
    (butlast (split-sequence:split-sequence #\newline (to-list (trivial-shell:shell-command (concatenate 'string "ls \"" (to-string path) "\""))))))
  
  (defun pwd ()
    "returns a list of characters of the current working directory"
    (butlast (to-list (trivial-shell:shell-command "pwd"))))
  
  (defun cd (path)
    "modifies a special variable that corresponds to the current path"
    (setf *current-directory* (append *current-directory* (list #\/) path)))
  
  (defun test ()
    (tb-init)
    (tb-clear)
    (tb-change-cell 0 0 (char-code #\!) 0 0)
    (tb-present)
    (plus-c:c-let ((event (:struct (tb-event)) :free t))
      (tb-poll-event event)
      (tb-change-cell 0 1 (event :ch) 0 0))
    (tb-present)
    (sleep 2)
    (tb-shutdown))
  
  (defparameter *show-deselected-files* nil)
  (defparameter *default-mode* 'search)
  
negative.code: 			   0)
  	      new-mode 'normal)
  	(setf new-mode 'search))
      (list new-mode selected)))
  
  (defun open-file-with-command (path command)
    "write the current path, close Lightning, and execute the command"
    (tb-shutdown)
    (write-path (to-string *lightning-path-file*) (to-string path))
    (trivial-shell:shell-command (to-string command))
    (exit))
  
  (defun action (filename path)
    "do something with a filename that the user selected"
    (when (dir-p filename)
      (cd filename))
    (when (file-p filename)
      (open-file-with-command path (append *editor* (list #\space) filename))))
  
  (defun lightning ()
    (let ((mode *default-mode*)
  	(selected-files ())
  	(search-buffer ())
  	(selected-index 0)
  	(all-files ())
  	(char-range (get-char-range)))
      (tb-init)
      (loop
  					; sort files
         (setf all-files (mapcar #'to-list (sort (mapcar #'to-string (ls)) #'string<)))
  
  					; if we're in search mode, only show files that match the buffer
         (if (and (eq mode 'search) search-buffer)
  	   (setf selected-files (select-files-in-search-buffer all-files search-buffer)))
  
  					; clear
         (tb-clear)
  
  					; draw file list, search string, mode, and current directory
         (draw-file-list 1 (1- (tb-height)) mode selected-files selected-index all-files)
         (if (eq mode 'search)
  	   (write-text 0 (1- (tb-height)) search-buffer))
         (write-text 0 0 (append (to-list (string mode)) (to-list ": ") *current-directory*))
         (tb-present)
  
  					; get and process input
         (cond
  	 ((and (eq mode 'search) (= (length selected-files) 1) (plusp (length search-buffer)))
  	  (action (nth 0 selected-files) *current-directory*)
  	  (setf mode *default-mode*
  		selected-files ()
  		selected-index 0
  		search-buffer ()))
  	 (t
  	  (plus-c:c-let ((event (:struct (tb-event)) :free t))
  	    (tb-poll-event event)
  	    (let ((letter (code-char (event :ch)))
  		  (keycode (event :key)))
  	      (cond
  					; go up one directory
  		((eq letter #\.)
  		 (cd (to-list ".."))
  		 (setf search-buffer ()
  		       selected-index 0))
  					; switch modes
  		((eq keycode (tb-const "TB_KEY_SPACE"))
  		 (let ((result (switch-mode mode selected-index selected-files all-files)))
  		   (setf mode (nth 0 result)
  			 selected-index (nth 1 result)
  			 selected-files ()
  			 search-buffer ())))
  					; quit instantly
  		((eq keycode (tb-const "TB_KEY_ESC"))
  		 (return))
  					; quit to the current directory
  		((eq letter #\;)
  		 (open-file-with-command *current-directory* (to-list "true")))
  					; normal-mode-specific commands
  		((eq mode 'normal)
  		 (cond
  					; move up one item
  		   ((eq letter #\k)
  		    (setf selected-index (mod (1- selected-index) (length all-files))))
  					; move down one item
  		   ((eq letter #\j)
  		    (setf selected-index (mod (1+ selected-index) (length all-files))))
  					; open the current item
  		   ((eq letter #\')
  		    (action (nth selected-index all-files) *current-directory*)
  		    (setf mode *default-mode*
  			  selected-files ()
  			  selected-index 0
  			  search-buffer ()))
  		   ((eq letter #\v)
  		    (open-file-with-command *current-directory* (append *editor* (list #\space) (list (nth selected-index all-files)))))))
  		((eq mode 'search)
  		 (cond
  		   (letter
  		    (cond
  		      ((member letter char-range)
  		       (setf search-buffer (append search-buffer (list letter))))
  		      ((eq letter #\-)
  		       (setf search-buffer (butlast search-buffer)))))
  		   ((eq keycode (tb-const "TB_KEY_ENTER"))
  		    (action (nth 0 selected-files) *current-directory*))))))))))))
  
  (lightning)
  