branch: master commit 1c6849575da3cadd82981c6fd696b3464e9212e6 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
ivy.el (ivy-expand-file-if-directory): New defun * ivy.el (ivy--directory-done): Use `ivy-expand-file-if-directory'. (ivy-partial-or-done): Use `ivy-expand-file-if-directory'. --- ivy.el | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ivy.el b/ivy.el index c73e5a5..5ebdb4a 100644 --- a/ivy.el +++ b/ivy.el @@ -541,21 +541,12 @@ When ARG is t, exit with current text, ignoring the candidates." (ivy--exhibit)) ((or (and - (not (equal ivy-text "")) - (ignore-errors - (file-directory-p - (setq dir - (file-name-as-directory - (expand-file-name - ivy-text ivy--directory)))))) + (not (string= ivy-text "")) + (setq dir (ivy-expand-file-if-directory ivy-text))) (and + (> ivy--length 0) (not (string= ivy--current "./")) - (cl-plusp ivy--length) - (ignore-errors - (file-directory-p - (setq dir (file-name-as-directory - (expand-file-name - ivy--current ivy--directory))))))) + (setq dir (ivy-expand-file-if-directory ivy--current)))) (ivy--cd dir) (ivy--exhibit)) ((or (and (equal ivy--directory "/") @@ -597,6 +588,16 @@ When ARG is t, exit with current text, ignoring the candidates." (t (ivy-done))))) +(defun ivy-expand-file-if-directory (file-name) + "Expand FILE-NAME as directory. +When this directory doesn't exist, return nil." + (when (stringp file-name) + (let ((full-name + (file-name-as-directory + (expand-file-name file-name ivy--directory)))) + (when (file-directory-p full-name) + full-name)))) + (defcustom ivy-tab-space nil "When non-nil, `ivy-partial-or-done' should insert a space." :type 'boolean) @@ -609,13 +610,12 @@ If the text hasn't changed as a result, forward to `ivy-alt-done'." (or (and (equal ivy--directory "/") (string-match "\\`[^/]+:.*\\'" ivy-text)) (string-match "\\`/" ivy-text))) - (let ((default-directory ivy--directory)) + (let ((default-directory ivy--directory) + dir) (minibuffer-complete) (setq ivy-text (ivy--input)) - (when (file-directory-p - (expand-file-name ivy-text ivy--directory)) - (ivy--cd (file-name-as-directory - (expand-file-name ivy-text ivy--directory))))) + (when (setq dir (ivy-expand-file-if-directory ivy-text)) + (ivy--cd dir))) (or (ivy-partial) (when (or (eq this-command last-command) (eq ivy--length 1))