]> code.delx.au - gnu-emacs-elpa/blobdiff - ivy.el
ivy.el (ivy-switch-buffer): Preselect other-buffer
[gnu-emacs-elpa] / ivy.el
diff --git a/ivy.el b/ivy.el
index 980046ba06cd6b04182dc3461b84843d97e1018c..1a92d0d1526051a1bba9bbecc00982ffc6f4710f 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -87,6 +87,10 @@ This is usually meant as a quick exit out of the minibuffer."
 Only \"./\" and \"../\" apply here. They appear in reverse order."
   :type 'list)
 
+(defcustom ivy-use-virtual-buffers nil
+  "When non-nil, add `recentf-mode' and bookmarks to the list of buffers."
+  :type 'boolean)
+
 ;;* Keymap
 (require 'delsel)
 (defvar ivy-minibuffer-map
@@ -102,6 +106,7 @@ Only \"./\" and \"../\" apply here. They appear in reverse order."
     (define-key map (kbd "C-r") 'ivy-previous-line-or-history)
     (define-key map (kbd "SPC") 'self-insert-command)
     (define-key map (kbd "DEL") 'ivy-backward-delete-char)
+    (define-key map (kbd "M-DEL") 'ivy-backward-kill-word)
     (define-key map (kbd "M-<") 'ivy-beginning-of-buffer)
     (define-key map (kbd "M->") 'ivy-end-of-buffer)
     (define-key map (kbd "<left>") 'ivy-beginning-of-buffer)
@@ -117,6 +122,12 @@ Only \"./\" and \"../\" apply here. They appear in reverse order."
     map)
   "Keymap used in the minibuffer.")
 
+(defvar ivy-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map [remap switch-to-buffer] 'ivy-switch-buffer)
+    map)
+  "Keymap for `ivy-mode'.")
+
 ;;* Globals
 (cl-defstruct ivy-state
   prompt collection
@@ -125,7 +136,11 @@ Only \"./\" and \"../\" apply here. They appear in reverse order."
   ;; The window in which `ivy-read' was called
   window
   action
-  unwind)
+  unwind
+  re-builder
+  matcher
+  ;; When this is non-nil, call it for each input change to get new candidates
+  dynamic-collection)
 
 (defvar ivy-last nil
   "The last parameters passed to `ivy-read'.")
@@ -164,9 +179,6 @@ Otherwise, store nil.")
 (defvar ivy--default nil
   "Default initial input.")
 
-(defvar ivy--update-fn nil
-  "Current function to call when current candidate(s) update.")
-
 (defvar ivy--prompt nil
   "Store the format-style prompt.
 When non-nil, it should contain one %d.")
@@ -183,46 +195,50 @@ When non-nil, it should contain one %d.")
 (defvar ivy--regex-function 'ivy--regex
   "Current function for building a regex.")
 
-(defvar ivy--collection nil
-  "Store the current collection function.")
-
 (defvar Info-current-file)
 
+(defmacro ivy-quit-and-run (&rest body)
+  "Quit the minibuffer and run BODY afterwards."
+  `(progn
+     (put 'quit 'error-message "")
+     (run-at-time nil nil
+                  (lambda ()
+                    (put 'quit 'error-message "Quit")
+                    ,@body))
+     (minibuffer-keyboard-quit)))
+
+(defun ivy--done (text)
+  "Insert TEXT and exit minibuffer."
+  (if (and ivy--directory
+           (not (eq (ivy-state-history ivy-last) 'grep-files-history)))
+      (insert (expand-file-name
+                 text ivy--directory))
+    (insert text))
+  (setq ivy-exit 'done)
+  (exit-minibuffer))
+
 ;;* Commands
 (defun ivy-done ()
   "Exit the minibuffer with the selected candidate."
   (interactive)
   (delete-minibuffer-contents)
-  (when (cond (ivy--directory
-               (if (zerop ivy--length)
-                   (if (or (not (eq confirm-nonexistent-file-or-buffer t))
-                           (equal " (confirm)" ivy--prompt-extra))
-                       (progn
-                         (insert
-                          (expand-file-name ivy-text ivy--directory))
-                         (setq ivy-exit 'done))
-                     (setq ivy--prompt-extra " (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-state-require-match ivy-last)
-                         '(nil confirm confirm-after-completion))
-                   (progn
-                     (insert ivy-text)
-                     (setq ivy-exit 'done))
-                 (setq ivy--prompt-extra " (match required)")
-                 (insert ivy-text)
-                 (ivy--exhibit)
-                 nil))
-              (t
-               (insert ivy--current)
-               (setq ivy-exit 'done)))
-    (exit-minibuffer)))
+  (cond ((> ivy--length 0)
+         (ivy--done ivy--current))
+        ((memq (ivy-state-collection ivy-last)
+               '(read-file-name-internal internal-complete-buffer))
+         (if (or (not (eq confirm-nonexistent-file-or-buffer t))
+                 (equal " (confirm)" ivy--prompt-extra))
+             (ivy--done ivy-text)
+           (setq ivy--prompt-extra " (confirm)")
+           (insert ivy-text)
+           (ivy--exhibit)))
+        ((memq (ivy-state-require-match ivy-last)
+               '(nil confirm confirm-after-completion))
+         (ivy--done ivy-text))
+        (t
+         (setq ivy--prompt-extra " (match required)")
+         (insert ivy-text)
+         (ivy--exhibit))))
 
 (defun ivy-build-tramp-name (x)
   "Reconstruct X into a path.
@@ -233,6 +249,8 @@ Is is a cons cell, related to `tramp-get-completion-function'."
         (concat user "@" domain)
       domain)))
 
+(declare-function tramp-get-completion-function "tramp")
+
 (defun ivy-alt-done (&optional arg)
   "Exit the minibuffer with the selected candidate.
 When ARG is t, exit with current text, ignoring the candidates."
@@ -278,22 +296,36 @@ When ARG is t, exit with current text, ignoring the candidates."
 When called twice in a row, exit the minibuffer with the current
 candidate."
   (interactive)
-  (if (eq this-command last-command)
-      (progn
-        (delete-minibuffer-contents)
-        (insert ivy--current)
-        (setq ivy-exit 'done)
-        (exit-minibuffer))
-    (let* ((parts (split-string ivy-text " " t))
-           (postfix (car (last parts)))
-           (completion-ignore-case t)
-           (new (try-completion postfix
-                                (mapcar (lambda (str) (substring str (string-match postfix str)))
-                                        ivy--old-cands))))
-      (delete-region (minibuffer-prompt-end) (point-max))
-      (setcar (last parts) new)
-      (insert (mapconcat #'identity parts " ")
-              (if ivy-tab-space " " "")))))
+  (if (and (eq (ivy-state-collection ivy-last) 'read-file-name-internal)
+           (string-match "^/" ivy-text))
+      (let ((default-directory ivy--directory))
+        (minibuffer-complete)
+        (setq ivy-text (ivy--input))
+        (when (and (file-directory-p ivy-text)
+                   (= ivy--length 1))
+          (ivy--cd (expand-file-name ivy-text))))
+    (or (ivy-partial)
+        (if (eq this-command last-command)
+            (ivy-done)
+          (ivy-alt-done)))))
+
+(defun ivy-partial ()
+  "Complete the minibuffer text as much as possible."
+  (interactive)
+  (let* ((parts (or (split-string ivy-text " " t) (list "")))
+         (postfix (car (last parts)))
+         (completion-ignore-case t)
+         (new (try-completion postfix
+                              (mapcar (lambda (str) (substring str (string-match postfix str)))
+                                      ivy--old-cands))))
+    (cond ((eq new t) nil)
+         ((string= new ivy-text) nil)
+          (new
+           (delete-region (minibuffer-prompt-end) (point-max))
+           (setcar (last parts) new)
+           (insert (mapconcat #'identity parts " ")
+                   (if ivy-tab-space " " ""))
+           t))))
 
 (defun ivy-immediate-done ()
   "Exit the minibuffer with the current input."
@@ -318,7 +350,10 @@ candidate."
    :update-fn (ivy-state-update-fn ivy-last)
    :sort (ivy-state-sort ivy-last)
    :action (ivy-state-action ivy-last)
-   :unwind (ivy-state-unwind ivy-last)))
+   :unwind (ivy-state-unwind ivy-last)
+   :re-builder (ivy-state-re-builder ivy-last)
+   :matcher (ivy-state-matcher ivy-last)
+   :dynamic-collection (ivy-state-dynamic-collection ivy-last)))
 
 (defun ivy-beginning-of-buffer ()
   "Select the first completion candidate."
@@ -447,6 +482,19 @@ On error (read-only), call `ivy-on-del-error-function'."
        (when ivy-on-del-error-function
          (funcall ivy-on-del-error-function))))))
 
+(defun ivy-backward-kill-word ()
+  "Forward to `backward-kill-word'."
+  (interactive)
+  (if (and ivy--directory (= (minibuffer-prompt-end) (point)))
+      (progn
+        (ivy--cd (file-name-directory
+                  (directory-file-name
+                   (expand-file-name
+                    ivy--directory))))
+        (ivy--exhibit))
+    (ignore-errors
+      (backward-kill-word 1))))
+
 (defvar ivy--regexp-quote 'regexp-quote
   "Store the regexp quoting state.")
 
@@ -521,7 +569,7 @@ Directories come first."
 (cl-defun ivy-read (prompt collection
                     &key predicate require-match initial-input
                       history preselect keymap update-fn sort
-                      action unwind)
+                      action unwind re-builder matcher dynamic-collection)
   "Read a string in the minibuffer, with completion.
 
 PROMPT is a string to prompt with; normally it ends in a colon
@@ -544,7 +592,14 @@ When SORT is t, refer to `ivy-sort-functions-alist' for sorting.
 
 ACTION is a lambda to call after a result was selected.
 
-UNWIND is a lambda to call before exiting."
+UNWIND is a lambda to call before exiting.
+
+RE-BUILDER is a lambda that transforms text into a regex.
+
+MATCHER can completely override matching.
+
+DYNAMIC-COLLECTION is a function to call to update the list of
+candidates with each input."
   (setq ivy-last
         (make-ivy-state
          :prompt prompt
@@ -559,17 +614,19 @@ UNWIND is a lambda to call before exiting."
          :sort sort
          :action action
          :window (selected-window)
-         :unwind unwind))
+         :unwind unwind
+         :re-builder re-builder
+         :matcher matcher
+         :dynamic-collection dynamic-collection))
   (setq ivy--directory nil)
   (setq ivy--regex-function
-        (or (and (functionp collection)
+        (or re-builder
+            (and (functionp collection)
                  (cdr (assoc collection ivy-re-builders-alist)))
             (cdr (assoc t ivy-re-builders-alist))
             'ivy--regex))
   (setq ivy--subexps 0)
   (setq ivy--regexp-quote 'regexp-quote)
-  (setq ivy--collection (and (functionp collection)
-                             collection))
   (setq ivy--old-text "")
   (setq ivy-text "")
   (let (coll sort-fn)
@@ -583,6 +640,7 @@ UNWIND is a lambda to call before exiting."
              (setq coll (all-completions "" collection predicate))))
           ((eq collection 'read-file-name-internal)
            (setq ivy--directory default-directory)
+           (require 'dired)
            (setq coll
                  (ivy--sorted-files default-directory))
            (when initial-input
@@ -591,14 +649,7 @@ UNWIND is a lambda to call before exiting."
                (setq coll (cons initial-input coll)))
              (setq initial-input nil)))
           ((eq collection 'internal-complete-buffer)
-           (setq coll
-                 (mapcar (lambda (x)
-                           (if (with-current-buffer x
-                                 (file-remote-p
-                                  (abbreviate-file-name default-directory)))
-                               (propertize x 'face 'ivy-remote)
-                             x))
-                         (all-completions "" collection predicate))))
+           (setq coll (ivy--buffer-list "" ivy-use-virtual-buffers)))
           ((or (functionp collection)
                (vectorp collection)
                (listp (car collection)))
@@ -624,6 +675,8 @@ UNWIND is a lambda to call before exiting."
                               coll))
         (setq coll (cons preselect coll))))
     (setq ivy--index (or
+                      (and dynamic-collection
+                           ivy--index)
                       (and preselect
                            (ivy--preselect-index
                             coll initial-input preselect))
@@ -631,7 +684,6 @@ UNWIND is a lambda to call before exiting."
     (setq ivy--old-re nil)
     (setq ivy--old-cands nil)
     (setq ivy--all-candidates coll)
-    (setq ivy--update-fn update-fn)
     (setq ivy-exit nil)
     (setq ivy--default (or (thing-at-point 'symbol) ""))
     (setq ivy--prompt
@@ -648,6 +700,8 @@ UNWIND is a lambda to call before exiting."
              (minibuffer-with-setup-hook
                  #'ivy--minibuffer-setup
                (let* ((hist (or history 'ivy-history))
+                      (minibuffer-completion-table collection)
+                      (minibuffer-completion-predicate predicate)
                       (res (read-from-minibuffer
                             prompt
                             initial-input
@@ -694,14 +748,19 @@ The history, defaults and input-method arguments are ignored for now."
 
 ;;;###autoload
 (define-minor-mode ivy-mode
-    "Toggle Ivy mode on or off.
+  "Toggle Ivy mode on or off.
 With ARG, turn Ivy mode on if arg is positive, off otherwise.
 Turning on Ivy mode will set `completing-read-function' to
 `ivy-completing-read'.
 
+Global bindings:
+\\{ivy-mode-map}
+
+Minibuffer bindings:
 \\{ivy-minibuffer-map}"
   :group 'ivy
   :global t
+  :keymap ivy-mode-map
   :lighter " ivy"
   (if ivy-mode
       (setq completing-read-function 'ivy-completing-read)
@@ -839,11 +898,8 @@ Everything after \"!\" should not match."
     (goto-char (minibuffer-prompt-end))
     (delete-region (line-end-position) (point-max))))
 
-(defvar ivy--dynamic-function nil
-  "When this is non-nil, call it for each input change to get new candidates.")
-
 (defvar ivy--full-length nil
-  "When `ivy--dynamic-function' is non-nil, this can be the total amount of candidates.")
+  "When :dynamic-collection is non-nil, this can be the total amount of candidates.")
 
 (defvar ivy--old-text ""
   "Store old `ivy-text' for dynamic completion.")
@@ -871,7 +927,7 @@ Everything after \"!\" should not match."
                       (if ivy--directory
                           (abbreviate-file-name ivy--directory)
                         ""))
-              (or (and ivy--dynamic-function
+              (or (and (ivy-state-dynamic-collection ivy-last)
                        ivy--full-length)
                   ivy--length))))
         (save-excursion
@@ -903,14 +959,14 @@ Everything after \"!\" should not match."
   "Insert Ivy completions display.
 Should be run via minibuffer `post-command-hook'."
   (setq ivy-text (ivy--input))
-  (if ivy--dynamic-function
+  (if (ivy-state-dynamic-collection ivy-last)
       ;; while-no-input would cause annoying
       ;; "Waiting for process to die...done" message interruptions
       (let ((inhibit-message t))
         (while-no-input
           (unless (equal ivy--old-text ivy-text)
-            (let ((store ivy--dynamic-function)
-                  (ivy--dynamic-function nil))
+            (cl-letf ((store (ivy-state-dynamic-collection ivy-last))
+                      ((ivy-state-dynamic-collection ivy-last) nil))
               (setq ivy--all-candidates (funcall store ivy-text))))
           (ivy--insert-minibuffer (ivy--format ivy--all-candidates))))
     (cond (ivy--directory
@@ -921,19 +977,17 @@ Should be run via minibuffer `post-command-hook'."
                    (ivy--cd "/")))
              (if (string-match "~$" ivy-text)
                  (ivy--cd (expand-file-name "~/")))))
-          ((eq ivy--collection 'internal-complete-buffer)
+          ((eq (ivy-state-collection ivy-last) 'internal-complete-buffer)
            (when (or (and (string-match "^ " ivy-text)
                           (not (string-match "^ " ivy--old-text)))
                      (and (string-match "^ " ivy--old-text)
                           (not (string-match "^ " ivy-text))))
              (setq ivy--all-candidates
-                   (all-completions
-                    (if (and (> (length ivy-text) 0)
-                             (eq (aref ivy-text 0)
-                                 ?\ ))
-                        " "
-                      "")
-                    'internal-complete-buffer))
+                   (if (and (> (length ivy-text) 0)
+                            (eq (aref ivy-text 0)
+                                ?\ ))
+                       (ivy--buffer-list " ")
+                     (ivy--buffer-list "" ivy-use-virtual-buffers)))
              (setq ivy--old-re nil))))
     (ivy--insert-minibuffer
      (ivy--format
@@ -942,11 +996,13 @@ Should be run via minibuffer `post-command-hook'."
 
 (defun ivy--insert-minibuffer (text)
   "Insert TEXT into minibuffer with appropriate cleanup."
-  (ivy--cleanup)
-  (let ((buffer-undo-list t)
+  (let ((resize-mini-windows nil)
+        (buffer-undo-list t)
+        (update-fn (ivy-state-update-fn ivy-last))
         deactivate-mark)
-    (when ivy--update-fn
-      (funcall ivy--update-fn))
+    (ivy--cleanup)
+    (when update-fn
+      (funcall update-fn))
     (ivy--insert-prompt)
     ;; Do nothing if while-no-input was aborted.
     (when (stringp text)
@@ -970,36 +1026,41 @@ Should be run via minibuffer `post-command-hook'."
   "Return all items that match NAME in CANDIDATES.
 CANDIDATES are assumed to be static."
   (let* ((re (funcall ivy--regex-function name))
-         (cands (cond ((and (equal re ivy--old-re)
-                            ivy--old-cands)
-                       ivy--old-cands)
-                      ((and ivy--old-re
-                            (stringp re)
-                            (stringp ivy--old-re)
-                            (not (string-match "\\\\" ivy--old-re))
-                            (not (equal ivy--old-re ""))
-                            (memq (cl-search
-                                   (if (string-match "\\\\)$" ivy--old-re)
-                                       (substring ivy--old-re 0 -2)
-                                     ivy--old-re)
-                                   re) '(0 2)))
-                       (ignore-errors
-                         (cl-remove-if-not
-                          (lambda (x) (string-match re x))
-                          ivy--old-cands)))
-                      (t
-                       (let ((re-list (if (stringp re) (list (cons re t)) re))
-                             (res candidates))
-                         (dolist (re re-list)
-                           (setq res
-                                 (ignore-errors
-                                   (funcall
-                                    (if (cdr re)
-                                        #'cl-remove-if-not
-                                      #'cl-remove-if)
-                                    `(lambda (x) (string-match ,(car re) x))
-                                    res))))
-                         res))))
+         (matcher (ivy-state-matcher ivy-last))
+         (cands (cond
+                  (matcher
+                   (let ((ivy--old-re re))
+                     (cl-remove-if-not matcher candidates)))
+                  ((and (equal re ivy--old-re)
+                        ivy--old-cands)
+                   ivy--old-cands)
+                  ((and ivy--old-re
+                        (stringp re)
+                        (stringp ivy--old-re)
+                        (not (string-match "\\\\" ivy--old-re))
+                        (not (equal ivy--old-re ""))
+                        (memq (cl-search
+                               (if (string-match "\\\\)$" ivy--old-re)
+                                   (substring ivy--old-re 0 -2)
+                                 ivy--old-re)
+                               re) '(0 2)))
+                   (ignore-errors
+                     (cl-remove-if-not
+                      (lambda (x) (string-match re x))
+                      ivy--old-cands)))
+                  (t
+                   (let ((re-list (if (stringp re) (list (cons re t)) re))
+                         (res candidates))
+                     (dolist (re re-list)
+                       (setq res
+                             (ignore-errors
+                               (funcall
+                                (if (cdr re)
+                                    #'cl-remove-if-not
+                                  #'cl-remove-if)
+                                `(lambda (x) (string-match ,(car re) x))
+                                res))))
+                     res))))
          (tail (nthcdr ivy--index ivy--old-cands))
          idx)
     (when (and tail ivy--old-cands)
@@ -1021,9 +1082,34 @@ CANDIDATES are assumed to be static."
             (or (cl-position (ivy-state-preselect ivy-last)
                              cands :test 'equal)
                 ivy--index)))
-    (setq ivy--old-re re)
+    (setq ivy--old-re (if cands re ""))
     (setq ivy--old-cands cands)))
 
+(defvar ivy-format-function 'ivy-format-function-default
+  "Function to transform the list of candidates into a string.
+This string will be inserted into the minibuffer.")
+
+(defun ivy-format-function-default (cands)
+  "Transform CANDS into a string for minibuffer."
+  (let ((ww (window-width)))
+    (mapconcat
+     (lambda (s)
+       (if (> (length s) ww)
+           (concat (substring s 0 (- ww 3)) "...")
+         s))
+     cands "\n")))
+
+(defun ivy-format-function-arrow (cands)
+  "Transform CANDS into a string for minibuffer."
+  (let ((i -1))
+    (mapconcat
+     (lambda (s)
+       (concat (if (eq (cl-incf i) ivy--index)
+                   "==> "
+                 "    ")
+               s))
+     cands "\n")))
+
 (defun ivy--format (cands)
   "Return a string for CANDS suitable for display in the minibuffer.
 CANDS is a list of strings."
@@ -1046,16 +1132,84 @@ CANDS is a list of strings."
       (setq ivy--current (copy-sequence (nth index cands)))
       (setf (nth index cands)
             (ivy--add-face ivy--current 'ivy-current-match))
-      (let* ((ww (window-width))
-             (res (concat "\n" (mapconcat
-                                (lambda (s)
-                                  (if (> (length s) ww)
-                                      (concat (substring s 0 (- ww 3)) "...")
-                                    s))
-                                cands "\n"))))
+      (let* ((ivy--index index)
+             (res (concat "\n" (funcall ivy-format-function cands))))
         (put-text-property 0 (length res) 'read-only nil res)
         res))))
 
+(defvar ivy--virtual-buffers nil
+  "Store the virtual buffers alist.")
+
+(defvar recentf-list)
+(defvar ido-use-faces)
+
+(defun ivy--virtual-buffers ()
+  "Adapted from `ido-add-virtual-buffers-to-list'."
+  (unless recentf-mode
+    (recentf-mode 1))
+  (let ((bookmarks (and (boundp 'bookmark-alist)
+                        bookmark-alist))
+        virtual-buffers name)
+    (dolist (head (append
+                   recentf-list
+                   (delete "   - no file -"
+                           (delq nil (mapcar (lambda (bookmark)
+                                               (cdr (assoc 'filename bookmark)))
+                                             bookmarks)))))
+      (setq name (file-name-nondirectory head))
+      (when (equal name "")
+        (setq name (file-name-nondirectory (directory-file-name head))))
+      (when (equal name "")
+        (setq name head))
+      (and (not (equal name ""))
+           (null (get-file-buffer head))
+           (not (assoc name virtual-buffers))
+           (push (cons name head) virtual-buffers)))
+    (when virtual-buffers
+      (if ido-use-faces
+          (dolist (comp virtual-buffers)
+            (put-text-property 0 (length (car comp))
+                               'face 'ido-virtual
+                               (car comp))))
+      (setq ivy--virtual-buffers (nreverse virtual-buffers))
+      (mapcar #'car ivy--virtual-buffers))))
+
+(defun ivy--buffer-list (str &optional virtual)
+  "Return the buffers that match STR.
+When VIRTUAL is non-nil, add virtual buffers."
+  (delete-dups
+   (append
+    (mapcar
+     (lambda (x)
+       (if (with-current-buffer x
+             (file-remote-p
+              (abbreviate-file-name default-directory)))
+           (propertize x 'face 'ivy-remote)
+         x))
+     (all-completions str 'internal-complete-buffer))
+    (and virtual
+         (ivy--virtual-buffers)))))
+
+(defun ivy--switch-buffer-action ()
+  "Finalizer for `ivy-switch-buffer'."
+  (if (zerop (length ivy--current))
+      (switch-to-buffer
+       ivy-text nil 'force-same-window)
+    (let ((virtual (assoc ivy--current ivy--virtual-buffers)))
+      (if virtual
+          (find-file (cdr virtual))
+        (switch-to-buffer
+         ivy--current nil 'force-same-window)))))
+
+(defun ivy-switch-buffer ()
+  "Switch to another buffer."
+  (interactive)
+  (if (not ivy-mode)
+      (call-interactively 'switch-to-buffer)
+    (ivy-read "Switch to buffer: " 'internal-complete-buffer
+              :action #'ivy--switch-buffer-action
+              :preselect (buffer-name (other-buffer (current-buffer))))))
+
 (provide 'ivy)
 
 ;;; ivy.el ends here