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

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

[elpa] master 3953b16 03/31: Respect `confirm-nonexistent-file-or-buffer


From: Oleh Krehel
Subject: [elpa] master 3953b16 03/31: Respect `confirm-nonexistent-file-or-buffer'
Date: Fri, 01 May 2015 14:28:41 +0000

branch: master
commit 3953b1612532561085740e6f421a5f09fb0fdb76
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Respect `confirm-nonexistent-file-or-buffer'
    
    * ivy.el (ivy--extend-prompt): New defun.
    (ivy-done): Ask for a confirmation if no candidates match and
    `confirm-nonexistent-file-or-buffer' is t.
    
    Re #60
---
 ivy.el |   40 ++++++++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/ivy.el b/ivy.el
index e1d6837..2330ac0 100644
--- a/ivy.el
+++ b/ivy.el
@@ -166,32 +166,44 @@ When non-nil, it should contain one %d.")
 
 (defvar Info-current-file)
 
+(defun ivy--extend-prompt (str)
+  "Extend the current prompt with STR."
+  (unless (string-match str ivy--prompt)
+    (setq ivy--prompt
+          (if (string-match ": $" ivy--prompt)
+              (concat
+               (substring ivy--prompt 0 -2)
+               " " str ": ")
+            (concat ivy--prompt str " ")))))
+
 ;;** Commands
 (defun ivy-done ()
   "Exit the minibuffer with the selected candidate."
   (interactive)
   (delete-minibuffer-contents)
   (when (cond (ivy--directory
-               (insert
-                (if (zerop ivy--length)
-                    (expand-file-name ivy-text ivy--directory)
-                  (expand-file-name ivy--current ivy--directory)))
-               (setq ivy-exit 'done))
+               (if (zerop ivy--length)
+                   (if (or (not (eq confirm-nonexistent-file-or-buffer t))
+                           (string-match "confirm" ivy--prompt))
+                       (progn
+                         (insert
+                          (expand-file-name ivy-text ivy--directory))
+                         (setq ivy-exit 'done))
+                     (ivy--extend-prompt "confirm")
+                     (insert ivy-text)
+                     (ivy--exhibit)
+                     nil)
+                 (insert
+                  (expand-file-name
+                   ivy--current ivy--directory))
+                 (setq ivy-exit 'done)))
               ((zerop ivy--length)
                (if (memq ivy-require-match
                          '(nil confirm confirm-after-completion))
                    (progn
                      (insert ivy-text)
                      (setq ivy-exit 'done))
-                 (unless (string-match "match required" ivy--prompt)
-                   (setq ivy--prompt
-                         (if (string-match ": $" ivy--prompt)
-                             (concat
-                              (substring ivy--prompt 0 -2)
-                              " (match required): ")
-                           (concat
-                            ivy--prompt
-                            "(match required) "))))
+                 (ivy--extend-prompt "(match required)")
                  (insert ivy-text)
                  (ivy--exhibit)
                  nil))



reply via email to

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