diff --git a/src/command-window.lisp b/src/command-window.lisp index 8d2bb9a..d33fd87 100644 --- a/src/command-window.lisp +++ b/src/command-window.lisp @@ -340,8 +340,7 @@ be either `:keybinding' or `:string'. the former for key command the latter for (setf suggestions-win (complete-window:init))) (win-show suggestions-win) (multiple-value-bind (candidates common-prefix) - (suggestions-window:update-suggestions suggestions-win - command-line) + (suggestions-window:update-suggestions suggestions-win command-line) (if candidates (if (null common-prefix) (progn @@ -456,8 +455,9 @@ be either `:keybinding' or `:string'. the former for key command the latter for (command-line command-line)) win (when suggestions-win (let ((suggestion (suggested-selection win))) - (setf command-line suggestion) - (move-point-to-end win command-line)))) + (when (string-not-empty-p suggestion) + (setf command-line suggestion) + (move-point-to-end win command-line))))) win) (defun fire-user-input-event (win) diff --git a/src/complete.lisp b/src/complete.lisp index 9fad824..4674cac 100644 --- a/src/complete.lisp +++ b/src/complete.lisp @@ -38,9 +38,10 @@ See: complete:directory-complete") (defun reduce-to-common-prefix (items) (reduce #'text-utils:common-prefix items)) -(defun pathname-directory-pathname (pathname) +(defun pathname->directory-pathname (pathname) "convenience function to make a pathname object to a directory" - (make-pathname :name nil :type nil + (make-pathname :name nil + :type nil :defaults pathname)) (defun underlying-directory-p (pathname) @@ -78,21 +79,25 @@ to the appropriate home directory." "Return two values completion of 'string' (non nil if can be completed) and the common prefix of the completion string." (when (text-utils:string-not-empty-p string) - (let* ((string (tilde-expand-string string)) - (dir (pathname-directory-pathname string)) - (namefun (if (relative-pathname-p string) - #'namestring - (lambda (x) (namestring (merge-pathnames x)))))) + (let* ((namestring (tilde-expand-string string)) + (name-dir (if (file-exists-p namestring) + (fs:parent-dir-path namestring) + namestring)) + (dir (pathname->directory-pathname namestring)) + (namefun (if (relative-pathname-p string) + #'namestring + (lambda (x) (namestring (merge-pathnames x)))))) (unless (and (underlying-directory-p dir) (not (wild-pathname-p dir))) (return-from directory-complete (values nil 0))) - (with-directory-iterator (next dir) + (with-directory-iterator (next dir) (when-let* ((all (loop - for entry = (next) - while entry collect - (funcall namefun entry))) + for entry = (next) + while entry collect + (funcall namefun entry))) (candidates (sort (remove-if-not (lambda (a) - (text-utils:string-starts-with-p string a)) + (text-utils:string-starts-with-p name-dir + a)) all) (lambda (a b) (< (length a) (length b))))))