emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 3c6790f 387/399: ivy.el (ivy-immediate-done): Improve make


From: Oleh Krehel
Subject: [elpa] master 3c6790f 387/399: ivy.el (ivy-immediate-done): Improve make-directory
Date: Sat, 20 Jul 2019 14:58:05 -0400 (EDT)

branch: master
commit 3c6790f846d0d57925cfdbe11f644eb290ab89fa
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    ivy.el (ivy-immediate-done): Improve make-directory
    
    1. Don't modify (ivy-state-def ivy-last).
    2. "C-M-j" with no input should return (ivy-state-def ivy-last).
    3. Update the test, since `read-file-name-default' will detect that
    the same (eq) string was returned and return "" instead of the file
    name.
    4. Add a test that `ivy-read' actually returned the file name.
    
    Re #1170
    Re #1719
    Fixes #2139
---
 ivy-test.el | 19 +++++++++++++------
 ivy.el      | 22 ++++++++--------------
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/ivy-test.el b/ivy-test.el
index 8cea339..6566279 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -971,15 +971,22 @@ will bring the behavior in line with the newer Emacsen."
 a buffer visiting a file."
   (let ((ivy-mode-reset-arg (if ivy-mode 1 0)))
     (ivy-mode 1)
+    ;; `ivy-read' returns "~/dummy-dir/dummy-file" (same object, not a copy).
+    ;;
+    ;; `read-file-name-default' will then return "" in order for
+    ;; `set-visited-file-name' to detect that the user typed RET with
+    ;; the minibuffer empty.
     (should
-     (equal "~/dummy-dir/dummy-file" ;visiting file name, abbreviated form
-            (ivy-with
+     (equal (ivy-with
              '(let ((insert-default-directory t))
-                (with-temp-buffer
-                  (set-visited-file-name "~/dummy-dir/dummy-file")
-                  (read-file-name "Load file: " nil nil 'lambda))) ;load-file
+               (with-temp-buffer
+                 (set-visited-file-name "~/dummy-dir/dummy-file")
+                 (read-file-name "Load file: " nil nil 'lambda)))
              ;; No editing, just command ivy-immediate-done
-             "C-M-j")))
+             "C-M-j")
+            ""))
+    (should
+     (equal (ivy-state-current ivy-last) "~/dummy-dir/dummy-file"))
     (ivy-mode ivy-mode-reset-arg)))
 
 (ert-deftest ivy-starts-with-dotslash ()
diff --git a/ivy.el b/ivy.el
index 21c317c..a015275 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1125,14 +1125,8 @@ If the text hasn't changed as a result, forward to 
`ivy-alt-done'."
               ((and (string= ivy-text "")
                     (eq (ivy-state-collection ivy-last)
                         #'read-file-name-internal))
-                ;; For `read-file-name' compat, unchanged initial input means
-                ;; that `ivy-read' shall return INITIAL-INPUT.
-                ;; `read-file-name-default' `string-equal' return value with
-                ;; provided INITIAL-INPUT to detect that the user choose the
-                ;; default, `default-filename'.  We must return 
`ivy--directory'
-                ;; in unchanged form in cased `ivy--directory' started out as
-                ;; INITIAL-INPUT in abbreviated form.
-               ivy--directory)          ; Unchanged (unexpanded)
+               (or (ivy-state-def ivy-last)
+                   ivy--directory))
               (t
                (expand-file-name ivy-text ivy--directory))))
   (insert (ivy-state-current ivy-last))
@@ -2023,10 +2017,10 @@ customizations apply to the current completion session."
                          (car ivy--all-candidates))
                    (setq ivy-exit 'done))
                (read-from-minibuffer
-                prompt
-                (ivy-state-initial-input ivy-last)
-                (make-composed-keymap keymap ivy-minibuffer-map)
-                nil
+                          prompt
+                          (ivy-state-initial-input ivy-last)
+                          (make-composed-keymap keymap ivy-minibuffer-map)
+                          nil
                 hist))
              (when (eq ivy-exit 'done)
                (let ((item (if ivy--directory
@@ -2120,14 +2114,14 @@ This is useful for recursive `ivy-read'."
              (require 'tramp)
              (when (and (equal def initial-input)
                         (member "./" ivy-extra-directories))
-               (setf (ivy-state-def state) (setq def nil)))
+               (setq def nil))
              (setq ivy--directory default-directory)
              (when (and initial-input
                         (not (equal initial-input "")))
                (cond ((file-directory-p initial-input)
                       (when (equal (file-name-nondirectory initial-input) "")
                         (setf (ivy-state-preselect state) (setq preselect nil))
-                        (setf (ivy-state-def state) (setq def nil)))
+                        (setq def nil))
                       (setq ivy--directory (file-name-as-directory 
initial-input))
                       (setq initial-input nil)
                       (when preselect



reply via email to

[Prev in Thread] Current Thread [Next in Thread]