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

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

[elpa] master 33689c1 399/399: Merge commit '85d1e2e779ca92e6ef8e47d08f8


From: Oleh Krehel
Subject: [elpa] master 33689c1 399/399: Merge commit '85d1e2e779ca92e6ef8e47d08f866b13d4d87aee' from ivy
Date: Sat, 20 Jul 2019 14:58:07 -0400 (EDT)

branch: master
commit 33689c13c4e670812b8608100042aa4ecf1c796b
Merge: 64d03d9 85d1e2e
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Merge commit '85d1e2e779ca92e6ef8e47d08f866b13d4d87aee' from ivy
---
 packages/ivy/.gitignore        |    1 -
 packages/ivy/.travis.yml       |   16 -
 packages/ivy/Makefile          |    2 +-
 packages/ivy/README.md         |    2 +
 packages/ivy/counsel.el        | 1911 +++++++++++++++++++++++++++------------
 packages/ivy/dir               |   18 +
 packages/ivy/doc/Changelog.org |  698 ++++++++++++++-
 packages/ivy/doc/ivy-help.org  |    2 +-
 packages/ivy/doc/ivy.org       |   45 +-
 packages/ivy/doc/ivy.texi      | 1747 ------------------------------------
 packages/ivy/ivy-hydra.el      |   43 +-
 packages/ivy/ivy-overlay.el    |   71 +-
 packages/ivy/ivy-test.el       |  369 +++++++-
 packages/ivy/ivy.el            | 1213 ++++++++++++++++---------
 packages/ivy/ivy.info          | 1930 ++++++++++++++++++++++++++++++++++++++++
 packages/ivy/swiper.el         |  992 ++++++++++++++++-----
 16 files changed, 6004 insertions(+), 3056 deletions(-)

diff --git a/packages/ivy/.gitignore b/packages/ivy/.gitignore
index a2fa335..5638667 100644
--- a/packages/ivy/.gitignore
+++ b/packages/ivy/.gitignore
@@ -1,6 +1,5 @@
 *.elc
 *~
 /doc/dir
-*.info
 *-autoloads.el
 .dir-locals-2.el
diff --git a/packages/ivy/.travis.yml b/packages/ivy/.travis.yml
deleted file mode 100644
index 0af43c8..0000000
--- a/packages/ivy/.travis.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-language: emacs-lisp
-env:
-  - EVM_EMACS=emacs-24.3-travis
-  - EVM_EMACS=emacs-24.4-travis
-  - EVM_EMACS=emacs-24.5-travis
-  - EVM_EMACS=emacs-git-snapshot-travis
-
-before_install:
-  - git clone https://github.com/rejeep/evm.git $HOME/.evm
-  - export PATH=$HOME/.evm/bin:$PATH
-
-  - evm config path /tmp
-  - evm install $EVM_EMACS --use --skip
-
-script:
-  - make test
diff --git a/packages/ivy/Makefile b/packages/ivy/Makefile
index c6f3eca..2ad6a00 100644
--- a/packages/ivy/Makefile
+++ b/packages/ivy/Makefile
@@ -1,7 +1,7 @@
 emacs ?= emacs
 elmake = $(emacs) -batch -l makefi.el -f
 
-LOAD = -l colir.el -l ivy-overlay.el -l ivy.el -l swiper.el -l counsel.el
+LOAD = -l elpa.el -l colir.el -l ivy-overlay.el -l ivy.el -l swiper.el -l 
counsel.el
 RM ?= rm -f
 
 all: test
diff --git a/packages/ivy/README.md b/packages/ivy/README.md
index 43d4ce5..658504f 100644
--- a/packages/ivy/README.md
+++ b/packages/ivy/README.md
@@ -52,6 +52,8 @@ Ivy and Swiper wiki is here: [the 
wiki](https://github.com/abo-abo/swiper/wiki).
 (ivy-mode 1)
 (setq ivy-use-virtual-buffers t)
 (setq enable-recursive-minibuffers t)
+;; enable this if you want `swiper' to use it
+;; (setq search-default-mode #'char-fold-to-regexp)
 (global-set-key "\C-s" 'swiper)
 (global-set-key (kbd "C-c C-r") 'ivy-resume)
 (global-set-key (kbd "<f6>") 'ivy-resume)
diff --git a/packages/ivy/counsel.el b/packages/ivy/counsel.el
index 97423ec..272a607 100644
--- a/packages/ivy/counsel.el
+++ b/packages/ivy/counsel.el
@@ -4,8 +4,8 @@
 
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.11.0
-;; Package-Requires: ((emacs "24.3") (swiper "0.11.0"))
+;; Version: 0.12.0
+;; Package-Requires: ((emacs "24.3") (swiper "0.12.0"))
 ;; Keywords: convenience, matching, tools
 
 ;; This file is part of GNU Emacs.
@@ -54,7 +54,7 @@
 
 (define-obsolete-function-alias 'counsel-more-chars 'ivy-more-chars "0.10.0")
 
-(defun counsel--elisp-to-pcre (regex)
+(defun counsel--elisp-to-pcre (regex &optional look-around)
   "Convert REGEX from Elisp format to PCRE format, on best-effort basis.
 REGEX may be of any format returned by an Ivy regex function,
 namely a string or a list.  The return value is always a string.
@@ -62,16 +62,29 @@ namely a string or a list.  The return value is always a 
string.
 Note that incorrect results may be returned for sufficiently
 complex regexes."
   (if (consp regex)
-      (mapconcat
-       (lambda (pair)
-         (let ((subexp (counsel--elisp-to-pcre (car pair))))
-           (if (string-match-p "|" subexp)
-               (format "(?:%s)" subexp)
-             subexp)))
-       (cl-remove-if-not #'cdr regex)
-       ".*")
+      (if (and look-around
+               (or (cdr regex)
+                   (not (cdar regex))))
+          (concat
+           "^"
+           (mapconcat
+            (lambda (pair)
+              (let ((subexp (counsel--elisp-to-pcre (car pair))))
+                (format "(?%c.*%s)"
+                        (if (cdr pair) ?= ?!)
+                        subexp)))
+            regex
+            ""))
+        (mapconcat
+         (lambda (pair)
+           (let ((subexp (counsel--elisp-to-pcre (car pair))))
+             (if (string-match-p "|" subexp)
+                 (format "(?:%s)" subexp)
+               subexp)))
+         (cl-remove-if-not #'cdr regex)
+         ".*"))
     (replace-regexp-in-string
-     "\\\\[(){}|]\\|[()]"
+     "\\\\[(){}|`']\\|[()]"
      (lambda (s)
        (or (cdr (assoc s '(("\\(" . "(")
                            ("\\)" . ")")
@@ -79,7 +92,9 @@ complex regexes."
                            (")" . "\\)")
                            ("\\{" . "{")
                            ("\\}" . "}")
-                           ("\\|" . "|"))))
+                           ("\\|" . "|")
+                           ("\\`" . "^")
+                           ("\\'" . "$"))))
            (error
             "Unexpected error in `counsel--elisp-to-pcre' (got match %S)" s)))
      regex t t)))
@@ -99,12 +114,18 @@ complex regexes."
      str)
     str))
 
-(defun counsel-require-program (program)
-  "Check system for PROGRAM, printing error if unfound."
-  (or (and (stringp program)
-           (not (string= program ""))
-           (executable-find program))
-      (user-error "Required program \"%s\" not found in your path" program)))
+(defun counsel-require-program (cmd)
+  "Check system for program used in CMD, printing error if unfound.
+CMD is either a string or a list of strings.
+To skip the `executable-find' check, start the string with a space."
+  (unless (and (stringp cmd) (string-match-p "^ " cmd))
+    (let ((program (if (listp cmd)
+                       (car cmd)
+                     (car (split-string cmd)))))
+      (or (and (stringp program)
+               (not (string= program ""))
+               (executable-find program))
+          (user-error "Required program \"%s\" not found in your path" 
program)))))
 
 (defun counsel-prompt-function-default ()
   "Return prompt appended with a semicolon."
@@ -151,9 +172,18 @@ descriptions.")
 
 (defvar counsel-async-split-string-re "\n"
   "Store the regexp for splitting shell command output.")
+(make-obsolete-variable
+ 'counsel-async-split-string-re 'counsel-async-split-string-re-alist 
"<2019-07-16 Tue>")
+
+(defvar counsel-async-split-string-re-alist '((t . "\n"))
+  "Store the regexp for splitting shell command output.")
 
 (defvar counsel-async-ignore-re nil
   "Regexp matching candidates to ignore in `counsel--async-filter'.")
+(make-obsolete-variable 'counsel-async-ignore-re 
'counsel-async-ignore-re-alist "<2019-07-16 Tue>")
+
+(defvar counsel-async-ignore-re-alist nil
+  "An alist of regexp matching candidates to ignore in 
`counsel--async-filter'.")
 
 (defun counsel--async-command (cmd &optional sentinel filter name)
   "Start and return new counsel process by calling CMD.
@@ -180,6 +210,12 @@ respectively."
 
 (defvar counsel-grep-last-line nil)
 
+(defun counsel--split-string (&optional str)
+  (split-string
+   (or str (buffer-string))
+   (ivy-alist-setting counsel-async-split-string-re-alist)
+   t))
+
 (defun counsel--async-sentinel (process _msg)
   "Sentinel function for an asynchronous counsel PROCESS."
   (when (eq (process-status process) 'exit)
@@ -188,14 +224,16 @@ respectively."
           (ivy--set-candidates
            (ivy--sort-maybe
             (with-current-buffer (process-buffer process)
-              (split-string (buffer-string) counsel-async-split-string-re t))))
+              (counsel--split-string))))
           (setq counsel-grep-last-line nil)
           (when counsel--async-start
             (setq counsel--async-duration
                   (time-to-seconds (time-since counsel--async-start))))
           (let ((re (ivy-re-to-str (funcall ivy--regex-function ivy-text))))
             (if ivy--old-cands
-                (ivy--recompute-index ivy-text re ivy--all-candidates)
+                (if (eq (ivy-alist-setting ivy-index-functions-alist) 
'ivy-recompute-index-zero)
+                    (ivy-set-index 0)
+                  (ivy--recompute-index ivy-text re ivy--all-candidates))
               (unless (ivy-set-index
                        (ivy--preselect-index
                         (ivy-state-preselect ivy-last)
@@ -230,12 +268,11 @@ Update the minibuffer with the amount of lines collected 
every
       (with-current-buffer (process-buffer process)
         (setq numlines (count-lines (point-min) (point-max)))
         (ivy--set-candidates
-         (let ((lines (split-string (buffer-string)
-                                    counsel-async-split-string-re
-                                    t)))
-           (if (stringp counsel-async-ignore-re)
+         (let ((lines (counsel--split-string))
+               (ignore-re (ivy-alist-setting counsel-async-ignore-re-alist)))
+           (if (stringp ignore-re)
                (cl-remove-if (lambda (line)
-                               (string-match-p counsel-async-ignore-re line))
+                               (string-match-p ignore-re line))
                              lines)
              lines))))
       (let ((ivy--prompt (format "%d++ %s" numlines (ivy-state-prompt 
ivy-last))))
@@ -303,6 +340,7 @@ Update the minibuffer with the amount of lines collected 
every
 (declare-function jedi:complete-request "ext:jedi-core")
 (declare-function jedi:ac-direct-matches "ext:jedi")
 
+;;;###autoload
 (defun counsel-jedi ()
   "Python completion at point."
   (interactive)
@@ -361,12 +399,11 @@ Update the minibuffer with the amount of lines collected 
every
 
 ;;** `counsel-company'
 (defvar company-candidates)
-(defvar company-point)
 (defvar company-common)
+(defvar company-prefix)
+(declare-function company-abort "ext:company")
 (declare-function company-complete "ext:company")
 (declare-function company-mode "ext:company")
-(declare-function company-complete-common "ext:company")
-(declare-function company-abort "ext:company")
 
 ;;;###autoload
 (defun counsel-company ()
@@ -375,13 +412,17 @@ Update the minibuffer with the amount of lines collected 
every
   (company-mode 1)
   (unless company-candidates
     (company-complete))
-  (when company-point
-    (when (looking-back company-common (line-beginning-position))
-      (setq ivy-completion-beg (match-beginning 0))
-      (setq ivy-completion-end (match-end 0)))
-    (ivy-read "company cand: " company-candidates
-              :action #'ivy-completion-in-region-action
-              :unwind #'company-abort)))
+  (let ((len (cond (company-common
+                    (length company-common))
+                   (company-prefix
+                    (length company-prefix)))))
+    (when len
+      (setq ivy-completion-beg (- (point) len))
+      (setq ivy-completion-end (point))
+      (ivy-read "Candidate: " company-candidates
+                :action #'ivy-completion-in-region-action
+                :unwind #'company-abort
+                :caller 'counsel-company))))
 
 ;;** `counsel-irony'
 (declare-function irony-completion-candidates-async "ext:irony-completion")
@@ -602,26 +643,30 @@ to `ivy-highlight-face'."
 (defun counsel--setq-doconst (x)
   "Return a cons of description and value for X.
 X is an item of a radio- or choice-type defcustom."
-  (let (y)
-    (when (and (listp x)
-               (consp (setq y (last x))))
-      (unless (equal y '(function))
-        (setq x (car y))
-        (cons (prin1-to-string x)
-              (if (symbolp x)
-                  (list 'quote x)
-                x))))))
+  (when (listp x)
+    (let ((v (car-safe (last x)))
+          (tag (and (eq (car x) 'const)
+                    (plist-get (cdr x) :tag))))
+      (when (and (or v tag) (not (eq v 'function)))
+        (cons
+         (concat
+          (when tag
+            (concat tag ": "))
+          (if (stringp v) v (prin1-to-string v)))
+         (if (symbolp v)
+             (list 'quote v)
+           v))))))
 
 (declare-function lv-message "ext:lv")
 (declare-function lv-delete-window "ext:lv")
 (declare-function custom-variable-documentation "cus-edit")
 
-;;;###autoload
 (defface counsel-variable-documentation
   '((t :inherit font-lock-comment-face))
   "Face for displaying Lisp documentation."
   :group 'ivy-faces)
 
+;;;###autoload
 (defun counsel-set-variable (sym)
   "Set a variable SYM, with completion.
 
@@ -748,22 +793,30 @@ With prefix arg MODE a query for the symbol help mode is 
offered."
   "Face used by `counsel-M-x' for key bindings."
   :group 'ivy-faces)
 
+(defcustom counsel-alias-expand t
+  "When non-nil, show the expansion of aliases in `counsel-M-x'."
+  :type 'boolean
+  :group 'ivy)
+
 (defun counsel-M-x-transformer (cmd)
   "Return CMD annotated with its active key binding, if any."
-  (let ((key (where-is-internal (intern cmd) nil t)))
-    (if (not key)
-        cmd
-      ;; Prefer `<f2>' over `C-x 6' where applicable
-      (let ((i (cl-search [?\C-x ?6] key)))
-        (when i
-          (let ((dup (vconcat (substring key 0 i) [f2] (substring key (+ i 
2))))
-                (map (current-global-map)))
-            (when (equal (lookup-key map key)
-                         (lookup-key map dup))
-              (setq key dup)))))
-      (setq key (key-description key))
-      (put-text-property 0 (length key) 'face 'counsel-key-binding key)
-      (format "%s (%s)" cmd key))))
+  (let ((alias (symbol-function (intern cmd)))
+        (key (where-is-internal (intern cmd) nil t)))
+    (concat cmd
+            (when (and (symbolp alias) counsel-alias-expand)
+              (format " (%s)" alias))
+            (when key
+              ;; Prefer `<f2>' over `C-x 6' where applicable
+              (let ((i (cl-search [?\C-x ?6] key)))
+                (when i
+                  (let ((dup (vconcat (substring key 0 i) [f2] (substring key 
(+ i 2))))
+                        (map (current-global-map)))
+                    (when (equal (lookup-key map key)
+                                 (lookup-key map dup))
+                      (setq key dup)))))
+              (setq key (key-description key))
+              (put-text-property 0 (length key) 'face 'counsel-key-binding key)
+              (format " (%s)" key)))))
 
 (defvar amx-initialized)
 (defvar amx-cache)
@@ -872,6 +925,7 @@ when available, in that order of precedence."
  '(("r" counsel-command-history-action-eval           "eval command")
    ("e" counsel-command-history-action-edit-and-eval  "edit and eval 
command")))
 
+;;;###autoload
 (defun counsel-command-history ()
   "Show the history of commands."
   (interactive)
@@ -996,7 +1050,8 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
 (ivy-set-actions
  'counsel-descbinds
  '(("d" counsel-descbinds-action-find "definition")
-   ("I" counsel-descbinds-action-info "info")))
+   ("I" counsel-descbinds-action-info "info")
+   ("x" counsel-descbinds-action-exec "execute")))
 
 (defvar counsel-descbinds-history nil
   "History for `counsel-descbinds'.")
@@ -1037,11 +1092,21 @@ See `describe-buffer-bindings' for further information."
         (forward-line 1)))
     (nreverse res)))
 
+(defcustom counsel-descbinds-function #'describe-function
+  "Function to call to describe a function passed as parameter."
+  :type 'function)
+
 (defun counsel-descbinds-action-describe (x)
   "Describe function of candidate X.
 See `describe-function' for further information."
   (let ((cmd (cddr x)))
-    (describe-function cmd)))
+    (funcall counsel-descbinds-function cmd)))
+
+(defun counsel-descbinds-action-exec (x)
+  "Run candidate X.
+See `execute-extended-command' for further information."
+  (let ((cmd (cddr x)))
+    (command-execute cmd 'record)))
 
 (defun counsel-descbinds-action-find (x)
   "Find symbol definition of candidate X.
@@ -1078,6 +1143,7 @@ back to the face of the character after point, and 
finally the
 `default' face."
   (symbol-name (or (face-at-point t) 'default)))
 
+;;;###autoload
 (defun counsel-describe-face ()
   "Completion for `describe-face'."
   (interactive)
@@ -1103,17 +1169,20 @@ back to the face of the character after point, and 
finally the
    ("C" counsel-customize-face-other-window "customize other window")))
 
 ;;** `counsel-faces'
-(defun counsel--faces-format-function (format)
-  "Return an `ivy-format-function' for `counsel-faces'.
+(defvar counsel--faces-format "%-40s %s")
+
+(defun counsel--faces-format-function (names)
+  "Customize `ivy-format-functions-alist' for `counsel-faces'.
 Each candidate is formatted based on the given FORMAT string."
-  (let ((formatter (lambda (name)
-                     (format format name (propertize list-faces-sample-text
-                                                     'face (intern name))))))
-    (lambda (names)
-      (ivy--format-function-generic
-       (lambda (name)
-         (funcall formatter (ivy--add-face name 'ivy-current-match)))
-       formatter names "\n"))))
+  (let ((formatter
+         (lambda (name)
+           (format counsel--faces-format name
+                   (propertize list-faces-sample-text
+                               'face (intern name))))))
+    (ivy--format-function-generic
+     (lambda (name)
+       (funcall formatter (ivy--add-face name 'ivy-current-match)))
+     formatter names "\n")))
 
 ;;;###autoload
 (defun counsel-faces ()
@@ -1122,10 +1191,9 @@ Actions are provided by default for describing or 
customizing the
 selected face."
   (interactive)
   (let* ((names (mapcar #'symbol-name (face-list)))
-         (ivy-format-function
-          (counsel--faces-format-function
-           (format "%%-%ds %%s"
-                   (apply #'max 0 (mapcar #'string-width names))))))
+         (counsel--faces-format
+          (format "%%-%ds %%s"
+                  (apply #'max 0 (mapcar #'string-width names)))))
     (ivy-read "Face: " names
               :require-match t
               :history 'face-name-history
@@ -1134,6 +1202,8 @@ selected face."
               :action counsel-describe-face-function
               :caller 'counsel-faces)))
 
+(add-to-list 'ivy-format-functions-alist '(counsel-faces . 
counsel--faces-format-function))
+
 (ivy-set-actions
  'counsel-faces
  '(("c" counsel-customize-face "customize")
@@ -1149,23 +1219,33 @@ selected face."
  '(("j" find-file-other-window "other window")
    ("x" counsel-find-file-extern "open externally")))
 
+(defun counsel--dominating-file (file &optional dir)
+  "Look up directory hierarchy for FILE, starting in DIR.
+Like `locate-dominating-file', but DIR defaults to
+`default-directory' and the return value is expanded."
+  (and (setq dir (locate-dominating-file (or dir default-directory) file))
+       (expand-file-name dir)))
+
 (defun counsel-locate-git-root ()
-  "Locate the root of the git repository containing the current buffer."
-  (or (locate-dominating-file default-directory ".git")
-      (error "Not in a git repository")))
+  "Return the root of the Git repository containing the current buffer."
+  (or (counsel--git-root)
+      (error "Not in a Git repository")))
+
+(defun counsel-git-cands ()
+  (let ((default-directory (counsel-locate-git-root)))
+    (split-string
+     (shell-command-to-string counsel-git-cmd)
+     "\n"
+     t)))
 
 ;;;###autoload
 (defun counsel-git (&optional initial-input)
   "Find file in the current Git repository.
 INITIAL-INPUT can be given as the initial minibuffer input."
   (interactive)
-  (counsel-require-program (car (split-string counsel-git-cmd)))
-  (let* ((default-directory (expand-file-name (counsel-locate-git-root)))
-         (cands (split-string
-                 (shell-command-to-string counsel-git-cmd)
-                 "\n"
-                 t)))
-    (ivy-read "Find file: " cands
+  (counsel-require-program counsel-git-cmd)
+  (let ((default-directory (counsel-locate-git-root)))
+    (ivy-read "Find file: " (counsel-git-cands)
               :initial-input initial-input
               :action #'counsel-git-action
               :caller 'counsel-git)))
@@ -1181,9 +1261,9 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
   (cd (ivy-state-directory ivy-last))
   (counsel-cmd-to-dired
    (counsel--expand-ls
-    (format "%s | grep -i -E '%s' | xargs ls"
+    (format "%s | %s | xargs ls"
             counsel-git-cmd
-            (counsel--elisp-to-pcre ivy--old-re)))))
+            (counsel--file-name-filter)))))
 
 (defvar counsel-dired-listing-switches "-alh"
   "Switches passed to `ls' for `counsel-cmd-to-dired'.")
@@ -1233,12 +1313,6 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
 (defvar counsel-git-grep-cmd nil
   "Store the command for `counsel-git-grep'.")
 
-(defvar counsel--git-grep-count nil
-  "Store the line count in current repository.")
-
-(defvar counsel--git-grep-count-threshold 20000
-  "The maximum threshold beyond which repositories are considered large.")
-
 (defvar counsel-git-grep-history nil
   "History for `counsel-git-grep'.")
 
@@ -1251,18 +1325,32 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
 Typical value: '(recenter)."
   :type 'hook)
 
-(defun counsel-git-grep-function (str &optional _pred &rest _unused)
-  "Grep in the current git repository for STRING."
+(defcustom counsel-git-grep-cmd-function 
#'counsel-git-grep-cmd-function-default
+  "How a git-grep shell call is built from the input."
+  :type '(radio
+          (function-item counsel-git-grep-cmd-function-default)
+          (function-item counsel-git-grep-cmd-function-ignore-order)
+          (function :tag "Other")))
+
+(defun counsel-git-grep-cmd-function-default (str)
+  (format counsel-git-grep-cmd
+          (setq ivy--old-re (ivy--regex str t))))
+
+(defun counsel-git-grep-cmd-function-ignore-order (str)
+  (setq ivy--old-re (ivy--regex str t))
+  (let ((parts (split-string str " " t)))
+    (concat
+     "git --no-pager grep --full-name -n --no-color -i -e "
+     (mapconcat #'shell-quote-argument parts " --and -e "))))
+
+(defun counsel-git-grep-function (string)
+  "Grep in the current Git repository for STRING."
   (or
-   (and (> counsel--git-grep-count counsel--git-grep-count-threshold)
-        (ivy-more-chars))
-   (let* ((default-directory (ivy-state-directory ivy-last))
-          (cmd (format counsel-git-grep-cmd
-                       (setq ivy--old-re (ivy--regex str t)))))
-     (if (<= counsel--git-grep-count counsel--git-grep-count-threshold)
-         (split-string (shell-command-to-string cmd) "\n" t)
-       (counsel--gg-candidates (ivy--regex str))
-       nil))))
+   (ivy-more-chars)
+   (progn
+     (counsel--async-command
+      (funcall counsel-git-grep-cmd-function string))
+     nil)))
 
 (defun counsel-git-grep-action (x)
   "Go to occurrence X in current Git repository."
@@ -1281,31 +1369,6 @@ Typical value: '(recenter)."
         (swiper--cleanup)
         (swiper--add-overlays (ivy--regex ivy-text))))))
 
-(defun counsel-git-grep-matcher (regexp candidates)
-  "Return REGEXP matching CANDIDATES for `counsel-git-grep'."
-  (or (and (equal regexp ivy--old-re)
-           ivy--old-cands)
-      (prog1
-          (setq ivy--old-cands
-                (cl-remove-if-not
-                 (lambda (x)
-                   (ignore-errors
-                     (when (string-match "^[^:]+:[^:]+:" x)
-                       (setq x (substring x (match-end 0)))
-                       (if (stringp regexp)
-                           (string-match regexp x)
-                         (let ((res t))
-                           (dolist (re regexp)
-                             (setq res
-                                   (and res
-                                        (ignore-errors
-                                          (if (cdr re)
-                                              (string-match (car re) x)
-                                            (not (string-match (car re) 
x)))))))
-                           res)))))
-                 candidates))
-        (setq ivy--old-re regexp))))
-
 (defun counsel-git-grep-transformer (str)
   "Higlight file and line number in STR."
   (when (string-match "\\`\\([^:]+\\):\\([^:]+\\):" str)
@@ -1344,7 +1407,9 @@ files in a project.")
        (setq cmd counsel-git-grep-cmd-default)))
     (cons proj cmd)))
 
-(defun counsel--call (&rest command)
+(define-obsolete-function-alias 'counsel--call 'counsel--command "0.11.0")
+
+(defun counsel--command (&rest command)
   "Synchronously call COMMAND and return its output as a string.
 COMMAND comprises the program name followed by its arguments, as
 in `make-process'.  Signal `file-error' and emit a warning if
@@ -1379,20 +1444,9 @@ COMMAND fails.  Obey file handlers based on 
`default-directory'."
              (signal (car status) (cdr status))))
       (delete-file stderr))))
 
-(defun counsel--git-grep-count-func-default ()
-  "Default function to calculate `counsel--git-grep-count'."
-  (or (unless (eq system-type 'windows-nt)
-        (ignore-errors
-          (let ((git-dir (counsel--call "git" "rev-parse" "--git-dir")))
-            (read (counsel--call "du" "-s" git-dir)))))
-      0))
-
-(defvar counsel--git-grep-count-func #'counsel--git-grep-count-func-default
-  "Defun to calculate `counsel--git-grep-count' for `counsel-git-grep'.")
-
 ;;;###autoload
 (defun counsel-git-grep (&optional cmd initial-input)
-  "Grep for a string in the current git repository.
+  "Grep for a string in the current Git repository.
 When CMD is a string, use it as a \"git grep\" command.
 When CMD is non-nil, prompt for a specific \"git grep\" command.
 INITIAL-INPUT can be given as the initial minibuffer input."
@@ -1401,29 +1455,21 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
         proj)
     (setq proj (car proj-and-cmd))
     (setq counsel-git-grep-cmd (cdr proj-and-cmd))
-    (counsel-require-program (car (split-string counsel-git-grep-cmd)))
+    (counsel-require-program counsel-git-grep-cmd)
     (let ((collection-function
            (if proj
                #'counsel-git-grep-proj-function
              #'counsel-git-grep-function))
           (unwind-function
-           (if proj
-               (lambda ()
-                 (counsel-delete-process)
-                 (swiper--cleanup))
-             (lambda ()
-               (swiper--cleanup))))
+           (lambda ()
+             (counsel-delete-process)
+             (swiper--cleanup)))
           (default-directory (if proj
                                  (car proj)
                                (counsel-locate-git-root))))
-      (setq counsel--git-grep-count (funcall counsel--git-grep-count-func))
       (ivy-read "git grep: " collection-function
                 :initial-input initial-input
-                :matcher #'counsel-git-grep-matcher
-                :dynamic-collection (or proj
-                                        (>
-                                         counsel--git-grep-count
-                                         counsel--git-grep-count-threshold))
+                :dynamic-collection t
                 :keymap counsel-git-grep-map
                 :action #'counsel-git-grep-action
                 :unwind unwind-function
@@ -1432,7 +1478,7 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
 (cl-pushnew 'counsel-git-grep ivy-highlight-grep-commands)
 
 (defun counsel-git-grep-proj-function (str)
-  "Grep for STR in the current git repository."
+  "Grep for STR in the current Git repository."
   (or
    (ivy-more-chars)
    (let ((regex (setq ivy--old-re
@@ -1452,67 +1498,6 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
     (setq ivy--all-candidates
           (all-completions "" 'counsel-git-grep-function))))
 
-(defvar counsel-gg-state nil
-  "The current state of candidates / count sync.")
-
-(defun counsel--gg-candidates (regex)
-  "Return git grep candidates for REGEX."
-  (setq counsel-gg-state -2)
-  (counsel--gg-count regex)
-  (let ((default-directory (ivy-state-directory ivy-last)))
-    (set-process-filter
-     (counsel--async-command (concat (format counsel-git-grep-cmd regex)
-                                     " | head -n 200")
-                             #'counsel--gg-sentinel)
-     nil)))
-
-(defun counsel--gg-sentinel (process _msg)
-  "Sentinel function for a `counsel-git-grep' PROCESS."
-  (when (eq (process-status process) 'exit)
-    (cl-case (process-exit-status process)
-      ((0 141)
-       (with-current-buffer (process-buffer process)
-         (setq ivy--all-candidates
-               (or (split-string (buffer-string) "\n" t)
-                   '("")))
-         (setq ivy--old-cands ivy--all-candidates))
-       (when (zerop (cl-incf counsel-gg-state))
-         (ivy--exhibit)))
-      (1
-       (setq ivy--all-candidates '("Error"))
-       (setq ivy--old-cands ivy--all-candidates)
-       (ivy--exhibit)))))
-
-(defun counsel--gg-count-sentinel (process _msg)
-  "Sentinel function for a `counsel--gg-count' PROCESS."
-  (when (and (eq (process-status process) 'exit)
-             (zerop (process-exit-status process)))
-    (with-current-buffer (process-buffer process)
-      (setq ivy--full-length (string-to-number (buffer-string))))
-    (when (zerop (cl-incf counsel-gg-state))
-      (ivy--exhibit))))
-
-(defun counsel--gg-count (regex &optional no-async)
-  "Count the number of results matching REGEX in `counsel-git-grep'.
-The command to count the matches is called asynchronously.
-If NO-ASYNC is non-nil, do it synchronously instead."
-  (let ((default-directory (ivy-state-directory ivy-last))
-        (cmd (concat
-              (format (replace-regexp-in-string
-                       "--full-name" "-c"
-                       counsel-git-grep-cmd)
-                      ;; "git grep -i -c '%s'"
-                      (replace-regexp-in-string
-                       "-" "\\\\-"
-                       (replace-regexp-in-string "'" "''" regex)))
-              " | sed 's/.*:\\(.*\\)/\\1/g' | awk '{s+=$1} END {print s}'")))
-    (if no-async
-        (string-to-number (shell-command-to-string cmd))
-      (set-process-filter
-       (counsel--async-command cmd #'counsel--gg-count-sentinel
-                               nil " *counsel-gg-count*")
-       nil))))
-
 (defun counsel--normalize-grep-match (str)
   ;; Prepend ./ if necessary:
   (unless (ivy--starts-with-dotslash str)
@@ -1548,10 +1533,7 @@ When REVERT is non-nil, regenerate the current 
*ivy-occur* buffer."
                        " ")))
          (cmd (concat (format counsel-git-grep-cmd positive-pattern) 
negative-patterns))
          cands)
-    (setq cands (split-string
-                 (shell-command-to-string cmd)
-                 counsel-async-split-string-re
-                 t))
+    (setq cands (counsel--split-string (shell-command-to-string cmd)))
     ;; Need precise number of header lines for `wgrep' to work.
     (insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
                     default-directory))
@@ -1609,8 +1591,10 @@ done") "\n" t)))
 (defvar counsel-git-log-cmd "GIT_PAGER=cat git log --grep '%s'"
   "Command used for \"git log\".")
 
-(defvar counsel-git-log-split-string-re "\ncommit "
+(defvar counsel-git-log-split-string-re "^commit "
   "The `split-string' separates when split output of `counsel-git-log-cmd'.")
+(make-obsolete-variable
+ 'counsel-git-log-split-string-re 'counsel-async-split-string-re-alist 
"<2019-07-16 Tue>")
 
 (defun counsel-git-log-function (str)
   "Search for STR in git log."
@@ -1631,6 +1615,18 @@ done") "\n" t)))
   "Add candidate X to kill ring."
   (message "%S" (kill-new x)))
 
+(declare-function magit-show-commit "ext:magit-diff")
+
+(defun counsel-git-log-show-commit-action (log-entry)
+  "Visit the commit corresponding to LOG-ENTRY."
+  (require 'magit-diff)
+  (let ((commit (substring-no-properties log-entry 0 (string-match-p "\\W" 
log-entry))))
+    (magit-show-commit commit)))
+
+(ivy-set-actions
+ 'counsel-git-log
+ '(("v" counsel-git-log-show-commit-action "visit commit")))
+
 ;;** `counsel-git-change-worktree'
 (defun counsel-git-change-worktree-action (git-root-dir tree)
   "Find the corresponding file in the worktree located at tree.
@@ -1642,7 +1638,7 @@ TREE is the selected candidate."
     (find-file file-name)))
 
 (defun counsel-git-worktree-list ()
-  "List worktrees in the git repository containing the current buffer."
+  "List worktrees in the Git repository containing the current buffer."
   (let ((default-directory (counsel-locate-git-root)))
     (split-string (shell-command-to-string "git worktree list") "\n" t)))
 
@@ -1686,10 +1682,12 @@ The command is passed a single argument comprising all 
characters
 in BRANCH up to, but not including, the first space
 character (#x20), or the string's end if it lacks a space."
   (shell-command
-   (format "git checkout %s" (substring branch 0 (string-match-p " " 
branch)))))
+   (format "git checkout %s"
+           (shell-quote-argument
+            (substring branch 0 (string-match-p " " branch))))))
 
 (defun counsel-git-branch-list ()
-  "Return list of branches in the current git repository.
+  "Return list of branches in the current Git repository.
 Value comprises all local and remote branches bar the one
 currently checked out."
   (cl-mapcan (lambda (line)
@@ -1709,21 +1707,24 @@ currently checked out."
 
 (defvar counsel-yank-pop-truncate-radius)
 
+(defun counsel--git-log-format-function (str)
+  (let ((counsel-yank-pop-truncate-radius 5))
+    (counsel--yank-pop-format-function str)))
+
 ;;;###autoload
 (defun counsel-git-log ()
   "Call the \"git log --grep\" shell command."
   (interactive)
-  (let ((counsel-async-split-string-re counsel-git-log-split-string-re)
-        (counsel-async-ignore-re "^[ \n]*$")
-        (counsel-yank-pop-truncate-radius 5)
-        (ivy-format-function #'counsel--yank-pop-format-function))
-    (ivy-read "Grep log: " #'counsel-git-log-function
-              :dynamic-collection t
-              :action #'counsel-git-log-action
-              :unwind #'counsel-delete-process
-              :caller 'counsel-git-log)))
+  (ivy-read "Grep log: " #'counsel-git-log-function
+            :dynamic-collection t
+            :action #'counsel-git-log-action
+            :unwind #'counsel-delete-process
+            :caller 'counsel-git-log))
 
+(add-to-list 'ivy-format-functions-alist '(counsel-git-log . 
counsel--git-log-format-function))
 (add-to-list 'ivy-height-alist '(counsel-git-log . 4))
+(add-to-list 'counsel-async-split-string-re-alist '(counsel-git-log . "^commit 
"))
+(add-to-list 'counsel-async-ignore-re-alist '(counsel-git-log . "^[ \n]*$"))
 
 ;;* File
 ;;** `counsel-find-file'
@@ -1731,13 +1732,11 @@ currently checked out."
   (let ((map (make-sparse-keymap)))
     (define-key map (kbd "C-DEL") 'counsel-up-directory)
     (define-key map (kbd "C-<backspace>") 'counsel-up-directory)
-    (define-key map (kbd "C-M-y") 'counsel-yank-directory)
+    (define-key map (kbd "`") (ivy-make-magic-action 'counsel-find-file "b"))
     map))
 
-(defun counsel-yank-directory ()
-  "Yank the current directory into the minibuffer."
-  (interactive)
-  (insert ivy--directory))
+(define-obsolete-function-alias 'counsel-yank-directory 
'ivy-insert-current-full
+  "<2019-06-13 Thu>")
 
 (when (executable-find "git")
   (add-to-list 'ivy-ffap-url-functions 'counsel-github-url-p)
@@ -1789,6 +1788,15 @@ choose between `yes-or-no-p' and `y-or-n-p'; otherwise 
default to
              #'yes-or-no-p)
            (apply #'format fmt args)))
 
+(defun counsel-find-file-copy (x)
+  "Copy file X."
+  (require 'dired-aux)
+  (counsel--find-file-1 "Copy file to: "
+                        ivy--directory
+                        (lambda (new-name)
+                          (dired-copy-file x new-name 1))
+                        'counsel-find-file-copy))
+
 (defun counsel-find-file-delete (x)
   "Delete file X."
   (when (or delete-by-moving-to-trash
@@ -1797,20 +1805,27 @@ choose between `yes-or-no-p' and `y-or-n-p'; otherwise 
default to
             (counsel--yes-or-no-p "Delete %s? " x))
     (dired-delete-file x dired-recursive-deletes delete-by-moving-to-trash)
     (dired-clean-up-after-deletion x)
-    (ivy--reset-state ivy-last)))
+    (let ((win (and (not (eq ivy-exit 'done))
+                    (active-minibuffer-window))))
+      (when win (with-selected-window win (ivy--cd ivy--directory))))))
 
 (defun counsel-find-file-move (x)
   "Move or rename file X."
-  (ivy-read "Rename file to: " #'read-file-name-internal
-            :matcher #'counsel--find-file-matcher
-            :action (lambda (new-name)
-                      (require 'dired-aux)
-                      (dired-rename-file x new-name 1))
-            :keymap counsel-find-file-map
-            :caller 'counsel-find-file-move))
+  (require 'dired-aux)
+  (counsel--find-file-1 "Rename file to: "
+                        ivy--directory
+                        (lambda (new-name)
+                          (dired-rename-file x new-name 1))
+                        'counsel-find-file-move))
 
 (defun counsel-find-file-mkdir-action (_x)
-  (make-directory (expand-file-name ivy-text ivy--directory)))
+  "Create a directory from `ivy-text'."
+  (let ((dir (file-name-as-directory
+              (expand-file-name ivy-text ivy--directory)))
+        (win (and (not (eq ivy-exit 'done))
+                  (active-minibuffer-window))))
+    (make-directory dir)
+    (when win (with-selected-window win (ivy--cd dir)))))
 
 (ivy-set-actions
  'counsel-find-file
@@ -1820,6 +1835,7 @@ choose between `yes-or-no-p' and `y-or-n-p'; otherwise 
default to
    ("x" counsel-find-file-extern "open externally")
    ("r" counsel-find-file-as-root "open as root")
    ("k" counsel-find-file-delete "delete")
+   ("c" counsel-find-file-copy "copy file")
    ("m" counsel-find-file-move "move or rename")
    ("d" counsel-find-file-mkdir-action "mkdir")))
 
@@ -1845,7 +1861,7 @@ a dot. The generic way to toggle ignored files is 
\\[ivy-toggle-ignore],
 but the leading dot is a lot faster."
   :type `(choice
           (const :tag "None" nil)
-          (const :tag "Dotfiles" "\\`\\.")
+          (const :tag "Dotfiles and Lockfiles" 
"\\(?:\\`\\|[/\\]\\)\\(?:[#.]\\)")
           (const :tag "Ignored Extensions"
                  ,(regexp-opt completion-ignored-extensions))
           (regexp :tag "Regex")))
@@ -1861,12 +1877,12 @@ Skip some dotfiles unless `ivy-text' requires them."
               (string-match re-str (directory-file-name x)))))))
     (if (or (null ivy-use-ignore)
             (null counsel-find-file-ignore-regexp)
-            (string-match "\\`\\." ivy-text))
+            (string-match-p "\\`\\." ivy-text))
         res
       (or (cl-remove-if
            (lambda (x)
              (and
-              (string-match counsel-find-file-ignore-regexp x)
+              (string-match-p counsel-find-file-ignore-regexp x)
               (not (member x ivy-extra-directories))))
            res)
           res))))
@@ -1876,14 +1892,21 @@ Skip some dotfiles unless `ivy-text' requires them."
 (defvar counsel-find-file-speedup-remote t
   "Speed up opening remote files by disabling `find-file-hook' for them.")
 
+(defcustom counsel-find-file-extern-extensions '("mp4" "mkv" "xlsx")
+  "List of extensions that make `counsel-find-file' use 
`counsel-find-file-extern'."
+  :type '(repeat string))
+
 (defun counsel-find-file-action (x)
   "Find file X."
   (with-ivy-window
-    (if (and counsel-find-file-speedup-remote
-             (file-remote-p ivy--directory))
-        (let ((find-file-hook nil))
-          (find-file (expand-file-name x ivy--directory)))
-      (find-file (expand-file-name x ivy--directory)))))
+    (cond ((and counsel-find-file-speedup-remote
+                (file-remote-p ivy--directory))
+           (let ((find-file-hook nil))
+             (find-file (expand-file-name x ivy--directory))))
+          ((member (file-name-extension x) counsel-find-file-extern-extensions)
+           (counsel-find-file-extern x))
+          (t
+           (find-file (expand-file-name x ivy--directory))))))
 
 (defun counsel--preselect-file ()
   "Return candidate to preselect during filename completion.
@@ -1899,24 +1922,30 @@ The preselect behaviour can be customized via user 
options
         buffer-file-name
         (file-name-nondirectory buffer-file-name))))
 
-;;;###autoload
-(defun counsel-find-file (&optional initial-input)
-  "Forward to `find-file'.
-When INITIAL-INPUT is non-nil, use it in the minibuffer during completion."
-  (interactive)
-  (ivy-read "Find file: " #'read-file-name-internal
+(defun counsel--find-file-1 (prompt initial-input action caller)
+  (ivy-read prompt #'read-file-name-internal
             :matcher #'counsel--find-file-matcher
             :initial-input initial-input
-            :action #'counsel-find-file-action
+            :action action
             :preselect (counsel--preselect-file)
             :require-match 'confirm-after-completion
             :history 'file-name-history
             :keymap counsel-find-file-map
-            :caller 'counsel-find-file))
+            :caller caller))
+
+;;;###autoload
+(defun counsel-find-file (&optional initial-input)
+  "Forward to `find-file'.
+When INITIAL-INPUT is non-nil, use it in the minibuffer during completion."
+  (interactive)
+  (counsel--find-file-1
+   "Find file: " initial-input
+   #'counsel-find-file-action
+   'counsel-find-file))
 
 (ivy-set-occur 'counsel-find-file 'counsel-find-file-occur)
 
-(defvar counsel-find-file-occur-cmd "ls -a | grep -i -E '%s' | xargs -d '\\n' 
ls -d --group-directories-first"
+(defvar counsel-find-file-occur-cmd "ls -a | %s | xargs -d '\\n' ls -d 
--group-directories-first"
   "Format string for `counsel-find-file-occur'.")
 
 (defvar counsel-find-file-occur-use-find (not (eq system-type 'gnu/linux))
@@ -1926,11 +1955,49 @@ When INITIAL-INPUT is non-nil, use it in the minibuffer 
during completion."
   "Expand CMD that ends in \"ls\" with switches."
   (concat cmd " " counsel-dired-listing-switches " | sed -e \"s/^/  /\""))
 
+(defvar counsel-file-name-filter-alist
+  '(("ag -i '%s'" . t)
+    ("ack -i '%s'" . t)
+    ("perl -ne '/(%s.*)/i && print \"$1\\n\";'" . t)
+    ("grep -i -E '%s'"))
+  "Alist of file name filtering commands.
+The car is a shell command and the cdr is t when the shell
+command supports look-arounds.  The executable for the commands
+will be checked for existence via `executable-find'.  The first
+one that exists will be used.")
+
+(defun counsel--file-name-filter (&optional use-ignore)
+  "Return a command that filters a file list to match ivy candidates.
+If USE-IGNORE is non-nil, try to generate a command that respects
+`counsel-find-file-ignore-regexp'."
+  (let ((regex ivy--old-re)
+        (filter-cmd (cl-find-if
+                     (lambda (x)
+                       (executable-find
+                        (car (split-string (car x)))))
+                     counsel-file-name-filter-alist))
+        cmd)
+    (when (and use-ignore ivy-use-ignore
+               counsel-find-file-ignore-regexp
+               (cdr filter-cmd)
+               (not (string-match-p "\\`\\." ivy-text))
+               (not (string-match-p counsel-find-file-ignore-regexp
+                                    (or (car ivy--old-cands) ""))))
+      (let ((ignore-re (list (counsel--elisp-to-pcre
+                              counsel-find-file-ignore-regexp))))
+        (setq regex (if (stringp regex)
+                        (list ignore-re (cons regex t))
+                      (cons ignore-re regex)))))
+    (setq cmd (format (car filter-cmd)
+                      (counsel--elisp-to-pcre regex (cdr filter-cmd))))
+    (if (string-match-p "csh\\'" shell-file-name)
+        (replace-regexp-in-string "\\?!" "?\\\\!" cmd)
+      cmd)))
+
 (defun counsel--occur-cmd-find ()
-  (let* ((regex (counsel--elisp-to-pcre ivy--old-re))
-         (cmd (format
-               "find . -maxdepth 1 | grep -i -E '%s' | xargs -I {} find {} 
-maxdepth 0 -ls"
-               regex)))
+  (let ((cmd (format
+              "find . -maxdepth 1 | %s | xargs -I {} find {} -maxdepth 0 -ls"
+              (counsel--file-name-filter t))))
     (concat
      (counsel--cmd-to-dired-by-type "d" cmd)
      " && "
@@ -1955,13 +2022,29 @@ When INITIAL-INPUT is non-nil, use it in the minibuffer 
during completion."
     (counsel-cmd-to-dired
      (counsel--expand-ls
       (format counsel-find-file-occur-cmd
-              (counsel--elisp-to-pcre ivy--old-re))))))
+              (if (string-match-p "grep" counsel-find-file-occur-cmd)
+                  ;; for backwards compatibility
+                  (counsel--elisp-to-pcre ivy--old-re)
+                (counsel--file-name-filter t)))))))
+
+(defvar counsel-up-directory-level t
+  "Control whether `counsel-up-directory' goes up a level or always a 
directory.
+
+If non-nil, then `counsel-up-directory' will remove the final level of the 
path.
+For example: /a/long/path/file.jpg => /a/long/path/
+             /a/long/path/     =>     /a/long/
+
+If nil, then `counsel-up-directory' will go up a directory.
+For example: /a/long/path/file.jpg => /a/long/
+             /a/long/path/     =>     /a/long/")
 
 (defun counsel-up-directory ()
   "Go to the parent directory preselecting the current one.
 
 If the current directory is remote and it's not possible to go up any
-further, make the remote prefix editable"
+further, make the remote prefix editable.
+
+See variable `counsel-up-directory-level'."
   (interactive)
   (let* ((cur-dir (directory-file-name (expand-file-name ivy--directory)))
          (up-dir (file-name-directory cur-dir)))
@@ -1976,9 +2059,11 @@ further, make the remote prefix editable"
           (setq ivy-text "")
           (delete-minibuffer-contents)
           (insert up-dir))
-      (ivy--cd up-dir)
-      (setf (ivy-state-preselect ivy-last)
-            (file-name-as-directory (file-name-nondirectory cur-dir))))))
+      (if (and counsel-up-directory-level (not (string= ivy-text "")))
+          (delete-region (line-beginning-position) (line-end-position))
+        (ivy--cd up-dir)
+        (setf (ivy-state-preselect ivy-last)
+              (file-name-as-directory (file-name-nondirectory cur-dir)))))))
 
 (defun counsel-down-directory ()
   "Descend into the current directory."
@@ -2057,15 +2142,29 @@ will be expanded according to its format.  This 
function is
 intended to be used in `ivy-ffap-url-functions' to browse the
 result as a URL."
   (let ((word-at-point (current-word)))
-    (cl-some
-     (lambda (pair)
-       (let ((regexp (car pair))
-             (formatter (cdr pair)))
-         (when (string-match regexp word-at-point)
-           (if (functionp formatter)
-               (funcall formatter word-at-point)
-             (format formatter word-at-point)))))
-     counsel-url-expansions-alist)))
+    (when word-at-point
+      (cl-some
+       (lambda (pair)
+         (let ((regexp (car pair))
+               (formatter (cdr pair)))
+           (when (string-match regexp word-at-point)
+             (if (functionp formatter)
+                 (funcall formatter word-at-point)
+               (format formatter word-at-point)))))
+       counsel-url-expansions-alist))))
+
+;;** `counsel-dired'
+(declare-function dired "dired")
+
+;;;###autoload
+(defun counsel-dired (&optional initial-input)
+  "Forward to `dired'.
+When INITIAL-INPUT is non-nil, use it in the minibuffer during completion."
+  (interactive)
+  (counsel--find-file-1
+   "Dired (directory): " initial-input
+   (lambda (d) (dired (expand-file-name d)))
+   'counsel-dired))
 
 ;;** `counsel-recentf'
 (defvar recentf-list)
@@ -2081,6 +2180,7 @@ result as a URL."
             :action (lambda (f)
                       (with-ivy-window
                         (find-file f)))
+            :require-match t
             :caller 'counsel-recentf))
 (ivy-set-actions
  'counsel-recentf
@@ -2203,7 +2303,7 @@ can use `C-x r j i' to open that file."
  '(("j" find-file-other-window "other window")))
 
 ;;** `counsel-locate'
-(defcustom counsel-locate-cmd (cond ((eq system-type 'darwin)
+(defcustom counsel-locate-cmd (cond ((memq system-type '(darwin berkeley-unix))
                                      'counsel-locate-cmd-noregex)
                                     ((and (eq system-type 'windows-nt)
                                           (executable-find "es.exe"))
@@ -2231,6 +2331,7 @@ string - the full shell command to run."
 (defvar counsel-locate-history nil
   "History for `counsel-locate'.")
 
+;;;###autoload
 (defun counsel-locate-action-extern (x)
   "Pass X to `xdg-open' or equivalent command via the shell."
   (interactive "FFile: ")
@@ -2286,11 +2387,30 @@ string - the full shell command to run."
       (funcall counsel-locate-cmd input))
      '("" "working..."))))
 
+(defcustom counsel-locate-db-path "~/.local/mlocate.db"
+  "Location where to put the locatedb in case your home folder is encrypted."
+  :type 'file)
+
+(defun counsel--locate-updatedb ()
+  (when (file-exists-p "~/.Private")
+    (let ((db-fname (expand-file-name counsel-locate-db-path)))
+      (setenv "LOCATE_PATH" db-fname)
+      (when (or (not (file-exists-p db-fname))
+                (> (time-to-seconds
+                    (time-subtract
+                     (current-time)
+                     (nth 5 (file-attributes db-fname))))
+                   60))
+        (message "Updating %s..." db-fname)
+        (counsel--command
+         "updatedb" "-l" "0" "-o" db-fname "-U" (expand-file-name "~"))))))
+
 ;;;###autoload
 (defun counsel-locate (&optional initial-input)
   "Call the \"locate\" shell command.
 INITIAL-INPUT can be given as the initial minibuffer input."
   (interactive)
+  (counsel--locate-updatedb)
   (ivy-read "Locate: " #'counsel-locate-function
             :initial-input initial-input
             :dynamic-collection t
@@ -2325,7 +2445,7 @@ INITIAL-INPUT can be given as the initial minibuffer 
input."
   (let ((default-directory counsel--fzf-dir))
     (setq ivy--old-re (ivy--regex-fuzzy str))
     (counsel--async-command
-     (list "fzf" "-f" str)))
+     (format counsel-fzf-cmd str)))
   nil)
 
 ;;;###autoload
@@ -2341,20 +2461,18 @@ FZF-PROMPT, if non-nil, is passed as `ivy-read' prompt 
argument."
              (read-directory-name (concat
                                    fzf-basename
                                    " in directory: "))))))
-
-  (let ((fzf-basename (car (split-string counsel-fzf-cmd))))
-    (counsel-require-program fzf-basename)
-    (setq counsel--fzf-dir
-          (or initial-directory
-              (funcall counsel-fzf-dir-function)))
-    (ivy-read (or fzf-prompt (concat fzf-basename ": "))
-              #'counsel-fzf-function
-              :initial-input initial-input
-              :re-builder #'ivy--regex-fuzzy
-              :dynamic-collection t
-              :action #'counsel-fzf-action
-              :unwind #'counsel-delete-process
-              :caller 'counsel-fzf)))
+  (counsel-require-program counsel-fzf-cmd)
+  (setq counsel--fzf-dir
+        (or initial-directory
+            (funcall counsel-fzf-dir-function)))
+  (ivy-read (or fzf-prompt "fzf: ")
+            #'counsel-fzf-function
+            :initial-input initial-input
+            :re-builder #'ivy--regex-fuzzy
+            :dynamic-collection t
+            :action #'counsel-fzf-action
+            :unwind #'counsel-delete-process
+            :caller 'counsel-fzf))
 
 (defun counsel-fzf-action (x)
   "Find file X in current fzf directory."
@@ -2422,7 +2540,7 @@ FZF-PROMPT, if non-nil, is passed as `ivy-read' prompt 
argument."
                         (message (cdr x)))
               :caller 'counsel-rpm)))
 
-(defcustom counsel-file-jump-args "* -type f -not -path '*\/.git*'"
+(defcustom counsel-file-jump-args ". -name '.git' -prune -o -type f -print | 
cut -c 3-"
   "Arguments for the `find-command' when using `counsel-file-jump'."
   :type 'string)
 
@@ -2437,8 +2555,8 @@ INITIAL-DIRECTORY, if non-nil, is used as the root 
directory for search."
    (list nil
          (when current-prefix-arg
            (read-directory-name "From directory: "))))
-  (counsel-require-program "find")
-  (let* ((default-directory (or initial-directory default-directory)))
+  (counsel-require-program find-program)
+  (let ((default-directory (or initial-directory default-directory)))
     (ivy-read "Find file: "
               (split-string
                (shell-command-to-string
@@ -2446,23 +2564,27 @@ INITIAL-DIRECTORY, if non-nil, is used as the root 
directory for search."
                "\n" t)
               :matcher #'counsel--find-file-matcher
               :initial-input initial-input
-              :action (lambda (x)
-                        (with-ivy-window
-                          (find-file (expand-file-name x ivy--directory))))
+              :action #'find-file
               :preselect (counsel--preselect-file)
               :require-match 'confirm-after-completion
               :history 'file-name-history
               :keymap counsel-find-file-map
               :caller 'counsel-file-jump)))
 
-(defcustom counsel-dired-jump-args "* -type f -not -path '*\/.git*'"
+(ivy-set-actions
+ 'counsel-file-jump
+ `(("d" ,(lambda (x)
+           (dired (or (file-name-directory x) default-directory)))
+    "open in dired")))
+
+(defcustom counsel-dired-jump-args ". -name '.git' -prune -o -type d -print | 
cut -c 3-"
   "Arguments for the `find-command' when using `counsel-dired-jump'."
   :type 'string)
 
 ;;** `counsel-dired-jump'
 ;;;###autoload
 (defun counsel-dired-jump (&optional initial-input initial-directory)
-  "Jump to a directory (in dired) below the current directory.
+  "Jump to a directory (see `dired-jump') below the current directory.
 List all subdirectories within the current directory.
 INITIAL-INPUT can be given as the initial minibuffer input.
 INITIAL-DIRECTORY, if non-nil, is used as the root directory for search."
@@ -2470,15 +2592,18 @@ INITIAL-DIRECTORY, if non-nil, is used as the root 
directory for search."
    (list nil
          (when current-prefix-arg
            (read-directory-name "From directory: "))))
-  (counsel-require-program "find")
-  (let* ((default-directory (or initial-directory default-directory)))
-    (ivy-read "Directory: "
+  (counsel-require-program find-program)
+  (let ((default-directory (or initial-directory default-directory)))
+    (ivy-read "Find directory: "
               (split-string
                (shell-command-to-string
                 (concat find-program " " counsel-dired-jump-args))
                "\n" t)
+              :matcher #'counsel--find-file-matcher
               :initial-input initial-input
               :action (lambda (d) (dired-jump nil (expand-file-name d)))
+              :history 'file-name-history
+              :keymap counsel-find-file-map
               :caller 'counsel-dired-jump)))
 
 ;;* Grep
@@ -2508,6 +2633,7 @@ It applies no filtering to ivy--all-candidates."
     (define-key map (kbd "C-l") 'ivy-call-and-recenter)
     (define-key map (kbd "M-q") 'counsel-git-grep-query-replace)
     (define-key map (kbd "C-'") 'swiper-avy)
+    (define-key map (kbd "C-x C-d") 'counsel-cd)
     map))
 
 (defcustom counsel-ag-base-command
@@ -2521,6 +2647,10 @@ regex string."
 
 (defvar counsel-ag-command nil)
 
+(defvar counsel--grep-tool-look-around t)
+
+(defvar counsel--regex-look-around nil)
+
 (counsel-set-async-exit-code 'counsel-ag 1 "No matches found")
 (ivy-set-occur 'counsel-ag 'counsel-ag-occur)
 (ivy-set-display-transformer 'counsel-ag 'counsel-git-grep-transformer)
@@ -2552,33 +2682,46 @@ NEEDLE is the search string."
 (defun counsel--grep-regex (str)
   (counsel--elisp-to-pcre
    (setq ivy--old-re
-         (funcall ivy--regex-function str))))
+         (funcall ivy--regex-function str))
+   counsel--regex-look-around))
+
+(defun counsel--ag-extra-switches (regex)
+  "Get additional switches needed for look-arounds."
+  (and (stringp counsel--regex-look-around)
+       ;; using look-arounds
+       (string-match-p "\\`\\^(\\?[=!]" regex)
+       (concat " " counsel--regex-look-around " ")))
 
 (defun counsel-ag-function (string)
   "Grep in the current directory for STRING."
-  (let ((command-args (counsel--split-command-args string)))
-    (let ((switches (car command-args))
-          (search-term (cdr command-args)))
-      (or
-       (let ((ivy-text search-term))
-         (ivy-more-chars))
-       (let ((default-directory (ivy-state-directory ivy-last))
-             (regex (counsel--grep-regex search-term)))
-         (counsel--async-command (counsel--format-ag-command
-                                  switches
-                                  (shell-quote-argument regex)))
-         nil)))))
+  (let* ((command-args (counsel--split-command-args string))
+         (search-term (cdr command-args)))
+    (or
+     (let ((ivy-text search-term))
+       (ivy-more-chars))
+     (let* ((default-directory (ivy-state-directory ivy-last))
+            (regex (counsel--grep-regex search-term))
+            (switches (concat (car command-args)
+                              (counsel--ag-extra-switches regex)
+                              (and (ivy--case-fold-p string) " -i "))))
+       (counsel--async-command (counsel--format-ag-command
+                                switches
+                                (shell-quote-argument regex)))
+       nil))))
 
 ;;;###autoload
-(defun counsel-ag (&optional initial-input initial-directory extra-ag-args 
ag-prompt)
+(cl-defun counsel-ag (&optional initial-input initial-directory extra-ag-args 
ag-prompt
+                      &key caller)
   "Grep for a string in the current directory using ag.
 INITIAL-INPUT can be given as the initial minibuffer input.
 INITIAL-DIRECTORY, if non-nil, is used as the root directory for search.
 EXTRA-AG-ARGS string, if non-nil, is appended to `counsel-ag-base-command'.
-AG-PROMPT, if non-nil, is passed as `ivy-read' prompt argument."
+AG-PROMPT, if non-nil, is passed as `ivy-read' prompt argument.
+CALLER is passed to `ivy-read'."
   (interactive)
   (setq counsel-ag-command counsel-ag-base-command)
-  (counsel-require-program (car (split-string counsel-ag-command)))
+  (setq counsel--regex-look-around counsel--grep-tool-look-around)
+  (counsel-require-program counsel-ag-command)
   (when current-prefix-arg
     (setq initial-directory
           (or initial-directory
@@ -2592,7 +2735,7 @@ AG-PROMPT, if non-nil, is passed as `ivy-read' prompt 
argument."
                                      (car (split-string 
counsel-ag-command)))))))
   (setq counsel-ag-command (counsel--format-ag-command (or extra-ag-args "") 
"%s"))
   (let ((default-directory (or initial-directory
-                               (locate-dominating-file default-directory 
".git")
+                               (counsel--git-root)
                                default-directory)))
     (ivy-read (or ag-prompt
                   (concat (car (split-string counsel-ag-command)) ": "))
@@ -2605,7 +2748,16 @@ AG-PROMPT, if non-nil, is passed as `ivy-read' prompt 
argument."
               :unwind (lambda ()
                         (counsel-delete-process)
                         (swiper--cleanup))
-              :caller 'counsel-ag)))
+              :caller (or caller 'counsel-ag))))
+
+(defun counsel-cd ()
+  "Change the directory for the currently running Ivy command."
+  (interactive)
+  (let ((input ivy-text)
+        (new-dir (read-directory-name "cd: ")))
+    (ivy-quit-and-run
+      (let ((default-directory new-dir))
+        (funcall (ivy-state-caller ivy-last) input)))))
 
 (cl-pushnew 'counsel-ag ivy-highlight-grep-commands)
 
@@ -2617,15 +2769,14 @@ AG-PROMPT, if non-nil, is passed as `ivy-read' prompt 
argument."
         (and (string-match "\"\\(.*\\)\"" (buffer-name))
              (match-string 1 (buffer-name))))
   (let* ((command-args (counsel--split-command-args ivy-text))
+         (regex (counsel--grep-regex (cdr command-args)))
+         (switches (concat (car command-args)
+                           (counsel--ag-extra-switches regex)))
          (cmd (format cmd-template
                       (concat
-                       (car command-args)
-                       (shell-quote-argument
-                        (counsel--elisp-to-pcre
-                         (ivy--regex (cdr command-args)))))))
-         (cands (split-string (shell-command-to-string cmd)
-                              counsel-async-split-string-re
-                              t)))
+                       switches
+                       (shell-quote-argument regex))))
+         (cands (counsel--split-string (shell-command-to-string cmd))))
     ;; Need precise number of header lines for `wgrep' to work.
     (insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
                     default-directory))
@@ -2650,8 +2801,9 @@ INITIAL-INPUT can be given as the initial minibuffer 
input.
 This uses `counsel-ag' with `counsel-pt-base-command' instead of
 `counsel-ag-base-command'."
   (interactive)
-  (let ((counsel-ag-base-command counsel-pt-base-command))
-    (counsel-ag initial-input)))
+  (let ((counsel-ag-base-command counsel-pt-base-command)
+        (counsel--grep-tool-look-around nil))
+    (counsel-ag initial-input :caller 'counsel-pt)))
 (cl-pushnew 'counsel-pt ivy-highlight-grep-commands)
 
 ;;** `counsel-ack'
@@ -2670,8 +2822,9 @@ INITIAL-INPUT can be given as the initial minibuffer 
input.
 This uses `counsel-ag' with `counsel-ack-base-command' replacing
 `counsel-ag-base-command'."
   (interactive)
-  (let ((counsel-ag-base-command counsel-ack-base-command))
-    (counsel-ag initial-input)))
+  (let ((counsel-ag-base-command counsel-ack-base-command)
+        (counsel--grep-tool-look-around t))
+    (counsel-ag initial-input :caller 'counsel-ack)))
 
 
 ;;** `counsel-rg'
@@ -2691,10 +2844,19 @@ Note: don't use single quotes for the regex."
 INITIAL-INPUT can be given as the initial minibuffer input.
 INITIAL-DIRECTORY, if non-nil, is used as the root directory for search.
 EXTRA-RG-ARGS string, if non-nil, is appended to `counsel-rg-base-command'.
-RG-PROMPT, if non-nil, is passed as `ivy-read' prompt argument."
+RG-PROMPT, if non-nil, is passed as `ivy-read' prompt argument.
+
+Example input with inclusion and exclusion file patterns:
+    -g*.py -g!*test* -- ..."
   (interactive)
-  (let ((counsel-ag-base-command counsel-rg-base-command))
-    (counsel-ag initial-input initial-directory extra-rg-args rg-prompt)))
+  (let ((counsel-ag-base-command counsel-rg-base-command)
+        (counsel--grep-tool-look-around
+         (let ((rg (car (split-string counsel-rg-base-command)))
+               (switch "--pcre2"))
+           (and (eq 0 (call-process rg nil nil nil switch "--version"))
+                switch))))
+    (counsel-ag initial-input initial-directory extra-rg-args rg-prompt
+                :caller 'counsel-rg)))
 (cl-pushnew 'counsel-rg ivy-highlight-grep-commands)
 
 ;;** `counsel-grep'
@@ -2771,6 +2933,9 @@ substituted by the search regexp and file, respectively.  
Neither
 (ivy-set-occur 'counsel-grep 'counsel-grep-occur)
 (counsel-set-async-exit-code 'counsel-grep 1 "")
 
+(defvar counsel-grep-history nil
+  "History for `counsel-grep'.")
+
 ;;;###autoload
 (defun counsel-grep (&optional initial-input)
   "Grep for a string in the file visited by the current buffer.
@@ -2778,12 +2943,15 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
   (interactive)
   (unless buffer-file-name
     (user-error "Current buffer is not visiting a file"))
-  (counsel-require-program (car (split-string counsel-grep-base-command)))
+  (counsel-require-program counsel-grep-base-command)
   (setq counsel-grep-last-line nil)
   (setq counsel-grep-command
         (format counsel-grep-base-command
-                "%s" (shell-quote-argument buffer-file-name)))
-  (let ((init-point (point))
+                "%s" (shell-quote-argument
+                      (file-name-nondirectory
+                       buffer-file-name))))
+  (let ((default-directory (file-name-directory buffer-file-name))
+        (init-point (point))
         res)
     (unwind-protect
          (setq res (ivy-read "grep: " 'counsel-grep-function
@@ -2799,9 +2967,8 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
                                          (line-end-position)))))
 
                              :keymap counsel-grep-map
-                             :history 'counsel-git-grep-history
-                             :update-fn (lambda ()
-                                          (counsel-grep-action 
(ivy-state-current ivy-last)))
+                             :history 'counsel-grep-history
+                             :update-fn 'auto
                              :re-builder #'ivy--regex
                              :action #'counsel-grep-action
                              :unwind (lambda ()
@@ -2811,6 +2978,16 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
       (unless res
         (goto-char init-point)))))
 
+;;;###autoload
+(defun counsel-grep-backward (&optional initial-input)
+  "Grep for a string in the file visited by the current buffer going
+backward similar to `swiper-backward'. When non-nil, INITIAL-INPUT is
+the initial search pattern."
+  (interactive)
+  (let ((ivy-index-functions-alist
+         '((counsel-grep . ivy-recompute-index-swiper-async-backward))))
+    (counsel-grep initial-input)))
+
 ;;** `counsel-grep-or-swiper'
 (defcustom counsel-grep-swiper-limit 300000
   "Buffer size threshold for `counsel-grep-or-swiper'.
@@ -2818,6 +2995,19 @@ When the number of characters in a buffer exceeds this 
threshold,
 `counsel-grep' will be used instead of `swiper'."
   :type 'integer)
 
+(defcustom counsel-grep-use-swiper-p #'counsel-grep-use-swiper-p-default
+  "When this function returns non-nil, call `swiper', else `counsel-grep'."
+  :type '(choice
+          (const :tag "Rely on `counsel-grep-swiper-limit'."
+           counsel-grep-use-swiper-p-default)
+          (const :tag "Always use `counsel-grep'." ignore)
+          (function :tag "Custom")))
+
+(defun counsel-grep-use-swiper-p-default ()
+  (<= (buffer-size)
+      (/ counsel-grep-swiper-limit
+         (if (eq major-mode 'org-mode) 4 1))))
+
 ;;;###autoload
 (defun counsel-grep-or-swiper (&optional initial-input)
   "Call `swiper' for small buffers and `counsel-grep' for large ones.
@@ -2828,14 +3018,23 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
           (ignore-errors
             (file-remote-p buffer-file-name))
           (jka-compr-get-compression-info buffer-file-name)
-          (<= (buffer-size)
-              (/ counsel-grep-swiper-limit
-                 (if (eq major-mode 'org-mode) 4 1))))
+          (funcall counsel-grep-use-swiper-p))
       (swiper initial-input)
     (when (file-writable-p buffer-file-name)
       (save-buffer))
     (counsel-grep initial-input)))
 
+;;** `counsel-grep-or-swiper-backward'
+;;;###autoload
+(defun counsel-grep-or-swiper-backward (&optional initial-input)
+  "Call `swiper-backward' for small buffers and `counsel-grep-backward' for
+large ones.  When non-nil, INITIAL-INPUT is the initial search pattern."
+  (interactive)
+  (let ((ivy-index-functions-alist
+         '((swiper . ivy-recompute-index-swiper-backward)
+           (counsel-grep . ivy-recompute-index-swiper-async-backward))))
+    (counsel-grep-or-swiper initial-input)))
+
 ;;** `counsel-recoll'
 (defun counsel-recoll-function (str)
   "Run recoll for STR."
@@ -2855,6 +3054,7 @@ When non-nil, INITIAL-INPUT is the initial search 
pattern."
 ;; You can try the GUI version of recoll with:
 ;;     sudo apt-get install recoll
 ;; Unfortunately, that does not install recollq.
+;;;###autoload
 (defun counsel-recoll (&optional initial-input)
   "Search for a string in the recoll database.
 You'll be given a list of files that match.
@@ -3008,6 +3208,7 @@ otherwise continue prompting for tags."
                  (org-get-tags nil t)
                (error (org-get-tags)))))
 
+;;;###autoload
 (defun counsel-org-tag ()
   "Add or remove tags in `org-mode'."
   (interactive)
@@ -3042,17 +3243,17 @@ otherwise continue prompting for tags."
                 :action #'counsel-org-tag-action
                 :caller 'counsel-org-tag))))
 
+(defvar org-version)
+
 ;;;###autoload
 (defun counsel-org-tag-agenda ()
   "Set tags for the current agenda item."
   (interactive)
-  (let ((store (symbol-function 'org-set-tags)))
-    (unwind-protect
-         (progn
-           (fset 'org-set-tags
-                 (symbol-function 'counsel-org-tag))
-           (org-agenda-set-tags nil nil))
-      (fset 'org-set-tags store))))
+  (cl-letf (((symbol-function (if (version< org-version "9.2")
+                                  'org-set-tags
+                                'org-set-tags-command))
+             #'counsel-org-tag))
+    (org-agenda-set-tags)))
 
 (define-obsolete-variable-alias 'counsel-org-goto-display-tags
     'counsel-org-headline-display-tags "0.10.0")
@@ -3079,6 +3280,89 @@ otherwise continue prompting for tags."
 ;;;###autoload
 (defalias 'counsel-org-goto #'counsel-outline)
 
+(defcustom counsel-org-goto-all-outline-path-prefix nil
+  "Prefix for outline candidates in `counsel-org-goto-all'."
+  :type '(choice
+          (const :tag "None" nil)
+          (const :tag "File name" file-name)
+          (const :tag "File name (nondirectory part)" file-name-nondirectory)
+          (const :tag "Buffer name" buffer-name)))
+
+(defun counsel-org-goto-all--outline-path-prefix ()
+  (cl-case counsel-org-goto-all-outline-path-prefix
+    (file-name buffer-file-name)
+    (file-name-nondirectory (file-name-nondirectory buffer-file-name))
+    (buffer-name (buffer-name))))
+
+(defvar counsel-outline-settings
+  '((emacs-lisp-mode
+     :outline-regexp ";;[;*]+[\s\t]+"
+     :outline-level counsel-outline-level-emacs-lisp)
+    (org-mode
+     :outline-title counsel-outline-title-org
+     :action counsel-org-goto-action
+     :history counsel-org-goto-history
+     :caller counsel-org-goto)
+    ;; markdown-mode package
+    (markdown-mode
+     :outline-title counsel-outline-title-markdown)
+    ;; Built-in mode or AUCTeX package
+    (latex-mode
+     :outline-title counsel-outline-title-latex))
+  "Alist mapping major modes to their `counsel-outline' settings.
+
+Each entry is a pair (MAJOR-MODE . PLIST).  `counsel-outline'
+checks whether an entry exists for the current buffer's
+MAJOR-MODE and, if so, loads the settings specified by PLIST
+instead of the default settings.  The following settings are
+recognized:
+
+- `:outline-regexp' is a regexp to match the beggining of an
+  outline heading.  It is only checked at the start of a line and
+  so need not start with \"^\".
+  Defaults to the value of the variable `outline-regexp'.
+
+- `:outline-level' is a function of no arguments which computes
+  the level of an outline heading.  It is called with point at
+  the beginning of `outline-regexp' and with the match data
+  corresponding to `outline-regexp'.
+  Defaults to the value of the variable `outline-level'.
+
+- `:outline-title' is a function of no arguments which returns
+  the title of an outline heading.  It is called with point at
+  the end of `outline-regexp' and with the match data
+  corresponding to `outline-regexp'.
+  Defaults to the function `counsel-outline-title'.
+
+- `:action' is a function of one argument, the selected outline
+  heading to jump to.  This setting corresponds directly to its
+  eponymous `ivy-read' keyword, as used by `counsel-outline', so
+  the type of the function's argument depends on the value
+  returned by `counsel-outline-candidates'.
+  Defaults to the function `counsel-outline-action'.
+
+- `:history' is a history list, usually a symbol representing a
+  history list variable.  It corresponds directly to its
+  eponymous `ivy-read' keyword, as used by `counsel-outline'.
+  Defaults to the symbol `counsel-outline-history'.
+
+- `:caller' is a symbol to uniquely idendify the caller to
+  `ivy-read'.  It corresponds directly to its eponymous
+  `ivy-read' keyword, as used by `counsel-outline'.
+  Defaults to the symbol `counsel-outline'.
+
+- `:display-style' overrides the variable
+  `counsel-outline-display-style'.
+
+- `:path-separator' overrides the variable
+  `counsel-outline-path-separator'.
+
+- `:face-style' overrides the variable
+  `counsel-outline-face-style'.
+
+- `:custom-faces' overrides the variable
+  `counsel-outline-custom-faces'.")
+
 ;;;###autoload
 (defun counsel-org-goto-all ()
   "Go to a different location in any org file."
@@ -3087,7 +3371,11 @@ otherwise continue prompting for tags."
     (dolist (b (buffer-list))
       (with-current-buffer b
         (when (derived-mode-p 'org-mode)
-          (setq entries (nconc entries (counsel-outline-candidates))))))
+          (setq entries
+                (nconc entries
+                       (counsel-outline-candidates
+                        (cdr (assq 'org-mode counsel-outline-settings))
+                        (counsel-org-goto-all--outline-path-prefix)))))))
     (ivy-read "Goto: " entries
               :history 'counsel-org-goto-history
               :action #'counsel-org-goto-action
@@ -3097,8 +3385,6 @@ otherwise continue prompting for tags."
   "Go to headline in candidate X."
   (org-goto-marker-or-bmk (cdr x)))
 
-(defvar org-version)
-
 (defun counsel--org-get-heading-args ()
   "Return list of arguments for `org-get-heading'.
 Try to return the right number of arguments for the current Org
@@ -3124,26 +3410,19 @@ attachment directory associated with the current 
buffer, all
 contained files are listed, so the return value could conceivably
 include attachments of other Org buffers."
   (require 'org-attach)
-  (let* ((ids (let (res)
-                (save-excursion
-                  (goto-char (point-min))
-                  (while (re-search-forward "^:ID:[\t ]+\\(.*\\)$" nil t)
-                    (push (match-string-no-properties 1) res))
-                  (nreverse res))))
-         (files
-          (cl-remove-if-not
-           #'file-exists-p
-           (mapcar (lambda (id)
-                     (expand-file-name
-                      (concat (substring id 0 2) "/" (substring id 2))
-                      org-attach-directory))
-                   ids))))
+  (let (dirs)
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "^:\\(ATTACH_DIR\\|ID\\):[\t ]+\\(.*\\)$" nil 
t)
+        (let ((dir (org-attach-dir)))
+          (when dir
+            (push dir dirs)))))
     (cl-mapcan
      (lambda (dir)
        (mapcar (lambda (file)
                  (file-relative-name (expand-file-name file dir)))
                (org-attach-file-list dir)))
-     files)))
+     (nreverse dirs))))
 
 ;;;###autoload
 (defun counsel-org-file ()
@@ -3344,11 +3623,49 @@ This variable has no effect unless
 
 ;;* Misc. Emacs
 ;;** `counsel-mark-ring'
+(defface counsel--mark-ring-highlight
+  '((t (:inherit highlight)))
+  "Face for current `counsel-mark-ring' line."
+  :group 'ivy-faces)
+
+(defvar counsel--mark-ring-overray nil
+  "Intarnal overray to highlight line by candidate of `counsel-mark-ring'.")
+
+(defun counsel--mark-ring-add-highlight ()
+  "Add highlight to current line."
+  (setq counsel--mark-ring-overray
+        (make-overlay (line-beginning-position) (1+ (line-end-position))))
+  (with-ivy-window
+    (overlay-put counsel--mark-ring-overray 'face
+                 'counsel--mark-ring-highlight)))
+
+(defun counsel--mark-ring-delete-highlight ()
+  "If `counsel-mark-ring' have highlight, delete highlight."
+  (if counsel--mark-ring-overray (delete-overlay counsel--mark-ring-overray)))
+
+(defvar counsel--mark-ring-calling-point 0
+  "Internal variable to remember calling position.")
+
+(defun counsel--mark-ring-unwind ()
+  "Return back to calling position of `counsel-mark-ring'."
+  (goto-char counsel--mark-ring-calling-point)
+  (counsel--mark-ring-delete-highlight))
+
+(defun counsel--mark-ring-update-fn ()
+  "Show preview by candidate."
+  (let ((linenum (string-to-number (ivy-state-current ivy-last))))
+    (counsel--mark-ring-delete-highlight)
+    (unless (= linenum 0)
+      (with-ivy-window
+        (forward-line (- linenum (line-number-at-pos)))))))
+
+;;;###autoload
 (defun counsel-mark-ring ()
   "Browse `mark-ring' interactively.
 Obeys `widen-automatically', which see."
   (interactive)
-  (let ((cands
+  (let ((counsel--mark-ring-calling-point (point))
+        (cands
          (save-excursion
            (save-restriction
              ;; Widen, both to save `line-number-at-pos' the trouble
@@ -3368,6 +3685,7 @@ Obeys `widen-automatically', which see."
     (if cands
         (ivy-read "Mark: " cands
                   :require-match t
+                  :update-fn #'counsel--mark-ring-update-fn
                   :action (lambda (cand)
                             (let ((pos (cdr-safe cand)))
                               (when pos
@@ -3377,6 +3695,7 @@ Obeys `widen-automatically', which see."
                                     (error "\
 Position of selected mark outside accessible part of buffer")))
                                 (goto-char pos))))
+                  :unwind #'counsel--mark-ring-unwind
                   :caller 'counsel-mark-ring)
       (message "Mark ring is empty"))))
 
@@ -3388,6 +3707,9 @@ Position of selected mark outside accessible part of 
buffer")))
 (declare-function package-delete "package")
 (declare-function package-desc-extras "package")
 
+(defvar counsel-package-history nil
+  "History for `counsel-package'.")
+
 (defun counsel--package-candidates ()
   "Return completion alist for `counsel-package'."
   (unless package--initialized
@@ -3402,6 +3724,7 @@ Position of selected mark outside accessible part of 
buffer")))
                 package-archive-contents)
         #'counsel--package-sort))
 
+;;;###autoload
 (defun counsel-package ()
   "Install or delete packages.
 
@@ -3420,9 +3743,10 @@ Additional actions:\\<ivy-minibuffer-map>
             (counsel--package-candidates)
             :action #'counsel-package-action
             :require-match t
+            :history 'counsel-package-history
             :caller 'counsel-package))
 
-(cl-pushnew '(counsel-package . "^+ ") ivy-initial-inputs-alist :key #'car)
+(cl-pushnew '(counsel-package . "^+") ivy-initial-inputs-alist :key #'car)
 
 (defun counsel-package-action (package)
   "Delete or install PACKAGE."
@@ -3530,14 +3854,8 @@ Additional actions:\\<ivy-minibuffer-map>
           (const :tag "Dashes" "\n----\n")
           string))
 
-(make-obsolete-variable
- 'counsel-yank-pop-height
- 'ivy-height-alist
- "<2018-04-14 Fri>") ;; TODO: Add version tag
-
-(defcustom counsel-yank-pop-height 5
-  "The `ivy-height' of `counsel-yank-pop'."
-  :type 'integer)
+(define-obsolete-variable-alias 'counsel-yank-pop-height
+    'ivy-height-alist "0.11.0")
 
 (defun counsel--yank-pop-format-function (cand-pairs)
   "Transform CAND-PAIRS into a string for `counsel-yank-pop'."
@@ -3610,9 +3928,12 @@ buffer position."
     (barf-if-buffer-read-only)
     (setq last-command 'yank)
     (setq yank-window-start (window-start))
-    ;; Avoid unexpected additions to `kill-ring'
-    (let (interprogram-paste-function)
-      (yank-pop (counsel--yank-pop-position s)))
+    (condition-case nil
+        ;; Avoid unexpected additions to `kill-ring'
+        (let (interprogram-paste-function)
+          (yank-pop (counsel--yank-pop-position s)))
+      (error
+       (insert s)))
     (when (funcall (if counsel-yank-pop-after-point #'> #'<)
                    (point) (mark t))
       (exchange-point-and-mark t))))
@@ -3681,8 +4002,7 @@ Note: Duplicate elements of `kill-ring' are always 
deleted."
                                          (t 1))
                                    t)))
         (counsel-yank-pop-after-point
-         (xor (consp arg) counsel-yank-pop-after-point))
-        (ivy-format-function #'counsel--yank-pop-format-function))
+         (xor (consp arg) counsel-yank-pop-after-point)))
     (unless (eq last-command 'yank)
       (push-mark))
     (ivy-read "kill-ring: " kills
@@ -3690,7 +4010,7 @@ Note: Duplicate elements of `kill-ring' are always 
deleted."
               :preselect preselect
               :action #'counsel-yank-pop-action
               :caller 'counsel-yank-pop)))
-
+(add-to-list 'ivy-format-functions-alist '(counsel-yank-pop . 
counsel--yank-pop-format-function))
 (add-to-list 'ivy-height-alist '(counsel-yank-pop . 5))
 
 (ivy-set-actions
@@ -3698,29 +4018,76 @@ Note: Duplicate elements of `kill-ring' are always 
deleted."
  '(("d" counsel-yank-pop-action-remove "delete")
    ("r" counsel-yank-pop-action-rotate "rotate")))
 
-;;** `counsel-evil-registers'
-(make-obsolete-variable
- 'counsel-evil-registers-height
- 'ivy-height-alist
- "<2018-04-14 Fri>") ;; TODO: Add version tag
+;;** `counsel-register'
+(defvar counsel-register-actions
+  '(("\\`buffer position" . jump-to-register)
+    ("\\`text" . insert-register)
+    ("\\`rectangle" . insert-register)
+    ("\\`window configuration" . jump-to-register)
+    ("\\`frame configuration" . jump-to-register)
+    ("\\`[-+]?[0-9]+\\(?:\\.[0-9]\\)?\\'" . insert-register)
+    ("\\`the file" . jump-to-register)
+    ("\\`keyboard macro" . jump-to-register)
+    ("\\`file-query" . jump-to-register))
+  "Alist of (REGEXP . FUNCTION) pairs for `counsel-register'.
+Selecting a register whose description matches REGEXP specifies
+FUNCTION as the action to take on the register.")
+
+(defvar counsel-register-history nil
+  "History for `counsel-register'.")
+
+(defun counsel-register-action (register)
+  "Default action for `counsel-register'.
+
+Call a function on REGISTER.  The function is determined by
+matching the register's value description against a regexp in
+`counsel-register-actions'."
+  (let* ((val (get-text-property 0 'register register))
+         (desc (register-describe-oneline val))
+         (action (cdr (cl-assoc-if (lambda (re) (string-match-p re desc))
+                                   counsel-register-actions))))
+    (if action
+        (funcall action val)
+      (error "No action was found for register %s"
+             (single-key-description val)))))
 
+;;;###autoload
+(defun counsel-register ()
+  "Interactively choose a register."
+  (interactive)
+  (ivy-read "Register: "
+            (cl-mapcan
+             (lambda (reg)
+               (let ((s (funcall register-preview-function reg)))
+                 (setq s (substring s 0 (string-match-p "[ \t\n\r]+\\'" s)))
+                 (unless (string= s "")
+                   (put-text-property 0 1 'register (car reg) s)
+                   (list s))))
+             register-alist)
+            :require-match t
+            :sort t
+            :history 'counsel-register-history
+            :action #'counsel-register-action
+            :caller 'counsel-register))
+
+;;** `counsel-evil-registers'
 (defcustom counsel-evil-registers-height 5
   "The `ivy-height' of `counsel-evil-registers'."
   :type 'integer)
 
+;;;###autoload
 (defun counsel-evil-registers ()
   "Ivy replacement for `evil-show-registers'."
   (interactive)
   (if (fboundp 'evil-register-list)
-      (let ((ivy-format-function #'counsel--yank-pop-format-function))
-        (ivy-read "evil-registers: "
-                  (cl-loop for (key . val) in (evil-register-list)
-                     collect (format "[%c]: %s" key (if (stringp val) val "")))
-                  :require-match t
-                  :action #'counsel-evil-registers-action
-                  :caller 'counsel-evil-registers))
+      (ivy-read "evil-registers: "
+                (cl-loop for (key . val) in (evil-register-list)
+                   collect (format "[%c]: %s" key (if (stringp val) val "")))
+                :require-match t
+                :action #'counsel-evil-registers-action
+                :caller 'counsel-evil-registers)
     (user-error "Required feature `evil' not installed.")))
-
+(add-to-list 'ivy-format-functions-alist '(counsel-evil-registers . 
counsel--yank-pop-format-function))
 (add-to-list 'ivy-height-alist '(counsel-evil-registers . 5))
 
 (defun counsel-evil-registers-action (s)
@@ -3861,49 +4228,24 @@ An extra action allows to switch to the process buffer."
 
 ;;** `counsel-minibuffer-history'
 ;;;###autoload
-(defun counsel-expression-history ()
-  "Select an element of `read-expression-history'.
-And insert it into the minibuffer.  Useful during `eval-expression'."
-  (declare (obsolete counsel-minibuffer-history "0.10.0 <2017-11-13 Mon>"))
-  (interactive)
-  (let ((enable-recursive-minibuffers t))
-    (ivy-read "Expression: "
-              (delete-dups (copy-sequence read-expression-history))
-              :action #'insert
-              :caller 'counsel-expression-history)))
-
-;;;###autoload
-(defun counsel-shell-command-history ()
-  "Browse shell command history."
-  (declare (obsolete counsel-minibuffer-history "0.10.0 <2017-11-13 Mon>"))
-  (interactive)
-  (ivy-read "Command: " shell-command-history
-            :action #'insert
-            :caller 'counsel-shell-command-history))
-
-;;;###autoload
 (defun counsel-minibuffer-history ()
   "Browse minibuffer history."
   (interactive)
   (let ((enable-recursive-minibuffers t))
-    (ivy-read "History: "
-              (delete-dups (copy-sequence
-                            (symbol-value minibuffer-history-variable)))
+    (ivy-read "History: " (ivy-history-contents minibuffer-history-variable)
+              :keymap ivy-reverse-i-search-map
               :action #'insert
               :caller 'counsel-minibuffer-history)))
 
 ;;** `counsel-esh-history'
-(defun counsel--browse-history (elements)
-  "Use Ivy to navigate through ELEMENTS."
+(defun counsel--browse-history (ring)
+  "Use Ivy to navigate through RING."
   (setq ivy-completion-beg (point))
   (setq ivy-completion-end (point))
-  (let ((cands
-         (delete-dups
-          (when (> (ring-size elements) 0)
-            (ring-elements elements)))))
-    (ivy-read "Symbol name: " cands
-              :action #'ivy-completion-in-region-action
-              :caller 'counsel-shell-history)))
+  (ivy-read "History: " (ivy-history-contents ring)
+            :keymap ivy-reverse-i-search-map
+            :action #'ivy-completion-in-region-action
+            :caller 'counsel-shell-history))
 
 (defvar eshell-history-ring)
 
@@ -3927,6 +4269,7 @@ And insert it into the minibuffer.  Useful during 
`eval-expression'."
 (defvar hydra-curr-body-fn)
 (declare-function hydra-keyboard-quit "ext:hydra")
 
+;;;###autoload
 (defun counsel-hydra-heads ()
   "Call a head of the current/last hydra."
   (interactive)
@@ -4001,6 +4344,7 @@ TREEP is used to expand internal nodes."
           (semantic-tag-get-attribute tag :members)))))
    (semantic-fetch-tags)))
 
+;;;###autoload
 (defun counsel-semantic ()
   "Jump to a semantic tag in the current buffer."
   (interactive)
@@ -4015,6 +4359,7 @@ TREEP is used to expand internal nodes."
               :history 'counsel-semantic-history
               :caller 'counsel-semantic)))
 
+;;;###autoload
 (defun counsel-semantic-or-imenu ()
   (interactive)
   (require 'semantic/fw)
@@ -4078,73 +4423,6 @@ This variable has no effect unless 
`counsel-outline-face-style'
 is set to `custom'."
   :type '(repeat face))
 
-(defvar counsel-outline-settings
-  '((emacs-lisp-mode
-     :outline-regexp ";;[;*]+[\s\t]+"
-     :outline-level counsel-outline-level-emacs-lisp)
-    (org-mode
-     :outline-title counsel-outline-title-org
-     :action counsel-org-goto-action
-     :history counsel-org-goto-history
-     :caller counsel-org-goto)
-    (markdown-mode                      ; markdown-mode package
-     :outline-title counsel-outline-title-markdown)
-    (latex-mode                         ; Built-in mode or AUCTeX package
-     :outline-title counsel-outline-title-latex))
-  "Alist mapping major modes to their `counsel-outline' settings.
-
-Each entry is a pair (MAJOR-MODE . PLIST).  `counsel-outline'
-checks whether an entry exists for the current buffer's
-MAJOR-MODE and, if so, loads the settings specified by PLIST
-instead of the default settings.  The following settings are
-recognized:
-
-- `:outline-regexp' is a regexp to match the beggining of an
-  outline heading.  It is only checked at the start of a line and
-  so need not start with \"^\".
-  Defaults to the value of the variable `outline-regexp'.
-
-- `:outline-level' is a function of no arguments which computes
-  the level of an outline heading.  It is called with point at
-  the beginning of `outline-regexp' and with the match data
-  corresponding to `outline-regexp'.
-  Defaults to the value of the variable `outline-level'.
-
-- `:outline-title' is a function of no arguments which returns
-  the title of an outline heading.  It is called with point at
-  the end of `outline-regexp' and with the match data
-  corresponding to `outline-regexp'.
-  Defaults to the function `counsel-outline-title'.
-
-- `:action' is a function of one argument, the selected outline
-  heading to jump to.  This setting corresponds directly to its
-  eponymous `ivy-read' keyword, as used by `counsel-outline', so
-  the type of the function's argument depends on the value
-  returned by `counsel-outline-candidates'.
-  Defaults to the function `counsel-outline-action'.
-
-- `:history' is a history list, usually a symbol representing a
-  history list variable.  It corresponds directly to its
-  eponymous `ivy-read' keyword, as used by `counsel-outline'.
-  Defaults to the symbol `counsel-outline-history'.
-
-- `:caller' is a symbol to uniquely idendify the caller to
-  `ivy-read'.  It corresponds directly to its eponymous
-  `ivy-read' keyword, as used by `counsel-outline'.
-  Defaults to the symbol `counsel-outline'.
-
-- `:display-style' overrides the variable
-  `counsel-outline-display-style'.
-
-- `:path-separator' overrides the variable
-  `counsel-outline-path-separator'.
-
-- `:face-style' overrides the variable
-  `counsel-outline-face-style'.
-
-- `:custom-faces' overrides the variable
-  `counsel-outline-custom-faces'.")
-
 (defun counsel-outline-title ()
   "Return title of current outline heading.
 Intended as a value for the `:outline-title' setting in
@@ -4201,30 +4479,33 @@ setting in `counsel-outline-settings', which see."
 (defvar counsel-outline--preselect 0
   "Index of the presected candidate in `counsel-outline'.")
 
-(defun counsel-outline-candidates (&optional settings)
+(defun counsel-outline-candidates (&optional settings prefix)
   "Return an alist of outline heading completion candidates.
 Each element is a pair (HEADING . MARKER), where the string
 HEADING is located at the position of MARKER.  SETTINGS is a
-plist entry from `counsel-outline-settings', which see."
-  (let ((bol-regex (concat "^\\(?:"
-                           (or (plist-get settings :outline-regexp)
-                               outline-regexp)
-                           "\\)"))
-        (outline-title-fn (or (plist-get settings :outline-title)
-                              #'counsel-outline-title))
-        (outline-level-fn (or (plist-get settings :outline-level)
-                              outline-level))
-        (display-style (or (plist-get settings :display-style)
-                           counsel-outline-display-style))
-        (path-separator (or (plist-get settings :path-separator)
-                            counsel-outline-path-separator))
-        (face-style (or (plist-get settings :face-style)
-                        counsel-outline-face-style))
-        (custom-faces (or (plist-get settings :custom-faces)
-                          counsel-outline-custom-faces))
-        (stack-level 0)
-        (orig-point (point))
-        cands name level marker stack)
+plist entry from `counsel-outline-settings', which see.
+PREFIX is a string prepended to all candidates."
+  (let* ((bol-regex (concat "^\\(?:"
+                            (or (plist-get settings :outline-regexp)
+                                outline-regexp)
+                            "\\)"))
+         (outline-title-fn (or (plist-get settings :outline-title)
+                               #'counsel-outline-title))
+         (outline-level-fn (or (plist-get settings :outline-level)
+                               outline-level))
+         (display-style (or (plist-get settings :display-style)
+                            counsel-outline-display-style))
+         (path-separator (or (plist-get settings :path-separator)
+                             counsel-outline-path-separator))
+         (face-style (or (plist-get settings :face-style)
+                         counsel-outline-face-style))
+         (custom-faces (or (plist-get settings :custom-faces)
+                           counsel-outline-custom-faces))
+         (stack-level 0)
+         (orig-point (point))
+         (stack (and prefix (list (counsel-outline--add-face
+                                   prefix 0 face-style custom-faces))))
+         cands name level marker)
     (save-excursion
       (setq counsel-outline--preselect 0)
       (goto-char (point-min))
@@ -4426,19 +4707,26 @@ Candidates comprise `counsel--unicode-names', which 
see.")
   "Insert COUNT copies of a Unicode character at point.
 COUNT defaults to 1."
   (interactive "p")
-  (let ((ivy-sort-max-size (expt 256 6)))
-    (setq ivy-completion-beg (point))
-    (setq ivy-completion-end (point))
-    (ivy-read "Unicode name: " counsel--unicode-table
-              :history 'counsel-unicode-char-history
-              :sort t
-              :action (lambda (name)
-                        (with-ivy-window
-                          (delete-region ivy-completion-beg ivy-completion-end)
-                          (setq ivy-completion-beg (point))
-                          (insert-char (get-text-property 0 'code name) count)
-                          (setq ivy-completion-end (point))))
-              :caller 'counsel-unicode-char)))
+  (setq ivy-completion-beg (point))
+  (setq ivy-completion-end (point))
+  (ivy-read "Unicode name: " counsel--unicode-table
+            :history 'counsel-unicode-char-history
+            :sort t
+            :action (lambda (name)
+                      (with-ivy-window
+                        (delete-region ivy-completion-beg ivy-completion-end)
+                        (setq ivy-completion-beg (point))
+                        (insert-char (get-text-property 0 'code name) count)
+                        (setq ivy-completion-end (point))))
+            :caller 'counsel-unicode-char))
+
+(defun counsel-unicode-copy (name)
+  "Ivy action to copy the unicode from NAME to the kill ring."
+  (kill-new (char-to-string (get-text-property 0 'code name))))
+
+(ivy-set-actions
+ 'counsel-unicode-char
+ '(("w" counsel-unicode-copy "copy")))
 
 ;;** `counsel-colors'
 (defun counsel-colors-action-insert-hex (color)
@@ -4463,12 +4751,41 @@ Return nil if NAME does not designate a valid color."
 
 (defvar shr-color-visible-luminance-min)
 (declare-function shr-color-visible "shr-color")
+(defvar counsel--colors-format "%-20s %s %s%s")
 
-(defun counsel-colors--formatter (formatter)
-  "Turn FORMATTER into format function for `counsel-colors-*'.
-Return closure suitable for `ivy-format-function'."
+(defun counsel--colors-emacs-format-function (colors)
+  "Format function for `counsel-colors-emacs'."
   (require 'shr-color)
-  (lambda (colors)
+  (let* ((blank (make-string 10 ?\s))
+         (formatter
+          (lambda (color)
+            (let ((fg (list :foreground color)))
+              (format counsel--colors-format color
+                      (propertize (get-text-property 0 'hex color) 'face fg)
+                      (propertize blank 'face (list :background color))
+                      (propertize (mapconcat (lambda (dup)
+                                               (concat " " dup))
+                                             (get-text-property 0 'dups color)
+                                             ",")
+                                  'face fg))))))
+    (ivy--format-function-generic
+     (lambda (color)
+       (let* ((hex (get-text-property 0 'hex color))
+              (shr-color-visible-luminance-min 100)
+              (fg (cadr (shr-color-visible hex "black" t))))
+         (propertize (funcall formatter color)
+                     'face (list :foreground fg :background hex))))
+     formatter colors "\n")))
+
+(defun counsel--colors-web-format-function (colors)
+  "Format function for `counsel-colors-web'."
+  (require 'shr-color)
+  (let* ((blank (make-string 10 ?\s))
+         (formatter (lambda (color)
+                      (let ((hex (get-text-property 0 'hex color)))
+                        (format counsel--colors-format color
+                                (propertize hex 'face (list :foreground hex))
+                                (propertize blank 'face (list :background 
hex)))))))
     (ivy--format-function-generic
      (lambda (color)
        (let* ((hex (get-text-property 0 'hex color))
@@ -4494,26 +4811,15 @@ selected color."
                               (when hex
                                 (propertize name 'hex hex 'dups dups))))
                           (list-colors-duplicates))))
-         (fmt (format "%%-%ds %%s %%s%%s"
-                      (apply #'max 0 (mapcar #'string-width colors))))
-         (blank (make-string 10 ?\s))
-         (ivy-format-function
-          (counsel-colors--formatter
-           (lambda (color)
-             (let ((fg (list :foreground color)))
-               (format fmt color
-                       (propertize (get-text-property 0 'hex color) 'face fg)
-                       (propertize blank 'face (list :background color))
-                       (propertize (mapconcat (lambda (dup)
-                                                (concat " " dup))
-                                              (get-text-property 0 'dups color)
-                                              ",")
-                                   'face fg)))))))
+         (counsel--colors-format
+          (format "%%-%ds %%s %%s%%s"
+                  (apply #'max 0 (mapcar #'string-width colors)))))
     (ivy-read "Emacs color: " colors
               :require-match t
               :history 'counsel-colors-emacs-history
               :action #'insert
               :caller 'counsel-colors-emacs)))
+(add-to-list 'ivy-format-functions-alist '(counsel-colors-emacs . 
counsel--colors-emacs-format-function))
 
 (ivy-set-actions
  'counsel-colors-emacs
@@ -4551,16 +4857,9 @@ You can insert or kill the name or hexadecimal RGB value 
of the
 selected color."
   (interactive)
   (let* ((colors (counsel-colors--web-alist))
-         (blank (make-string 10 ?\s))
-         (fmt (format "%%-%ds %%s %%s"
-                      (apply #'max 0 (mapcar #'string-width colors))))
-         (ivy-format-function
-          (counsel-colors--formatter
-           (lambda (color)
-             (let ((hex (get-text-property 0 'hex color)))
-               (format fmt color
-                       (propertize hex 'face (list :foreground hex))
-                       (propertize blank 'face (list :background hex))))))))
+         (counsel--colors-format
+          (format "%%-%ds %%s %%s"
+                  (apply #'max 0 (mapcar #'string-width colors)))))
     (ivy-read "Web color: " colors
               :require-match t
               :history 'counsel-colors-web-history
@@ -4568,6 +4867,7 @@ selected color."
               :action #'insert
               :caller 'counsel-colors-web)))
 
+(add-to-list 'ivy-format-functions-alist '(counsel-colors-web . 
counsel--colors-web-format-function))
 (ivy-set-actions
  'counsel-colors-web
  '(("h" counsel-colors-action-insert-hex "insert hexadecimal value")
@@ -4616,11 +4916,11 @@ selected color."
 
 (defun counsel-rhythmbox-toggle-shuffle (_song)
   "Toggle Rhythmbox shuffle setting."
-  (let* ((old-order (counsel--call "dconf" "read" 
"/org/gnome/rhythmbox/player/play-order"))
+  (let* ((old-order (counsel--command "dconf" "read" 
"/org/gnome/rhythmbox/player/play-order"))
          (new-order (if (string= old-order "'shuffle'")
                         "'linear'"
                       "'shuffle'")))
-    (counsel--call
+    (counsel--command
      "dconf"
      "write"
      "/org/gnome/rhythmbox/player/play-order"
@@ -4674,6 +4974,7 @@ selected color."
                        :session service path interface "ListChildren"
                        0 nb-songs '("*")))))))
   (ivy-read "Rhythmbox: " counsel-rhythmbox-songs
+            :require-match t
             :history 'counsel-rhythmbox-history
             :preselect (counsel-rhythmbox-current-song)
             :action
@@ -4975,6 +5276,7 @@ When ARG is non-nil, ignore NoDisplay property in 
*.desktop files."
       (unless (member title counsel-wmctrl-ignore)
         (cons title id)))))
 
+;;;###autoload
 (defun counsel-wmctrl ()
   "Select a desktop window using wmctrl."
   (interactive)
@@ -4984,6 +5286,473 @@ When ARG is non-nil, ignore NoDisplay property in 
*.desktop files."
               :action #'counsel-wmctrl-action
               :caller 'counsel-wmctrl)))
 
+(defvar counsel--switch-buffer-temporary-buffers nil
+  "Internal.")
+
+(defvar counsel--switch-buffer-previous-buffers nil
+  "Internal.")
+
+(defun counsel--switch-buffer-unwind ()
+  "Clear temporary file buffers and restore `buffer-list'.
+The buffers are those opened during a session of `counsel-switch-buffer'."
+  (mapc #'kill-buffer counsel--switch-buffer-temporary-buffers)
+  (mapc #'bury-buffer (cl-remove-if-not
+                       #'buffer-live-p
+                       counsel--switch-buffer-previous-buffers))
+  (setq counsel--switch-buffer-temporary-buffers nil
+        counsel--switch-buffer-previous-buffers nil))
+
+(defun counsel--switch-buffer-update-fn ()
+  (unless counsel--switch-buffer-previous-buffers
+    (setq counsel--switch-buffer-previous-buffers (buffer-list)))
+  (let* ((current (ivy-state-current ivy-last))
+         (virtual (assoc current ivy--virtual-buffers)))
+    (cond
+      ((get-buffer current)
+       (ivy-call))
+      ((and virtual (file-exists-p (cdr virtual)))
+       (let ((buf (ignore-errors
+                    ;; may not open due to `large-file-warning-threshold' etc.
+                    (find-file-noselect (cdr virtual)))))
+         (if buf
+             (progn
+               (push buf counsel--switch-buffer-temporary-buffers)
+               (ivy-call))
+           ;; clean up the minibuffer so that there's no delay before
+           ;; the Ivy candidates are displayed once again
+           (message ""))))
+      (t
+       (with-ivy-window
+         (switch-to-buffer (ivy-state-buffer ivy-last)))))))
+
+;;;###autoload
+(defun counsel-switch-buffer ()
+  "Switch to another buffer.
+Display a preview of the selected ivy completion candidate buffer
+in the current window."
+  (interactive)
+  (ivy-read "Switch to buffer: " 'internal-complete-buffer
+            :preselect (buffer-name (other-buffer (current-buffer)))
+            :keymap ivy-switch-buffer-map
+            :action #'ivy--switch-buffer-action
+            :matcher #'ivy--switch-buffer-matcher
+            :caller 'counsel-switch-buffer
+            :unwind #'counsel--switch-buffer-unwind
+            :update-fn 'counsel--switch-buffer-update-fn))
+
+;;;###autoload
+(defun counsel-switch-buffer-other-window ()
+  "Switch to another buffer in another window.
+Display a preview of the selected ivy completion candidate buffer
+in the current window."
+  (interactive)
+  (ivy-read "Switch to buffer in other window: " 'internal-complete-buffer
+            :preselect (buffer-name (other-buffer (current-buffer)))
+            :action #'ivy--switch-buffer-other-window-action
+            :matcher #'ivy--switch-buffer-matcher
+            :caller 'counsel-switch-buffer-other-window
+            :unwind #'counsel--switch-buffer-unwind
+            :update-fn 'counsel--switch-buffer-update-fn))
+
+(defun counsel-open-buffer-file-externally (buffer)
+  "Open the file associated with BUFFER with an external program."
+  (when (zerop (length buffer))
+    (user-error "Can't open that"))
+  (let* ((virtual (assoc buffer ivy--virtual-buffers))
+         (filename (if virtual
+                       (cdr virtual)
+                     (buffer-file-name (get-buffer buffer)))))
+    (unless filename
+      (user-error "Can't open `%s' externally" buffer))
+    (counsel-locate-action-extern (expand-file-name filename))))
+
+(ivy-add-actions
+ 'ivy-switch-buffer
+ '(("x" counsel-open-buffer-file-externally "open externally")))
+
+;;** `counsel-compile'
+(defvar counsel-compile-history nil
+  "History for `counsel-compile'.
+
+This is a list of strings with additional properties which allow
+the history to be filtered depending on the context of the call.
+The properties include:
+
+`srcdir'
+    the root directory of the source code
+`blddir'
+    the root directory of the build (in or outside the `srcdir')
+`bldenv'
+    the build environment as passed to `compilation-environment'
+`recursive'
+    the completion should be run again in `blddir' of this result
+`cmd'
+    if set, pass only the substring with this property to `compile'
+
+This variable is suitable for addition to
+`savehist-additional-variables'.")
+
+(defvar counsel-compile-root-functions
+  '(counsel--project-current
+    counsel--configure-root
+    counsel--git-root
+    counsel--dir-locals-root)
+  "Special hook to find the project root for compile commands.
+Each function on this hook is called in turn with no arguments
+and should return either a directory, or nil if no root was
+found.")
+
+(defun counsel--compile-root ()
+  "Return root of current project or signal an error on failure.
+The root is determined by `counsel-compile-root-functions'."
+  (or (run-hook-with-args-until-success 'counsel-compile-root-functions)
+      (error "Couldn't find project root")))
+
+(defun counsel--project-current ()
+  "Return root of current project or nil on failure.
+Use `project-current' to determine the root."
+  (and (fboundp 'project-current)
+       (cdr (project-current))))
+
+(defun counsel--configure-root ()
+  "Return root of current project or nil on failure.
+Use the presence of a \"configure\" file to determine the root."
+  (counsel--dominating-file "configure"))
+
+(defun counsel--git-root ()
+  "Return root of current project or nil on failure.
+Use the presence of a \".git\" file to determine the root."
+  (counsel--dominating-file ".git"))
+
+(defun counsel--dir-locals-root ()
+  "Return root of current project or nil on failure.
+Use the presence of a `dir-locals-file' to determine the root."
+  (counsel--dominating-file dir-locals-file))
+
+(defvar counsel-compile-local-builds
+  '(counsel-compile-get-filtered-history
+    counsel-compile-get-build-directories
+    counsel-compile-get-make-invocation)
+  "Additional compile invocations to feed into `counsel-compile'.
+
+This can either be a list of compile invocation strings or
+functions that will provide such a list.  You should customise
+this if you want to provide specific non-standard build types to
+`counsel-compile'.  The default helpers are set up to handle
+common build environments.")
+
+(defcustom counsel-compile-make-args "-k"
+  "Additional arguments for make.
+You may, for example, want to add \"-jN\" for the number of cores
+N in your system."
+  :type 'string)
+
+(defcustom counsel-compile-env nil
+  "List of environment variables for compilation to inherit.
+Each element should be a string of the form ENVVARNAME=VALUE.  This
+list is passed to `compilation-environment'."
+  :type '(repeat (string :tag "ENVVARNAME=VALUE")))
+
+(defvar counsel-compile-env-history nil
+  "History for `counsel-compile-env'.")
+
+(defvar counsel-compile-env-pattern
+  "[_[:digit:][:upper:]]+=[/[:album:]]*"
+  "Pattern to match valid environment variables.")
+
+(defcustom counsel-compile-make-pattern "\\`\\(?:GNUm\\|[Mm]\\)akefile\\'"
+  "Regexp for matching the names of Makefiles."
+  :type 'regexp)
+
+(defcustom counsel-compile-build-directories
+  '("build" "builds" "bld" ".build")
+  "List of potential build subdirectory names to check for."
+  :type '(repeat directory))
+
+(defvar counsel-compile-phony-pattern "^\\.PHONY:[\t ]+\\(.+\\)$"
+  "Regexp for extracting phony targets from Makefiles.")
+
+;; This is loosely based on the Bash Make completion code
+(defun counsel-compile--probe-make-targets (dir)
+  "Return a list of Make targets for DIR.
+
+Return an empty list is Make exits with an error.  This might
+happen because some sort of configuration needs to be done first
+or the source tree is pristine and being used for multiple build
+trees."
+  (let ((default-directory dir)
+        (targets nil))
+    (with-temp-buffer
+      ;; 0 = no-rebuild, -q & 1 needs rebuild, 2 error (for GNUMake at
+      ;; least)
+      (when (< (call-process "make" nil t nil "-nqp") 2)
+        (goto-char (point-min))
+        (while (re-search-forward counsel-compile-phony-pattern nil t)
+          (setq targets
+                (nconc targets (split-string
+                                (match-string-no-properties 1)))))))
+    (sort targets #'string-lessp)))
+
+(defun counsel-compile--pretty-propertize (leader text face)
+  "Return a pretty string of the form \" LEADER TEXT\".
+LEADER is propertized with a warning face and the remaining
+text with FACE."
+  (concat (propertize (concat " " leader " ")
+                      'face
+                      'font-lock-warning-face)
+          (propertize text 'face face)))
+
+(defun counsel--compile-get-make-targets (srcdir &optional blddir)
+  "Return a list of Make targets for a given SRCDIR/BLDDIR combination.
+
+We search the Makefile for a list of phony targets which are
+generally the top level targets a Make system provides.
+The resulting strings are tagged with properties that
+`counsel-compile-history' can use for filtering results."
+  (let ((fmt (format (propertize "make %s %%s" 'cmd t)
+                     counsel-compile-make-args))
+        (suffix (and blddir
+                     (counsel-compile--pretty-propertize "in" blddir
+                                                         'dired-directory)))
+        (build-env (and counsel-compile-env
+                        (counsel-compile--pretty-propertize
+                         "with"
+                         (mapconcat #'identity counsel-compile-env " ")
+                         'font-lock-variable-name-face)))
+        (props `(srcdir ,srcdir blddir ,blddir bldenv ,counsel-compile-env)))
+    (mapcar (lambda (target)
+              (setq target (concat (format fmt target) suffix build-env))
+              (add-text-properties 0 (length target) props target)
+              target)
+            (counsel-compile--probe-make-targets (or blddir srcdir)))))
+
+(defun counsel-compile-get-make-invocation (&optional blddir)
+  "Have a look in the root directory for any build control files.
+
+The optional BLDDIR is useful for other helpers that have found
+subdirectories that builds may be invoked in."
+  (let ((srcdir (counsel--compile-root)))
+    (when (directory-files (or blddir srcdir) nil
+                           counsel-compile-make-pattern t)
+      (counsel--compile-get-make-targets srcdir blddir))))
+
+(defun counsel--find-build-subdir (srcdir)
+  "Return builds subdirectory of SRCDIR, if one exists."
+  (cl-some (lambda (dir)
+             (setq dir (expand-file-name dir srcdir))
+             (and (file-directory-p dir) dir))
+           counsel-compile-build-directories))
+
+(defun counsel--get-build-subdirs (blddir)
+  "Return all subdirs under BLDDIR sorted by modification time.
+If there are non-directory files in BLDDIR, include BLDDIR in the
+list as it may also be a build directory."
+  (let* ((files (directory-files-and-attributes
+                 blddir t directory-files-no-dot-files-regexp t))
+         (dirs (cl-remove-if-not #'cl-second files)))
+    ;; Any non-dir files?
+    (when (< (length dirs)
+             (length files))
+      (push (cons blddir (file-attributes blddir)) dirs))
+    (mapcar #'car (sort dirs (lambda (x y)
+                               (time-less-p (nth 6 y) (nth 6 x)))))))
+
+(defun counsel-compile-get-build-directories (&optional dir)
+  "Return a list of potential build directories."
+  (let* ((srcdir (or dir (counsel--compile-root)))
+         (blddir (counsel--find-build-subdir srcdir))
+         (props `(srcdir ,srcdir recursive t))
+         (fmt (concat (propertize "Select build in "
+                                  'face 'font-lock-warning-face)
+                      (propertize "%s" 'face 'dired-directory))))
+    (mapcar (lambda (subdir)
+              (let ((s (format fmt subdir)))
+                (add-text-properties 0 (length s) `(blddir ,subdir ,@props) s)
+                s))
+            (and blddir (counsel--get-build-subdirs blddir)))))
+
+;; This is a workaround for the fact there is no concept of "project"
+;; local variables (as opposed to for example buffer-local).  So we
+;; store all our history in a global list filter out the results we
+;; don't want.
+(defun counsel-compile-get-filtered-history (&optional dir)
+  "Return a compile history relevant to current project."
+  (let ((root (or dir (counsel--compile-root)))
+        history)
+    (dolist (item counsel-compile-history)
+      (let ((srcdir (get-text-property 0 'srcdir item))
+            (blddir (get-text-property 0 'blddir item)))
+        (when (or (and srcdir (file-in-directory-p srcdir root))
+                  (and blddir (file-in-directory-p blddir root)))
+          (push item history))))
+    (nreverse history)))
+
+(defun counsel--get-compile-candidates (&optional dir)
+  "Return the list of compile commands.
+This is determined by `counsel-compile-local-builds', which see."
+  (let (cands)
+    (dolist (cmds counsel-compile-local-builds)
+      (when (functionp cmds)
+        (setq cmds (funcall cmds dir)))
+      (when cmds
+        (push (if (listp cmds) cmds (list cmds)) cands)))
+    (apply #'append (nreverse cands))))
+
+;; This is a workaround to ensure we tag all the relevant metadata in
+;; our compile history.  This also allows M-x compile to do fancy
+;; things like infer `default-directory' from 'cd's in the string.
+(defun counsel-compile--update-history (_proc)
+  "Update `counsel-compile-history' from the compilation state."
+  (let* ((srcdir (counsel--compile-root))
+         (blddir default-directory)
+         (bldenv compilation-environment)
+         (cmd (concat
+               (propertize (car compilation-arguments) 'cmd t)
+               (unless (file-equal-p blddir srcdir)
+                 (counsel-compile--pretty-propertize "in" blddir
+                                                     'dired-directory))
+               (when bldenv
+                 (counsel-compile--pretty-propertize "with"
+                                                     (mapconcat #'identity 
bldenv " ")
+                                                     
'font-lock-variable-name-face)))))
+    (add-text-properties 0 (length cmd)
+                         `(srcdir ,srcdir blddir ,blddir bldenv ,bldenv) cmd)
+    (add-to-history 'counsel-compile-history cmd)))
+
+(defvar counsel-compile--current-build-dir nil
+  "Tracks the last directory `counsel-compile' was called with.
+
+This state allows us to set it correctly if the user has manually
+edited the command, thus losing our embedded state.")
+
+(defun counsel-compile--action (cmd)
+  "Process CMD to call `compile'.
+
+If CMD has the `recursive' property set we call `counsel-compile'
+again to further refine the compile options in the directory
+specified by the `blddir' property."
+  (let ((blddir (get-text-property 0 'blddir cmd))
+        (bldenv (get-text-property 0 'bldenv cmd)))
+    (if (get-text-property 0 'recursive cmd)
+        (counsel-compile blddir)
+      (when (get-char-property 0 'cmd cmd)
+        (setq cmd (substring-no-properties
+                   cmd 0 (next-single-property-change 0 'cmd cmd))))
+      (let ((default-directory (or blddir
+                                   counsel-compile--current-build-dir
+                                   default-directory))
+            (compilation-environment bldenv))
+        ;; No need to specify `:history' because of this hook.
+        (add-hook 'compilation-start-hook #'counsel-compile--update-history)
+        (unwind-protect
+             (compile cmd)
+          (remove-hook 'compilation-start-hook 
#'counsel-compile--update-history))))))
+
+;;;###autoload
+(defun counsel-compile (&optional dir)
+  "Call `compile' completing with smart suggestions, optionally for DIR."
+  (interactive)
+  (setq counsel-compile--current-build-dir (or dir default-directory))
+  (ivy-read "Compile command: "
+            (counsel--get-compile-candidates dir)
+            :action #'counsel-compile--action
+            :caller 'counsel-compile))
+
+
+(defun counsel-compile-env--format-hint (cands)
+  "Return a formatter for compile-env CANDS."
+  (let ((rmstr
+         (propertize "remove" 'face 'font-lock-warning-face))
+        (addstr
+         (propertize "add" 'face 'font-lock-variable-name-face)))
+    (ivy--format-function-generic
+     (lambda (selected)
+       (format "%s %s"
+               (if (member selected counsel-compile-env) rmstr addstr)
+               selected))
+     #'identity
+     cands
+     "\n")))
+
+(defun counsel-compile-env--update (var)
+  "Update `counsel-compile-env' either adding or removing VAR."
+  (cond ((member var counsel-compile-env)
+         (setq counsel-compile-env (delete var counsel-compile-env)))
+        ((string-match-p counsel-compile-env-pattern var)
+         (push var counsel-compile-env))
+        (t (user-error "Ignoring malformed variable: '%s'" var))))
+
+;;;###autoload
+(defun counsel-compile-env ()
+  "Update `counsel-compile-env' interactively."
+  (interactive)
+  (ivy-read "Compile environment variable: "
+            (delete-dups (append
+                          counsel-compile-env counsel-compile-env-history))
+            :action #'counsel-compile-env--update
+            :predicate (lambda (cand)
+                         (string-match-p counsel-compile-env-pattern
+                                         cand))
+            :history 'counsel-compile-env-history
+            :caller 'counsel-compile-env))
+(add-to-list 'ivy-format-functions-alist '(counsel-compile-env . 
counsel-compile-env--format-hint))
+
+;;** `counsel-minor'
+(defvar counsel-minor-history nil
+  "History for `counsel-minor'.")
+
+(defun counsel--minor-candidates ()
+  "Return completion alist for `counsel-minor'.
+
+The alist element is cons of minor mode string with its lighter
+and minor mode symbol."
+  (delq nil
+        (mapcar
+         (lambda (mode)
+           (when (and (boundp mode) (commandp mode))
+             (let ((lighter (alist-get mode minor-mode-alist)))
+               (cons (concat
+                      (if (symbol-value mode) "-" "+")
+                      (symbol-name mode)
+                      (propertize
+                       (if lighter
+                           (format " \"%s\""
+                                   (format-mode-line (cons t lighter)))
+                         "")
+                       'face font-lock-string-face))
+                     mode))))
+         minor-mode-list)))
+
+;;;###autoload
+(defun counsel-minor ()
+  "Enable or disable minor mode.
+
+Disabled minor modes are prefixed with \"+\", and
+selecting one of these will enable it.
+Enabled minor modes are prefixed with \"-\", and
+selecting one of these will enable it.
+
+Additional actions:\\<ivy-minibuffer-map>
+
+  \\[ivy-dispatching-done] d: Go to minor mode definition
+  \\[ivy-dispatching-done] h: Describe minor mode"
+
+  (interactive)
+  (ivy-read "Minor modes (enable +mode or disable -mode): "
+            (counsel--minor-candidates)
+            :require-match t
+            :history 'counsel-minor-history
+            :sort t
+            :action (lambda (x)
+                      (call-interactively (cdr x)))))
+
+(cl-pushnew '(counsel-minor . "^+") ivy-initial-inputs-alist :key #'car)
+
+(ivy-set-actions
+ 'counsel-minor
+ `(("d" ,(lambda (x) (find-function (cdr x))) "definition")
+   ("h" ,(lambda (x) (describe-function (cdr x))) "help")))
+
 ;;* `counsel-mode'
 (defvar counsel-mode-map
   (let ((map (make-sparse-keymap)))
diff --git a/packages/ivy/dir b/packages/ivy/dir
new file mode 100644
index 0000000..0d5ee45
--- /dev/null
+++ b/packages/ivy/dir
@@ -0,0 +1,18 @@
+This is the file .../info/dir, which contains the
+topmost node of the Info hierarchy, called (dir)Top.
+The first time you invoke Info you start off looking at this node.
+
+File: dir,     Node: Top       This is the top of the INFO tree
+
+  This (the Directory node) gives a menu of major topics.
+  Typing "q" exits, "?" lists all Info commands, "d" returns here,
+  "h" gives a primer for first-timers,
+  "mEmacs<Return>" visits the Emacs manual, etc.
+
+  In Emacs, you can click mouse button 2 on a menu item or cross reference
+  to select it.
+
+* Menu:
+
+Emacs
+* Ivy: (ivy).           Using Ivy for completion.
diff --git a/packages/ivy/doc/Changelog.org b/packages/ivy/doc/Changelog.org
index 4a15581..8c26c2d 100644
--- a/packages/ivy/doc/Changelog.org
+++ b/packages/ivy/doc/Changelog.org
@@ -1,7 +1,7 @@
 #+TITLE: Ivy CHANGELOG
 #+OPTIONS: H:4 num:nil toc:3
 #+SETUPFILE: ~/git/org-html-themes/setup/theme-readtheorg.setup
-#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="kbd-style.css"/>
+#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="css/kbd-style.css"/>
 
 * 0.6.0
 :PROPERTIES:
@@ -2898,7 +2898,7 @@ See 
[[https://github.com/abo-abo/swiper/issues/845][#845]], [[https://github.com
 #+END_EXPORT
 * 0.10.0
 :PROPERTIES:
-:CUSTOM_ID: 0-10-0
+:CUSTOM_ID: 0.10.0
 :END:
 -----
 ** Fixes
@@ -3613,7 +3613,7 @@ See 
[[https://github.com/abo-abo/swiper/issues/929][#929]], [[https://github.com
 -----
 * 0.11.0
 :PROPERTIES:
-:CUSTOM_ID: 0-11-0
+:CUSTOM_ID: 0.11.0
 :END:
 -----
 ** Fixes
@@ -4501,3 +4501,695 @@ one or more buffers while still in the minibuffer.
 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
 <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
 #+END_EXPORT
+* 0.12.0
+:PROPERTIES:
+:CUSTOM_ID: 0.12.0
+:END:
+-----
+** Fixes
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fixes
+:END:
+-----
+*** counsel-ag
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-ag
+:END:
+Don't allow newlines in wildcards when using el:ivy--regex-fuzzy. See 
[[https://github.com/abo-abo/swiper/issues/1907][#1907]].
+-----
+*** counsel-company
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-company
+:END:
+Add caller. See [[https://github.com/abo-abo/swiper/issues/2051][#2051]].
+
+Use el:company-prefix. See 
[[https://github.com/abo-abo/swiper/issues/2054][#2054]], 
[[https://github.com/abo-abo/swiper/issues/2074][#2074]].
+
+Don't rely on el:company-point See 
[[https://github.com/abo-abo/swiper/issues/2071][#2071]].
+-----
+*** counsel-dired-jump
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-dired-jump
+:END:
+Fix "-type d". See [[https://github.com/abo-abo/swiper/issues/1965][#1965]].
+
+Fix for OSX. See [[https://github.com/abo-abo/swiper/issues/1990][#1990]].
+-----
+*** counsel-file-jump
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-file-jump
+:END:
+Fix file expansion. See 
[[https://github.com/abo-abo/swiper/issues/1903][#1903]].
+
+Fix dotfiles not being shown. See 
[[https://github.com/abo-abo/swiper/issues/1820][#1820]].
+-----
+*** counsel-find-file
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-find-file
+:END:
+Add nested hidden dotfiles to el:counsel-find-file-ignore-regexp. See 
[[https://github.com/abo-abo/swiper/issues/1820][#1820]].
+
+Add lockfiles to el:counsel-find-file-ignore-regexp. See 
[[https://github.com/abo-abo/swiper/issues/2117][#2117]].
+
+Improve mkdir action with el:ivy-call: cd into the created directory.
+
+Improve delete action with el:ivy-call: stay in the directory.
+
+Improve copy and move actions. See 
[[https://github.com/abo-abo/swiper/issues/2053][#2053]].
+-----
+*** counsel-git-checkout
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-git-checkout
+:END:
+Quote branch names. See 
[[https://github.com/abo-abo/swiper/issues/1905][#1905]], 
[[https://github.com/abo-abo/swiper/issues/1906][#1906]].
+-----
+*** counsel-git-log
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-git-log
+:END:
+Change el:counsel-git-log-split-string-re. See 
[[https://github.com/abo-abo/swiper/issues/2129][#2129]].
+
+Fix el:ivy-resume. See 
[[https://github.com/abo-abo/swiper/issues/2133][#2133]].
+-----
+*** counsel-locate
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-locate
+:END:
+Use a non-regex locate on BSD. See 
[[https://github.com/abo-abo/swiper/issues/1950][#1950]].
+-----
+*** counsel-org-file
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-org-file
+:END:
+Handle ATTACH_DIR property. Re-use el:org-attach-dir. See 
[[https://github.com/abo-abo/swiper/issues/2042][#2042]].
+-----
+*** counsel-org-goto-all
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-org-goto-all
+:END:
+Use org-mode outline settings. See 
[[https://github.com/abo-abo/swiper/issues/1947][#1947]].
+-----
+*** counsel-org-tag-agenda
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-org-tag-agenda
+:END:
+Fix due to Org 9.2.3 API change. See 
[[https://github.com/abo-abo/swiper/issues/1997][#1997]].
+
+Fix el:org-version testing. See 
[[https://github.com/abo-abo/swiper/issues/2006][#2006]].
+-----
+*** counsel-package
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-package
+:END:
+Strip space from the initial input. See 
[[https://github.com/abo-abo/swiper/issues/1998][#1998]].
+-----
+*** counsel-recentf
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-recentf
+:END:
+Require match. See [[https://github.com/abo-abo/swiper/issues/2043][#2043]].
+-----
+*** counsel-rhythmbox
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-rhythmbox
+:END:
+Add =:require-match=.
+-----
+*** counsel-unicode-char
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-counsel-unicode-char
+:END:
+Don't sort every time. See 
[[https://github.com/abo-abo/swiper/issues/1204][#1204]], 
[[https://github.com/abo-abo/swiper/issues/1988][#1988]].
+
+Modify copy action to use actual result. See 
[[https://github.com/abo-abo/swiper/issues/2075][#2075]].
+-----
+*** documentation
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-documentation
+:END:
+el:ivy-initial-inputs-alist is now a defcustom.
+
+el:swiper-mc docstring. See 
[[https://github.com/abo-abo/swiper/issues/1879][#1879]].
+
+Update ivy.org. See [[https://github.com/abo-abo/swiper/issues/1951][#1951]], 
[[https://github.com/abo-abo/swiper/issues/2046][#2046]], 
[[https://github.com/abo-abo/swiper/issues/2143][#2143]].
+
+Mention el:char-fold-to-regexp. See 
[[https://github.com/abo-abo/swiper/issues/1977][#1977]].
+
+Mention automatically integrated packages in ivy.org. See 
[[https://github.com/abo-abo/swiper/issues/1674][#1674]].
+
+Remove outdated magit customization. See 
[[https://github.com/abo-abo/swiper/issues/2035][#2035]].
+
+el:ivy-read docstring. See 
[[https://github.com/abo-abo/swiper/issues/2107][#2107]].
+
+el:ivy-reverse-i-search docstring. See 
[[https://github.com/abo-abo/swiper/issues/2126][#2126]].
+
+Add autoloads for various commands. See 
[[https://github.com/abo-abo/swiper/issues/2131][#2131]].
+-----
+*** ivy-avy
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-avy
+:END:
+Fix when there's a scroll.
+-----
+*** ivy-completion-in-region
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-completion-in-region
+:END:
+Don't insert initial-input if nil. See 
[[https://github.com/abo-abo/swiper/issues/2086][#2086]].
+-----
+*** ivy-display-function-overlay
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-display-function-overlay
+:END:
+Don't assume in-buffer completion. See 
[[https://github.com/abo-abo/swiper/issues/2048][#2048]], 
[[https://github.com/abo-abo/swiper/issues/2049][#2049]].
+-----
+*** ivy-help
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-help
+:END:
+Set el:org-hide-emphasis-markers. Reveal all Org contents. See 
[[https://github.com/abo-abo/swiper/issues/2021][#2021]].
+Hide Org markup locally. See 
[[https://github.com/abo-abo/swiper/issues/2085][#2085]].
+-----
+*** ivy-immediate-done
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-immediate-done
+:END:
+Improve for el:make-directory. See 
[[https://github.com/abo-abo/swiper/issues/1170][#1170]], 
[[https://github.com/abo-abo/swiper/issues/1719][#1719]], 
[[https://github.com/abo-abo/swiper/issues/2139][#2139]].
+-----
+*** ivy-insert-current
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-insert-current
+:END:
+Insert text without properties. See 
[[https://github.com/abo-abo/swiper/issues/2040][#2040]].
+-----
+*** ivy-next-history-element
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-next-history-element
+:END:
+Use el:minibuffer-default for el:dired-dwim-target.
+
+#+begin_src elisp
+(setq dired-dwim-target t)
+#+end_src
+
+Is a nice productivity boost. Except for the situation when you want to copy 
the file to
+the current directory, and a different directory is preselected instead. When 
this
+happens, you can now press ~M-n~ to select the current directory.
+-----
+*** ivy-occur
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-occur
+:END:
+Make ivy-switch-buffer-occur work with multi-pass regex builders. See 
[[https://github.com/abo-abo/swiper/issues/1973][#1973]].
+
+Make find-file-occur work with multi-pass regex builders. See 
[[https://github.com/abo-abo/swiper/issues/1984][#1984]].
+
+Make grep-occur work with multi-pass regex builders. See 
[[https://github.com/abo-abo/swiper/issues/2033][#2033]].
+
+Make swiper occur wgrep work for narrowed buffers. See 
[[https://github.com/abo-abo/swiper/issues/1848][#1848]].
+
+Don't setq-local el:ivy--directory. See 
[[https://github.com/abo-abo/swiper/issues/1866][#1866]].
+
+Don't hightlight the file name part. See 
[[https://github.com/abo-abo/swiper/issues/2073][#2073]].
+
+Fix missing line numbers. See 
[[https://github.com/abo-abo/swiper/issues/2076][#2076]].
+
+Fix for el:counsel-find-file. See 
[[https://github.com/abo-abo/swiper/issues/2094][#2094]].
+
+el:ivy-occur-revert-buffer should stay on the same line.
+-----
+*** ivy-occur-press
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-occur-press
+:END:
+Improve when the window config was changed.
+-----
+*** ivy-partial
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-partial
+:END:
+Works better when selecting files. See 
[[https://github.com/abo-abo/swiper/issues/2103][#2103]].
+-----
+*** ivy-previous-line-or-history
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-previous-line-or-history
+:END:
+Improve. See [[https://github.com/abo-abo/swiper/issues/2137][#2137]], 
[[https://github.com/abo-abo/swiper/issues/2138][#2138]], 
[[https://github.com/abo-abo/swiper/issues/1137][#1137]].
+-----
+*** ivy-read
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-read
+:END:
+Allow to override global actions per command. See 
[[https://github.com/abo-abo/swiper/issues/1873][#1873]].
+
+Require TRAMP earlier so that there's completion. See 
[[https://github.com/abo-abo/swiper/issues/1918][#1918]].
+
+Allow all re-builders to use el:ivy-highlight-grep-commands. See 
[[https://github.com/abo-abo/swiper/issues/1983][#1983]].
+
+Improve column calculation in el:ivy-dispatching-done-hydra.
+
+Allow recursive minibuffers to use el:ivy-display-functions-alist. See 
[[https://github.com/abo-abo/swiper/issues/1995][#1995]].
+
+Don't use invalid =:preselect= as a regexp. See 
[[https://github.com/abo-abo/swiper/issues/2002][#2002]].
+
+Allow to select "" when prompt is selectable. See 
[[https://github.com/abo-abo/swiper/issues/1924][#1924]].
+
+Fix el:all-completions returning $$. See 
[[https://github.com/abo-abo/swiper/issues/2012][#2012]].
+
+Fix matcher not called on input "". See 
[[https://github.com/abo-abo/swiper/issues/2013][#2013]].
+
+Fix filter for el:ivy--regex-ignore-order. See 
[[https://github.com/abo-abo/swiper/issues/2015][#2015]].
+
+Don't offer virtual buffers for plain el:switch-to-buffer. See 
[[https://github.com/abo-abo/swiper/issues/839][#839]].
+
+el:ivy-completion-in-region-action obeys :exit-function.
+
+Shrink ivy window after reading action. See 
[[https://github.com/abo-abo/swiper/issues/2079][#2079]].
+
+Use single face for highlighting adjacent groups. See 
[[https://github.com/abo-abo/swiper/issues/2080][#2080]].
+
+Use el:ivy-flx-limit more. See 
[[https://github.com/abo-abo/swiper/issues/2081][#2081]].
+
+Fix el:ivy-read-action. See 
[[https://github.com/abo-abo/swiper/issues/2082][#2082]].
+
+Set el:line-spacing to nil in the minibuffer. See 
[[https://github.com/abo-abo/swiper/issues/2118][#2118]].
+-----
+*** ivy-reverse-i-search
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-reverse-i-search
+:END:
+Don't bind ivy-recursive-restore to nil. See 
[[https://github.com/abo-abo/swiper/issues/1215][#1215]].
+-----
+*** ivy--sort
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy--sort
+:END:
+Higher priority for el:ivy-sort-matches-functions-alist. See 
[[https://github.com/abo-abo/swiper/issues/2136][#2136]].
+-----
+*** ivy-switch-buffer
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-switch-buffer
+:END:
+Preserve the index after kill. See 
[[https://github.com/abo-abo/swiper/issues/1787][#1787]], 
[[https://github.com/abo-abo/swiper/issues/1910][#1910]].
+
+Fix ~M-o f~ for virtual buffers. See 
[[https://github.com/abo-abo/swiper/issues/2111][#2111]].
+-----
+*** ivy-thing-at-point
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-thing-at-point
+:END:
+Extend. See [[https://github.com/abo-abo/swiper/issues/1871][#1871]].
+-----
+*** ivy-use-selectable-prompt
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-ivy-use-selectable-prompt
+:END:
+Don't highlight if not needed.
+-----
+*** swiper
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-swiper
+:END:
+Fix blinks in non-graphical Emacs. See 
[[https://github.com/abo-abo/swiper/issues/1921][#1921]], 
[[https://github.com/abo-abo/swiper/issues/1923][#1923]].
+
+Documentation. See [[https://github.com/abo-abo/swiper/issues/643][#643]].
+
+Don't rely on el:window-start in terminal.  el:window-start and el:window-end 
is not
+reliable when in a terminal. It can be made reliable if a el:redisplay is 
performed, but
+then we get annoying blinking. See 
[[https://github.com/abo-abo/swiper/issues/1928][#1928]].
+
+Add extra condition to recenter in terminal. See 
[[https://github.com/abo-abo/swiper/issues/2059][#2059]].
+
+Fix overlays clean up. See 
[[https://github.com/abo-abo/swiper/issues/2064][#2064]].
+
+Obey el:search-invisible. See 
[[https://github.com/abo-abo/swiper/issues/1739][#1739]].
+
+Improve highlighting with el:char-fold-to-regexp. See 
[[https://github.com/abo-abo/swiper/issues/2124][#2124]].
+
+Add group for faces. See 
[[https://github.com/abo-abo/swiper/issues/2135][#2135]].
+-----
+*** swiper-avy
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-swiper-avy
+:END:
+If the input is 1 char, re-highlight. See 
[[https://github.com/abo-abo/swiper/issues/1915][#1915]].
+
+Warn if no input.
+
+Fix for el:swiper-background-faces. See 
[[https://github.com/abo-abo/swiper/issues/2019][#2019]].
+
+Handle quit. See [[https://github.com/abo-abo/swiper/issues/2062][#2062]].
+
+Work for el:swiper-isearch. See 
[[https://github.com/abo-abo/swiper/issues/2134][#2134]].
+-----
+*** swiper-font-lock-exclude-p
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-swiper-font-lock-exclude-p
+:END:
+Exclude el:xref--xref-buffer-mode from font-lock. See 
[[https://github.com/abo-abo/swiper/issues/1917][#1917]].
+
+Try checking for non prog-mode.
+-----
+*** swiper-multi
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-swiper-multi
+:END:
+Misc fixes. See [[https://github.com/abo-abo/swiper/issues/2101][#2101]], 
[[https://github.com/abo-abo/swiper/issues/2102][#2102]].
+-----
+*** swiper-query-replace
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-fx-swiper-query-replace
+:END:
+Fix for el:ivy--regex-ignore-order.
+
+Check for empty input. See 
[[https://github.com/abo-abo/swiper/issues/2066][#2066]].
+** New Features
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-new-features
+:END:
+-----
+*** counsel-descbinds
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-descbinds
+:END:
+Add ~M-o x~ el:counsel-descbinds-action-exec. See 
[[https://github.com/abo-abo/swiper/issues/2024][#2024]].
+-----
+*** counsel-file-jump
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-file-jump
+:END:
+Add ~M-o d~ that opens the item in el:dired. See 
[[https://github.com/abo-abo/swiper/issues/2057][#2057]].
+-----
+*** counsel-find-file
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-find-file
+:END:
+Press ~`~ to get completion for bookmarks. This allows you to efficiently jump 
between
+recent directories. See 
[[https://github.com/abo-abo/swiper/issues/1956][#1956]], 
[[https://github.com/abo-abo/swiper/issues/1958][#1958]].
+
+Press ~$~ to get completion for your environment variables that are 
directories. See [[https://github.com/abo-abo/swiper/issues/1932][#1932]],
+[[https://github.com/abo-abo/swiper/issues/1937][#1937]].
+
+New action: ~M-o c~ el:counsel-find-file-copy. See 
[[https://github.com/abo-abo/swiper/issues/1955][#1955]].
+
+New var el:counsel-up-directory-level that customizes ~C-DEL~. See 
[[https://github.com/abo-abo/swiper/issues/1096][#1096]].
+
+New var el:counsel-find-file-extern-extensions. Allows to press ~RET~ instead 
of ~M-o x~ for
+selected file types, for which it doesn't make sense to be opened in Emacs.
+
+When on a remote, ~//~ will cd to the remote root, instead of the local root. 
If you want to
+go to the local root, use ~/ C-j~. See 
[[https://github.com/abo-abo/swiper/issues/1487][#1487]].
+
+When on a remote, ~~~ will cd to the remote home, instead of the local home. 
If you want to
+go to the local home, use ~/ C-j ~~. You can also try =`=.
+
+New binding when completing file names ~C-M-y~ el:ivy-insert-current-full that 
obsoletes
+el:counsel-yank-directory. See 
[[https://github.com/abo-abo/swiper/issues/2092][#2092]].
+
+You can now use ~RET~ or ~C-m~ (in place of ~C-M-j~) to create a directory, 
even if it matches
+an existing file.
+-----
+*** counsel-git-grep
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-git-grep
+:END:
+New variable el:counsel-git-grep-cmd-function. Customize how git-grep is 
called based on
+input.
+-----
+*** counsel-git-log
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-git-log
+:END:
+Bind ~M-o v~ el:counsel-git-log-show-commit-action to visit the item in
+el:magit-show-commit. See 
[[https://github.com/abo-abo/swiper/issues/2129][#2129]], 
[[https://github.com/abo-abo/swiper/issues/2148][#2148]].
+-----
+*** counsel-grep
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-grep
+:END:
+Add el:counsel-grep-history. See 
[[https://github.com/abo-abo/swiper/issues/1914][#1914]].
+-----
+*** counsel-grep-use-swiper-p
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-grep-use-swiper-p
+:END:
+When this function returns non-nil, el:counsel-grep-or-swiper will call 
el:swiper, else
+el:counsel-grep-or-swiper. See 
[[https://github.com/abo-abo/swiper/issues/1908][#1908]].
+-----
+*** counsel-locate
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-locate
+:END:
+Automatically call =updatedb= when your home folder is encrypted.
+Use el:counsel-locate-db-path to customize.
+-----
+*** counsel-mark-ring
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-mark-ring
+:END:
+Add preview and highlight by candidate. See 
[[https://github.com/abo-abo/swiper/issues/2078][#2078]].
+
+New variable el:counsel-descbinds-function. See 
[[https://github.com/abo-abo/swiper/issues/1876][#1876]], 
[[https://github.com/abo-abo/swiper/issues/2091][#2091]].
+-----
+*** counsel-M-x
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-m-x
+:END:
+Optionally expand aliases.  For example, if =rb= is aliased to 
el:revert-buffer, and bound
+to ~C-c r~, el:counsel-M-x will show: =rb (revert-buffer) (C-c r)=.
+Customize with el:counsel-alias-expand, enabled by default.
+See [[https://github.com/abo-abo/swiper/issues/1904][#1904]].
+-----
+*** counsel-rg
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-rg
+:END:
+Dynamically handle look-arounds. See 
[[https://github.com/abo-abo/swiper/issues/1935][#1935]].
+
+Anchor pcre lookarounds to bol. See 
[[https://github.com/abo-abo/swiper/issues/1976][#1976]], 
[[https://github.com/abo-abo/swiper/issues/1979][#1979]].
+
+Add an example of inclusion patterns to the doc.
+
+Press ~C-x C-d~ calls el:counsel-cd that allows you to change the current 
directory.
+
+Add dynamic case folding. Make sure el:counsel-ag-base-command or
+el:counsel-rg-base-command does not include "-i": it will be added 
automatically based on
+your input and el:ivy-case-fold-search. See 
[[https://github.com/abo-abo/swiper/issues/1869][#1869]].
+-----
+*** counsel-set-variable
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-counsel-set-variable
+:END:
+Better annotations for options.
+If the option is e.g.:
+#+begin_example
+(const :tag "Dotfiles and Lockfiles" "\\(?:\\`\\|[/\\]\\)\\(?:[#.]\\)")
+#+end_example
+then display:
+#+begin_example
+Dotfiles and Lockfiles: \(?:\`\|[/\]\)\(?:[#.]\)
+#+end_example
+instead of:
+#+begin_example
+\\(?:\\`\\|[/\\]\\)\\(?:[#.]\\)
+#+end_example
+
+If the option's value is nil, but a =:tag= is present, display the option.
+-----
+*** ivy-avy
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-ivy-avy
+:END:
+Allow to scroll with ~C-v~ and ~M-v~.
+-----
+*** ivy-dispatching-done-hydra
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-ivy-dispatching-done-hydra
+:END:
+New variable el:ivy-dispatching-done-hydra-exit-keys. In case you bind
+el:ivy-dispatching-done-hydra to a custom key.
+-----
+*** ivy-read
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-ivy-read
+:END:
+Allow to mark/unmark candidates with ~m~, ~u~, ~DEL~, ~t~. The bindings are 
similar to what
+el:dired provides. They are available in the ~C-o~ hydra. See 
[[https://github.com/abo-abo/swiper/issues/561][#561]].
+
+Add =:multi-action= argument. If multiple candidates are marked and this 
argument is
+present, call it with the whole list of marked candidates, instead of calling 
=:action= in
+turn for each marked candidate. See 
[[https://github.com/abo-abo/swiper/issues/561][#561]], 
[[https://github.com/abo-abo/swiper/issues/2068][#2068]].
+
+el:ivy-inhibit-action can be a function. This allows you to effectively 
override the
+=:action= argument to el:ivy-read.
+
+New var el:ivy-dispatching-done-idle can delay the hint by a specified amount 
of seconds.
+
+=:update-fn= argument can now be ='auto=. This will call =:action= each time 
the current
+candidate changes.
+
+New var el:ivy-format-functions-alist that obsoletes el:ivy-format-function. 
See [[https://github.com/abo-abo/swiper/issues/2083][#2083]],
+[[https://github.com/abo-abo/swiper/issues/2084][#2084]], 
[[https://github.com/abo-abo/swiper/issues/2130][#2130]].
+
+New var el:ivy-display-functions-alist that obsoletes el:ivy-display-function. 
See [[https://github.com/abo-abo/swiper/issues/2089][#2089]].
+
+Add ability to resume dynamic collections. See 
[[https://github.com/abo-abo/swiper/issues/1095][#1095]], 
[[https://github.com/abo-abo/swiper/issues/2112][#2112]].
+-----
+*** ivy--regex
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-ivy--regex
+:END:
+Match initial dot in the input as a literal dot.  This brings much more 
usability,
+e.g. enter ".org" to switch between Org-mode files, ".el" for Elisp etc.
+-----
+*** ivy-reverse-i-search
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-ivy-reverse-i-search
+:END:
+New binding ~C-k~ el:ivy-reverse-i-search-kill. Remove elements from history.
+-----
+*** ivy-sort-matches-functions-alist
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-ivy-sort-matches-functions-alist
+:END:
+Sort shorter matches first for el:ivy-completion-in-region.
+-----
+*** ivy-switch-buffer
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-ivy-switch-buffer
+:END:
+Add ~M-o x~ el:counsel-open-buffer-file-externally. See 
[[https://github.com/abo-abo/swiper/issues/2108][#2108]], 
[[https://github.com/abo-abo/swiper/issues/2115][#2115]].
+
+Move ~C-c C-k~ el:ivy-switch-buffer-kill to ~C-k~.
+
+Fix el:ivy-push-view windows layout. See 
[[https://github.com/abo-abo/swiper/issues/2109][#2109]].
+-----
+*** swiper
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-swiper
+:END:
+New variable el:swiper-use-visual-line-p. Configure to prevent el:swiper from 
becoming
+slow in huge buffers where el:visual-line-mode is enabled.
+
+Add preview overlays. See 
[[https://github.com/abo-abo/swiper/issues/1948][#1948]].
+-----
+*** swiper-query-replace
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nf-swiper-query-replace
+:END:
+Use el:query-replace-compile-replacement to allow using Elisp in replacements. 
 Simply use
+~M-i~ to insert and edit the suggested replacement. See 
[[https://github.com/abo-abo/swiper/issues/2096][#2096]].
+
+For example, suppose in swiper.el, we want to rename:
+#+begin_example
+(defTYPE swiper- to (defTYPE ivy
+#+end_example
+where TYPE is (group, face, fun, var ...).
+
+1. el:swiper-isearch for =(def\sw+ swiper=
+2. ~M-q~ to replace and ~TAB~ to get: =\,(concat \1 " " \2)=
+3. Modify it to =\,(concat \1 " ivy")=
+** New Commands
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-new-commands
+:END:
+-----
+*** counsel-compile
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-counsel-compile
+:END:
+Call el:compile, completing with smart suggestions. See 
[[https://github.com/abo-abo/swiper/issues/1941][#1941]], 
[[https://github.com/abo-abo/swiper/issues/1963][#1963]], 
[[https://github.com/abo-abo/swiper/issues/1966][#1966]], 
[[https://github.com/abo-abo/swiper/issues/1968][#1968]], 
[[https://github.com/abo-abo/swiper/issues/1972][#1972]],
+[[https://github.com/abo-abo/swiper/issues/2077][#2077]].
+
+Add el:counsel-compile-env. See 
[[https://github.com/abo-abo/swiper/issues/2030][#2030]].
+-----
+*** counsel-dired
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-counsel-dired
+:END:
+Like el:counsel-find-file, but open el:dired instead. See 
[[https://github.com/abo-abo/swiper/issues/1993][#1993]], 
[[https://github.com/abo-abo/swiper/issues/1999][#1999]].
+-----
+*** counsel-minor
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-counsel-minor
+:END:
+Toggle minor mode. The interface is similar to el:counsel-package, you enable 
modes with
+"+mode" and disable with "-mode". See 
[[https://github.com/abo-abo/swiper/issues/2000][#2000]], 
[[https://github.com/abo-abo/swiper/issues/2070][#2070]].
+-----
+*** counsel-register
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-counsel-register
+:END:
+Completion for registers: buffer positions, text, rectangles, window configs, 
frame
+configs, macros etc. See 
[[https://github.com/abo-abo/swiper/issues/2056][#2056]].
+-----
+*** counsel-switch-buffer
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-counsel-switch-buffer
+:END:
+Like el:ivy-switch-buffer, but you get automatic live preview.
+See [[https://github.com/abo-abo/swiper/issues/1895][#1895]], 
[[https://github.com/abo-abo/swiper/issues/1897][#1897]], 
[[https://github.com/abo-abo/swiper/issues/1954][#1954]], 
[[https://github.com/abo-abo/swiper/issues/1971][#1971]], 
[[https://github.com/abo-abo/swiper/issues/1959][#1959]], 
[[https://github.com/abo-abo/swiper/issues/2009][#2009]], 
[[https://github.com/abo-abo/swiper/issues/2113][#2113]].
+-----
+*** counsel-switch-buffer-other-window
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-counsel-switch-buffer-other-window
+:END:
+Switch to another buffer in another window, with preview. See 
[[https://github.com/abo-abo/swiper/issues/2022][#2022]], 
[[https://github.com/abo-abo/swiper/issues/2067][#2067]].
+-----
+*** swiper-all-thing-at-point
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-swiper-all-thing-at-point
+:END:
+Start el:swiper-all with el:symbol-at-point as input. See 
[[https://github.com/abo-abo/swiper/issues/2106][#2106]].
+-----
+*** swiper-isearch
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-swiper-isearch
+:END:
+A faster version of el:swiper that's not line-based:
+- Much faster startup
+- When there are many matches on the same line, you can select each on 
individually
+
+See [[https://github.com/abo-abo/swiper/issues/1931][#1931]], 
[[https://github.com/abo-abo/swiper/issues/2014][#2014]], 
[[https://github.com/abo-abo/swiper/issues/2018][#2018]], 
[[https://github.com/abo-abo/swiper/issues/2029][#2029]], 
[[https://github.com/abo-abo/swiper/issues/2031][#2031]], 
[[https://github.com/abo-abo/swiper/issues/2034][#2034]], 
[[https://github.com/abo-abo/swiper/issues/2039][#2039]], 
[[https://github.com/abo-abo/swiper/issues/2058][#2058]], 
[[https://github.com/abo [...]
+
+New variable el:swiper-isearch-highlight-delay. Used to delay matches that are 
just one
+character by 0.2s. Usually in that time frame a second key will be added to 
the input.
+
+Obey el:search-default-mode. See 
[[https://github.com/abo-abo/swiper/issues/622][#622]], 
[[https://github.com/abo-abo/swiper/issues/2095][#2095]].
+-----
+*** swiper-isearch-thing-at-point
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-swiper-isearch-thing-at-point
+:END:
+Start el:swiper-isearch with el:symbol-at-point as input. See 
[[https://github.com/abo-abo/swiper/issues/2025][#2025]], 
[[https://github.com/abo-abo/swiper/issues/2029][#2029]].
+-----
+*** swiper-isearch-toggle
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-swiper-isearch-toggle
+:END:
+A two-way toggle between el:swiper and el:isearch-mode. See 
[[https://github.com/abo-abo/swiper/issues/2061][#2061]], 
[[https://github.com/abo-abo/swiper/issues/2065][#2065]].
+-----
+*** swiper-thing-at-point
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-swiper-thing-at-point
+:END:
+Start el:swiper with el:symbol-at-point as input. See 
[[https://github.com/abo-abo/swiper/issues/2027][#2027]].
+-----
+*** swiper-backward
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-swiper-backward
+:END:
+el:isearch-backward with an overview. See 
[[https://github.com/abo-abo/swiper/issues/1172][#1172]], 
[[https://github.com/abo-abo/swiper/issues/2132][#2132]].
+-----
+*** counsel-grep-or-swiper-backward
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-counsel-grep-or-swiper-backward
+:END:
+See [[https://github.com/abo-abo/swiper/issues/2132][#2132]].
+-----
+*** swiper-isearch-backward
+:PROPERTIES:
+:CUSTOM_ID: 0-12-0-nc-swiper-isearch-backward
+:END:
+See [[https://github.com/abo-abo/swiper/issues/2125][#2125]].
+-----
diff --git a/packages/ivy/doc/ivy-help.org b/packages/ivy/doc/ivy-help.org
index 1eb71c7..3a94118 100644
--- a/packages/ivy/doc/ivy-help.org
+++ b/packages/ivy/doc/ivy-help.org
@@ -132,7 +132,7 @@ Additionally, here are the keys that are otherwise not 
bound:
 - ~<~ and ~>~ adjust the height of the minibuffer.
 - ~c~ (=ivy-toggle-calling=) - toggle calling the current action each
   time a different candidate is selected.
-- ~m~ (=ivy-rotate-preferred-builders=) - rotate regex matcher.
+- ~M~ (=ivy-rotate-preferred-builders=) - rotate regex matcher.
 - ~w~ and ~s~ scroll the actions list.
 
 Minibuffer editing is disabled when Hydra is active.
diff --git a/packages/ivy/doc/ivy.org b/packages/ivy/doc/ivy.org
index 4324191..3258669 100644
--- a/packages/ivy/doc/ivy.org
+++ b/packages/ivy/doc/ivy.org
@@ -58,7 +58,7 @@ ivy-ox.el then ~C-c C-e i t~ in the ivy.org buffer.
 :CUSTOM_ID: copying
 :END:
 #+TEXINFO: @ifnottex
-Ivy manual, version 0.8.0
+Ivy manual, version 0.11.0
 
 Ivy is an interactive interface for completion in Emacs. Emacs uses
 completion mechanism in a variety of contexts: code, menus, commands,
@@ -118,7 +118,7 @@ discoverability.
      example, adding a custom display function that points to a
      selected candidate with =>=, instead of highlighting the selected
      candidate with the =ivy-current-match= face (see
-     =ivy-format-function=). Or take the customization of actions, say
+     =ivy-format-functions-alist=). Or take the customization of actions, say
      after the candidate function is selected. ~RET~ uses
      =counsel-describe-function= to describe the function, whereas
      ~M-o d~ jumps to that function's definition in the code. The
@@ -264,6 +264,7 @@ with some sample bindings:
 - Ivy-based interface to shell and system tools ::
 
      #+begin_src elisp
+     (global-set-key (kbd "C-c c") 'counsel-compile)
      (global-set-key (kbd "C-c g") 'counsel-git)
      (global-set-key (kbd "C-c j") 'counsel-git-grep)
      (global-set-key (kbd "C-c k") 'counsel-ag)
@@ -315,7 +316,7 @@ where the familiar ~C-a~, ~C-f~, ~M-d~, ~M-DEL~, ~M-b~, 
~M-w~, ~C-k~,
      =ivy-wrap= is set to =t=, =ivy-next-line= and =ivy-previous-line=
      will cycle past the last and the first candidates respectively.
 
-     Warp-around behavior is off by default.
+     Wrap-around behavior is off by default.
 
 - User Option =ivy-height= ::
      Use this option to adjust the minibuffer height, which also
@@ -952,13 +953,9 @@ To examine each action with each candidate in a 
key-efficient way, try:
      =completing-read-function= (which =ivy-mode= sets). Try refiling
      headings with similar names to appreciate =ivy-mode=.
 - =magit= ::
-     Magit requires this setting for ivy completion:
-
-     #+begin_src elisp
-     (setq magit-completing-read-function 'ivy-completing-read)
-     #+end_src
+     Uses ivy by default if Ivy is installed.
 - =find-file-in-project= ::
-     It uses ivy by default if Ivy is installed.
+     Uses ivy by default if Ivy is installed.
 - =projectile= ::
      Projectile requires this setting for ivy completion:
 
@@ -972,6 +969,10 @@ To examine each action with each candidate in a 
key-efficient way, try:
      (setq helm-make-completion-method 'ivy)
      #+end_src
 
+- automatically integrated packages ::
+     Ivy re-uses the following packages if they are installed:
+     =avy=, =amx= or =smex=, =flx=, and =wgrep=.
+
 * Commands
 :PROPERTIES:
 :CUSTOM_ID: commands
@@ -1021,6 +1022,22 @@ bindings that work here:
      files previously opened. It also works with TRAMP files.
 
 *** Using TRAMP
+:PROPERTIES:
+:CUSTOM_ID: using-tramp
+:END:
+- ~~~ (tilde) ::
+     Move to the home directory. Either the local or the remote one, depending 
on the
+     current directory. The boolean option =ivy-magic-tilde= decides whether 
the binding to
+     do this is ~~~ or ~~/~.
+
+- ~//~ (double slash) ::
+     Move to the root directory. Either the local or the remote one, depending 
on the
+     current directory. Here, you can also select a TRAMP connection method, 
such as =ssh=
+     or =scpx=.
+
+- ~/ C-j~ ::
+     Move the the local root directory.
+
 From any directory, with the empty input, inputting =/ssh:= and pressing
 ~C-j~ (or ~RET~, which is the same thing) completes for host and user
 names.
@@ -1113,13 +1130,17 @@ features such as multi-actions, non-exiting actions, 
=ivy-occur= and
 - =history= ::
      Name of the symbol to store history. See =completing-read=.
 - =preselect= ::
-     When set to a string value, select the first candidate matching
-     this value.
+     Determines which one of the candidates to initially select.
 
      When set to an integer value, select the candidate with that
      index value.
 
-     Every time the input becomes empty, the item corresponding to to
+     When set to any other non-nil value, select the first candidate
+     matching this value.  Comparison is first done with =equal=.
+     If this fails, and when applicable, match =preselect= as a
+     regular expression.
+
+     Every time the input becomes empty, the item corresponding to
      =preselect= is selected.
 - =keymap= ::
      A keymap to be composed with =ivy-minibuffer-map=. This keymap
diff --git a/packages/ivy/doc/ivy.texi b/packages/ivy/doc/ivy.texi
deleted file mode 100644
index 426591c..0000000
--- a/packages/ivy/doc/ivy.texi
+++ /dev/null
@@ -1,1747 +0,0 @@
-\input texinfo    @c -*- texinfo -*-
-@c %**start of header
-@setfilename ivy.info
-@settitle Ivy User Manual
-@documentencoding UTF-8
-@documentlanguage en
-@c %**end of header
-
-@copying
-@ifnottex
-Ivy manual, version 0.8.0
-
-Ivy is an interactive interface for completion in Emacs. Emacs uses
-completion mechanism in a variety of contexts: code, menus, commands,
-variables, functions, etc. Completion entails listing, sorting,
-filtering, previewing, and applying actions on selected items. When
-active, @code{ivy-mode} completes the selection process by narrowing
-available choices while previewing in the minibuffer. Selecting the
-final candidate is either through simple keyboard character inputs or
-through powerful regular expressions.
-@end ifnottex
-
-Copyright (C) 2015-2018 Free Software Foundation, Inc.
-
-@quotation
-Permission is granted to copy, distribute and/or modify this document
-under the terms of the GNU Free Documentation License, Version 1.3 or
-any later version published by the Free Software Foundation; with no
-Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
-and with the Back-Cover Texts as in (a) below.  A copy of the license
-is included in the section entitled ``GNU Free Documentation License.''
-
-(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
-modify this GNU manual.''
-@end quotation
-@end copying
-
-@dircategory Emacs
-@direntry
-* Ivy: (ivy).           Using Ivy for completion.
-@end direntry
-
-@finalout
-@titlepage
-@title Ivy User Manual
-@author Oleh Krehel
-@page
-@vskip 0pt plus 1filll
-@insertcopying
-@end titlepage
-
-@contents
-
-@ifnottex
-@node Top
-@top Ivy User Manual
-@end ifnottex
-
-@menu
-* Introduction::
-* Installation::
-* Getting started::
-* Key bindings::
-* Completion Styles::
-* Customization::
-* Commands::
-* API::
-* Variable Index::
-* Keystroke Index::
-
-@detailmenu
---- The Detailed Node Listing ---
-
-Installation
-
-* Installing from Emacs Package Manager::
-* Installing from the Git repository::
-
-Getting started
-
-* Basic customization::
-
-Key bindings
-
-* Global key bindings::
-* Minibuffer key bindings::
-
-Minibuffer key bindings
-
-* Key bindings for navigation::
-* Key bindings for single selection, action, then exit minibuffer: Key 
bindings for single selection action then exit minibuffer. 
-* Key bindings for multiple selections and actions, keep minibuffer open: Key 
bindings for multiple selections and actions keep minibuffer open. 
-* Key bindings that alter the minibuffer input::
-* Other key bindings::
-* Hydra in the minibuffer::
-* Saving the current completion session to a buffer::
-
-Completion Styles
-
-* ivy--regex-plus::
-* ivy--regex-ignore-order::
-* ivy--regex-fuzzy::
-
-Customization
-
-* Faces::
-* Defcustoms::
-* Actions::
-* Packages::
-
-Actions
-
-* What are actions?::
-* How can different actions be called?::
-* How to modify the actions list?::
-* Example - add two actions to each command::
-* Example - define a new command with several actions::
-
-Example - add two actions to each command
-
-* How to undo adding the two actions::
-* How to add actions to a specific command::
-
-Example - define a new command with several actions
-
-* Test the above function with @code{ivy-occur}::
-
-Commands
-
-* File Name Completion::
-* Buffer Name Completion::
-* Counsel commands::
-
-File Name Completion
-
-* Using TRAMP::
-
-API
-
-* Required arguments for @code{ivy-read}::
-* Optional arguments for @code{ivy-read}::
-* Example - @code{counsel-describe-function}::
-* Example - @code{counsel-locate}::
-* Example - @code{ivy-read-with-extra-properties}::
-
-@end detailmenu
-@end menu
-
-@node Introduction
-@chapter Introduction
-
-Ivy is for quick and easy selection from a list. When Emacs prompts
-for a string from a list of several possible choices, Ivy springs into
-action to assist in narrowing and picking the right string from a vast
-number of choices.
-
-Ivy strives for minimalism, simplicity, customizability and
-discoverability.
-
-@subsubheading Minimalism
-@indentedblock
-Uncluttered minibuffer is minimalism. Ivy shows the completion
-defaults, the number of matches, and 10 candidate matches below
-the input line. Customize @code{ivy-height} to adjust the number of
-candidate matches displayed in the minibuffer.
-@end indentedblock
-@subsubheading Simplicity
-@indentedblock
-Simplicity is about Ivy's behavior in the minibuffer. It is also
-about the code interface to extend Ivy's functionality. The
-minibuffer area behaves as close to @code{fundamental-mode} as
-possible. @kbd{SPC} inserts a space, for example, instead of being
-bound to the more complex @code{minibuffer-complete-word}. Ivy's code
-uses easy-to-examine global variables; avoids needless
-complications with branch-introducing custom macros.
-@end indentedblock
-@subsubheading Customizability
-@indentedblock
-Customizability is about being able to use different methods and
-interfaces of completion to tailor the selection process. For
-example, adding a custom display function that points to a
-selected candidate with @code{>}, instead of highlighting the selected
-candidate with the @code{ivy-current-match} face (see
-@code{ivy-format-function}). Or take the customization of actions, say
-after the candidate function is selected. @kbd{RET} uses
-@code{counsel-describe-function} to describe the function, whereas
-@kbd{M-o d} jumps to that function's definition in the code. The
-@kbd{M-o} prefix can be uniformly used with characters like @kbd{d} to
-group similar actions.
-@end indentedblock
-@subsubheading Discoverability
-@indentedblock
-Ivy displays easily discoverable commands through the hydra
-facility.  @kbd{C-o} in the minibuffer displays a hydra menu. It
-opens up within an expanded minibuffer area. Each menu item comes
-with short documentation strings and highlighted one-key
-completions. So discovering even seldom used keys is simply a
-matter of @kbd{C-o} in the minibuffer while in the midst of the Ivy
-interaction. This discoverability minimizes exiting Ivy interface
-for documentation look-ups.
-@end indentedblock
-
-@node Installation
-@chapter Installation
-
-Install Ivy automatically through Emacs's package manager, or manually
-from Ivy's development repository.
-
-Emacs 24.3 is the oldest version to run Ivy. Emacs 24.4 is the oldest
-version that runs Ivy with fancy faces display.
-
-@menu
-* Installing from Emacs Package Manager::
-* Installing from the Git repository::
-@end menu
-
-@node Installing from Emacs Package Manager
-@section Installing from Emacs Package Manager
-
-@kbd{M-x} @code{package-install} @kbd{RET} @code{ivy} @kbd{RET}
-
-Ivy is installed as part of @code{ivy} package, which is available from two
-different package archives, GNU ELPA and MELPA. For the latest stable
-version, use the GNU ELPA archives using the above M-x command.
-
-For current hourly builds, use the MELPA archives. In MELPA, Ivy is
-split into three packages: @code{ivy}, @code{swiper} and @code{counsel}; you 
can simply
-install @code{counsel} which will bring in the other two as dependencies.
-See the code below for adding MELPA to the list of package archives:
-
-@lisp
-(require 'package)
-(add-to-list 'package-archives
-            '("melpa" . "https://melpa.org/packages/";))
-@end lisp
-
-After this do @kbd{M-x} @code{package-refresh-contents} @kbd{RET}, followed by 
@kbd{M-x}
-@code{package-install} @kbd{RET} @code{counsel} @kbd{RET}.
-
-For package manager details, see @ref{Packages,,,emacs,}.
-
-@node Installing from the Git repository
-@section Installing from the Git repository
-
-@subsubheading Why install from Git?
-@indentedblock
-@itemize
-@item
-No need to wait for MELPA's hourly builds
-@item
-Easy to revert to previous versions
-@item
-Contribute to Ivy's development; send patches; pull requests
-@end itemize
-@end indentedblock
-
-
-@subsubheading Configuration steps
-@indentedblock
-First clone the Swiper repository with:
-
-@example
-cd ~/git && git clone https://github.com/abo-abo/swiper
-cd swiper && make compile
-@end example
-
-Second, add these lines to the Emacs init file:
-
-@lisp
-(add-to-list 'load-path "~/git/swiper/")
-(require 'ivy)
-@end lisp
-
-Then, update the code with:
-
-@example
-git pull
-make
-@end example
-@end indentedblock
-
-@node Getting started
-@chapter Getting started
-
-First enable Ivy completion everywhere:
-
-@lisp
-(ivy-mode 1)
-@end lisp
-
-Note: @code{ivy-mode} can be toggled on and off with @kbd{M-x} @code{ivy-mode}.
-
-@menu
-* Basic customization::
-@end menu
-
-@node Basic customization
-@section Basic customization
-
-Here are some basic settings particularly useful for new Ivy users:
-
-@lisp
-(setq ivy-use-virtual-buffers t)
-(setq ivy-count-format "(%d/%d) ")
-@end lisp
-
-If you want, you can go without any customizations at all. The above
-settings are the most bang for the buck in terms of customization.  So
-users that typically don't like customize a lot are advised to look at
-these settings first.
-
-For more advanced customizations, refer to @code{M-x describe-variable}
-documentation.
-
-@node Key bindings
-@chapter Key bindings
-
-@menu
-* Global key bindings::
-* Minibuffer key bindings::
-@end menu
-
-@node Global key bindings
-@section Global key bindings
-
-Here is a list of commands that are useful to be bound globally, along
-with some sample bindings:
-
-@subsubheading Ivy-based interface to standard commands
-@indentedblock
-@lisp
-(global-set-key (kbd "C-s") 'swiper)
-(global-set-key (kbd "M-x") 'counsel-M-x)
-(global-set-key (kbd "C-x C-f") 'counsel-find-file)
-(global-set-key (kbd "<f1> f") 'counsel-describe-function)
-(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
-(global-set-key (kbd "<f1> l") 'counsel-find-library)
-(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
-(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
-@end lisp
-@end indentedblock
-@subsubheading Ivy-based interface to shell and system tools
-@indentedblock
-@lisp
-(global-set-key (kbd "C-c g") 'counsel-git)
-(global-set-key (kbd "C-c j") 'counsel-git-grep)
-(global-set-key (kbd "C-c k") 'counsel-ag)
-(global-set-key (kbd "C-x l") 'counsel-locate)
-(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
-@end lisp
-@end indentedblock
-@subsubheading Ivy-resume and other commands
-@indentedblock
-@code{ivy-resume} resumes the last Ivy-based completion.
-
-@lisp
-(global-set-key (kbd "C-c C-r") 'ivy-resume)
-@end lisp
-@end indentedblock
-
-@node Minibuffer key bindings
-@section Minibuffer key bindings
-
-@vindex ivy-minibuffer-map
-Ivy includes several minibuffer bindings, which are defined in the
-@code{ivy-minibuffer-map} keymap variable. The most frequently used ones
-are described here.
-
-@code{swiper} or @code{counsel-M-x} add more key bindings through the 
@code{keymap}
-argument to @code{ivy-read}. These keys, also active in the minibuffer, are
-described under their respective commands.
-
-A key feature of @code{ivy-minibuffer-map} is its full editing capability
-where the familiar @kbd{C-a}, @kbd{C-f}, @kbd{M-d}, @kbd{M-DEL}, @kbd{M-b}, 
@kbd{M-w}, @kbd{C-k},
-@kbd{C-y} key bindings work the same as in @code{fundamental-mode}.
-
-@menu
-* Key bindings for navigation::
-* Key bindings for single selection, action, then exit minibuffer: Key 
bindings for single selection action then exit minibuffer. 
-* Key bindings for multiple selections and actions, keep minibuffer open: Key 
bindings for multiple selections and actions keep minibuffer open. 
-* Key bindings that alter the minibuffer input::
-* Other key bindings::
-* Hydra in the minibuffer::
-* Saving the current completion session to a buffer::
-@end menu
-
-@node Key bindings for navigation
-@subsection Key bindings for navigation
-
-@itemize
-@item
-@kbd{C-n} (@code{ivy-next-line}) selects the next candidate
-@item
-@kbd{C-p} (@code{ivy-previous-line}) selects the previous candidate
-@item
-@kbd{M-<} (@code{ivy-beginning-of-buffer}) selects the first candidate
-@item
-@kbd{M->} (@code{ivy-end-of-buffer}) selects the last candidate
-@item
-@kbd{C-v} (@code{ivy-scroll-up-command}) scrolls up by @code{ivy-height} lines
-@item
-@kbd{M-v} (@code{ivy-scroll-down-command}) scrolls down by @code{ivy-height} 
lines
-@end itemize
-
-
-@defopt ivy-wrap
-Specifies the wrap-around behavior for @kbd{C-n} and @kbd{C-p}. When
-@code{ivy-wrap} is set to @code{t}, @code{ivy-next-line} and 
@code{ivy-previous-line}
-will cycle past the last and the first candidates respectively.
-
-Warp-around behavior is off by default.
-@end defopt
-
-@defopt ivy-height
-Use this option to adjust the minibuffer height, which also
-affects scroll size when using @kbd{C-v} and @kbd{M-v} key bindings.
-
-@code{ivy-height} is 10 lines by default.
-@end defopt
-
-@node Key bindings for single selection action then exit minibuffer
-@subsection Key bindings for single selection, action, then exit minibuffer
-
-Ivy can offer several actions from which to choose which action to
-run. This "calling an action" operates on the selected candidate. For
-example, when viewing a list of files, one action could open it for
-editing, one to view it, another to invoke a special function, and so
-on. Custom actions can be added to this interface. The precise action
-to call on the selected candidate can be delayed until after the
-narrowing is completed. No need to exit the interface if unsure which
-action to run. This delayed flexibility and customization of actions
-extends usability of lists in Emacs.
-
-@subsubheading @kbd{C-m} or @kbd{RET} (@code{ivy-done})
-@vindex ivy-done
-@kindex C-m
-@kindex RET
-@indentedblock
-Calls the default action and then exits the minibuffer.
-@end indentedblock
-@subsubheading @kbd{M-o} (@code{ivy-dispatching-done})
-@vindex ivy-dispatching-done
-@kindex M-o
-@indentedblock
-Presents valid actions from which to choose. When only one action
-is available, there is no difference between @kbd{M-o} and @kbd{C-m}.
-@end indentedblock
-@subsubheading @kbd{C-j} (@code{ivy-alt-done})
-@vindex ivy-alt-done
-@kindex C-j
-@indentedblock
-When completing file names, selects the current directory
-candidate and starts a new completion session there. Otherwise,
-it is the same as @code{ivy-done}.
-@end indentedblock
-@subsubheading @kbd{TAB} (@code{ivy-partial-or-done})
-@vindex ivy-partial-or-done
-@kindex TAB
-@indentedblock
-Attempts partial completion, extending current input as much as
-possible. @kbd{TAB TAB} is the same as @kbd{C-j} (@code{ivy-alt-done}).
-
-Example ERT test:
-
-@lisp
-(should
- (equal (ivy-with
-        '(progn
-          (ivy-read "Test: " '("can do" "can't, sorry" "other"))
-          ivy-text)
-        "c <tab>")
-       "can"))
-@end lisp
-@end indentedblock
-@subsubheading @kbd{C-M-j} (@code{ivy-immediate-done})
-@vindex ivy-immediate-done
-@kindex C-M-j
-@indentedblock
-Exits with @emph{the current input} instead of @emph{the current candidate}
-(like other commands).
-
-This is useful e.g. when you call @code{find-file} to create a new
-file, but the desired name matches an existing file. In that
-case, using @kbd{C-j} would select that existing file, which isn't
-what you want - use this command instead.
-@end indentedblock
-@subsubheading @kbd{C-'} (@code{ivy-avy})
-@vindex ivy-avy
-@kindex C-'
-@indentedblock
-Uses avy to select one of the candidates on the current candidate
-page.  This can often be faster than multiple @kbd{C-n} or @kbd{C-p}
-keystrokes followed by @kbd{C-m}.
-@end indentedblock
-
-@node Key bindings for multiple selections and actions keep minibuffer open
-@subsection Key bindings for multiple selections and actions, keep minibuffer 
open
-
-For repeatedly applying multiple actions or acting on multiple
-candidates, Ivy does not close the minibuffer between commands. It
-keeps the minibuffer open for applying subsequent actions.
-
-Adding an extra meta key to the normal key chord invokes the special
-version of the regular commands that enables applying multiple
-actions.
-
-@subsubheading @kbd{C-M-m} (@code{ivy-call})
-@vindex ivy-call
-@kindex C-M-m
-@indentedblock
-Is the non-exiting version of @kbd{C-m} (@code{ivy-done}).
-
-Instead of closing the minibuffer, @kbd{C-M-m} allows selecting
-another candidate or another action. For example, @kbd{C-M-m} on
-functions list invokes @code{describe-function}. When combined with
-@kbd{C-n}, function descriptions can be invoked quickly in
-succession.
-@end indentedblock
-@subsubheading @kbd{C-M-o} (@code{ivy-dispatching-call})
-@vindex ivy-dispatching-call
-@kindex C-M-o
-@indentedblock
-Is the non-exiting version of @kbd{M-o} (@code{ivy-dispatching-done}).
-
-For example, during the @code{counsel-rhythmbox} completion, press
-@kbd{C-M-o e} to en-queue the selected candidate, followed by @kbd{C-n
-     C-m} to play the next candidate - the current action reverts to
-the default one after @kbd{C-M-o}.
-@end indentedblock
-@subsubheading @kbd{C-M-n} (@code{ivy-next-line-and-call})
-@vindex ivy-next-line-and-call
-@kindex C-M-n
-@indentedblock
-Combines @kbd{C-n} and @kbd{C-M-m}. Applies an action and moves to next
-line.
-
-Comes in handy when opening multiple files from
-@code{counsel-find-file}, @code{counsel-git-grep}, @code{counsel-ag}, 
@code{counsel-rg}, or
-@code{counsel-locate} lists. Just hold @kbd{C-M-n} for rapid-fire default
-action on each successive element of the list.
-@end indentedblock
-@subsubheading @kbd{C-M-p} (@code{ivy-previous-line-and-call})
-@vindex ivy-previous-line-and-call
-@kindex C-M-p
-@indentedblock
-Combines @kbd{C-p} and @kbd{C-M-m}.
-
-Similar to the above except it moves through the list in the
-other direction.
-@end indentedblock
-@subsubheading @code{ivy-resume}
-@vindex ivy-resume
-@indentedblock
-Recalls the state of the completion session just before its last
-exit.
-
-Useful after an accidental @kbd{C-m} (@code{ivy-done}).
-@end indentedblock
-
-@node Key bindings that alter the minibuffer input
-@subsection Key bindings that alter the minibuffer input
-
-@subsubheading @kbd{M-n} (@code{ivy-next-history-element})
-@vindex ivy-next-history-element
-@kindex M-n
-@indentedblock
-Cycles forward through the Ivy command history.
-
-Ivy updates an internal history list after each action. When this
-history list is empty, @kbd{M-n} inserts symbol (or URL) at point
-into the minibuffer.
-@end indentedblock
-@subsubheading @kbd{M-p} (@code{ivy-previous-history-element})
-@vindex ivy-previous-history-element
-@kindex M-p
-@indentedblock
-Cycles forward through the Ivy command history.
-@end indentedblock
-@subsubheading @kbd{M-i} (@code{ivy-insert-current})
-@vindex ivy-insert-current
-@kindex M-i
-@indentedblock
-Inserts the current candidate into the minibuffer.
-
-Useful for copying and renaming files, for example: @kbd{M-i} to
-insert the original file name string, edit it, and then @kbd{C-m} to
-complete the renaming.
-@end indentedblock
-@subsubheading @kbd{M-j} (@code{ivy-yank-word})
-@vindex ivy-yank-word
-@kindex M-j
-@indentedblock
-Inserts the sub-word at point into the minibuffer.
-
-This is similar to @kbd{C-s C-w} with @code{isearch}.  Ivy reserves @kbd{C-w}
-for @code{kill-region}.  See also @code{ivy-yank-symbol} and
-@code{ivy-yank-char}.
-@end indentedblock
-@subsubheading @kbd{S-SPC} (@code{ivy-restrict-to-matches})
-@vindex ivy-restrict-to-matches
-@kindex S-SPC
-@indentedblock
-Deletes the current input, and resets the candidates list to the
-currently restricted matches.
-
-This is how Ivy provides narrowing in successive tiers.
-@end indentedblock
-@subsubheading @kbd{C-r} (@code{ivy-reverse-i-search})
-@vindex ivy-reverse-i-search
-@kindex C-r
-@indentedblock
-Starts a recursive completion session through the command's
-history.
-
-This works just like @kbd{C-r} at the bash command prompt, where the
-completion candidates are the history items. Upon completion, the
-selected candidate string is inserted into the minibuffer.
-@end indentedblock
-
-@node Other key bindings
-@subsection Other key bindings
-
-@subsubheading @kbd{M-w} (@code{ivy-kill-ring-save})
-@vindex ivy-kill-ring-save
-@kindex M-w
-@indentedblock
-Copies selected candidates to the kill ring.
-
-Copies the region if the region is active.
-@end indentedblock
-
-@node Hydra in the minibuffer
-@subsection Hydra in the minibuffer
-
-@subsubheading @kbd{C-o} (@code{hydra-ivy/body})
-@kindex C-o
-@indentedblock
-Invokes the hydra menu with short key bindings.
-@end indentedblock
-
-When Hydra is active, minibuffer editing is disabled and menus
-display short aliases:
-
-@multitable {aaaaa} {aaaaaaaaa} {aaaaaaaaaaaaaaaaaaaaaaaaa}
-@headitem Short
-@tab Normal
-@tab Command name
-@item @kbd{o}
-@tab @kbd{C-g}
-@tab @code{keyboard-escape-quit}
-@item @kbd{j}
-@tab @kbd{C-n}
-@tab @code{ivy-next-line}
-@item @kbd{k}
-@tab @kbd{C-p}
-@tab @code{ivy-previous-line}
-@item @kbd{h}
-@tab @kbd{M-<}
-@tab @code{ivy-beginning-of-buffer}
-@item @kbd{l}
-@tab @kbd{M->}
-@tab @code{ivy-end-of-buffer}
-@item @kbd{d}
-@tab @kbd{C-m}
-@tab @code{ivy-done}
-@item @kbd{f}
-@tab @kbd{C-j}
-@tab @code{ivy-alt-done}
-@item @kbd{g}
-@tab @kbd{C-M-m}
-@tab @code{ivy-call}
-@item @kbd{u}
-@tab @kbd{C-c C-o}
-@tab @code{ivy-occur}
-@end multitable
-
-Hydra reduces key strokes, for example: @kbd{C-n C-n C-n C-n} is @kbd{C-o
-jjjj} in Hydra.
-
-Hydra menu offers these additional bindings:
-
-@subsubheading @kbd{c} (@code{ivy-toggle-calling})
-@vindex ivy-toggle-calling
-@kindex c
-@indentedblock
-Toggle calling the action after each candidate change. It
-modifies @kbd{j} to @kbd{jg}, @kbd{k} to @kbd{kg} etc.
-@end indentedblock
-@subsubheading @kbd{m} (@code{ivy-rotate-preferred-builders})
-@vindex ivy-rotate-preferred-builders
-@kindex m
-@indentedblock
-Rotate the current regexp matcher.
-@end indentedblock
-@subsubheading @kbd{>} (@code{ivy-minibuffer-grow})
-@vindex ivy-minibuffer-grow
-@kindex >
-@indentedblock
-Increase @code{ivy-height} for the current minibuffer.
-@end indentedblock
-@subsubheading @kbd{<} (@code{ivy-minibuffer-shrink})
-@vindex ivy-minibuffer-shrink
-@kindex <
-@indentedblock
-Decrease @code{ivy-height} for the current minibuffer.
-@end indentedblock
-@subsubheading @kbd{w} (@code{ivy-prev-action})
-@vindex ivy-prev-action
-@kindex w
-@indentedblock
-Select the previous action.
-@end indentedblock
-@subsubheading @kbd{s} (@code{ivy-next-action})
-@vindex ivy-next-action
-@kindex s
-@indentedblock
-Select the next action.
-@end indentedblock
-@subsubheading @kbd{a} (@code{ivy-read-action})
-@vindex ivy-read-action
-@kindex a
-@indentedblock
-Use a menu to select an action.
-@end indentedblock
-@subsubheading @kbd{C} (@code{ivy-toggle-case-fold})
-@vindex ivy-toggle-case-fold
-@kindex C
-@indentedblock
-Toggle case folding (match both upper and lower case
-characters for lower case input).
-@end indentedblock
-
-@node Saving the current completion session to a buffer
-@subsection Saving the current completion session to a buffer
-
-@subsubheading @kbd{C-c C-o} (@code{ivy-occur})
-@vindex ivy-occur
-@kindex C-c C-o
-@indentedblock
-Saves the current candidates to a new buffer and exits
-completion.
-@end indentedblock
-
-The new buffer is read-only and has a few useful bindings defined.
-
-@subsubheading @kbd{RET} or @kbd{f} (@code{ivy-occur-press})
-@vindex ivy-occur-press
-@kindex RET
-@kindex f
-@indentedblock
-Call the current action on the selected candidate.
-@end indentedblock
-@subsubheading @kbd{mouse-1} (@code{ivy-occur-click})
-@vindex ivy-occur-click
-@kindex mouse-1
-@indentedblock
-Call the current action on the selected candidate.
-@end indentedblock
-@subsubheading @kbd{j} (@code{next-line})
-@kindex j
-@indentedblock
-Move to next line.
-@end indentedblock
-@subsubheading @kbd{k} (@code{previous-line})
-@kindex k
-@indentedblock
-Move to previous line.
-@end indentedblock
-@subsubheading @kbd{a} (@code{ivy-occur-read-action})
-@vindex ivy-occur-read-action
-@kindex a
-@indentedblock
-Read an action and make it current for this buffer.
-@end indentedblock
-@subsubheading @kbd{o} (@code{ivy-occur-dispatch})
-@vindex ivy-occur-dispatch
-@kindex o
-@indentedblock
-Read an action and call it on the selected candidate.
-@end indentedblock
-@subsubheading @kbd{q} (@code{quit-window})
-@kindex q
-@indentedblock
-Bury the current buffer.
-@end indentedblock
-
-
-Ivy has no limit on the number of active buffers like these.
-
-Ivy takes care of naming buffers uniquely by constructing descriptive
-names. For example: @code{*ivy-occur counsel-describe-variable
-"function$*}.
-
-@node Completion Styles
-@chapter Completion Styles
-
-Ivy's completion functions rely on a regex builder - a function that
-transforms a string input to a string regex. All current candidates
-simply have to match this regex. Each collection can be assigned its
-own regex builder by customizing @code{ivy-re-builders-alist}.
-
-The keys of this alist are collection names, and the values are one of
-the following:
-@itemize
-@item
-@code{ivy--regex}
-@item
-@code{ivy--regex-plus}
-@item
-@code{ivy--regex-ignore-order}
-@item
-@code{ivy--regex-fuzzy}
-@item
-@code{regexp-quote}
-@end itemize
-
-A catch-all key, @code{t}, applies to all collections that don't have their
-own key.
-
-The default is:
-
-@lisp
-(setq ivy-re-builders-alist
-      '((t . ivy--regex-plus)))
-@end lisp
-
-This example shows a custom regex builder assigned to file name
-completion:
-
-@lisp
-(setq ivy-re-builders-alist
-      '((read-file-name-internal . ivy--regex-fuzzy)
-       (t . ivy--regex-plus)))
-@end lisp
-
-Here, @code{read-file-name-internal} is a function that is passed as the
-second argument to @code{completing-read} for file name completion.
-
-The regex builder resolves as follows (in order of priority):
-@enumerate
-@item
-@code{re-builder} argument passed to @code{ivy-read}.
-@item
-@code{collection} argument passed to @code{ivy-read} is a function and has an
-entry on @code{ivy-re-builders-alist}.
-@item
-@code{caller} argument passed to @code{ivy-read} has an entry on
-@code{ivy-re-builders-alist}.
-@item
-@code{this-command} has an entry on @code{ivy-re-builders-alist}.
-@item
-@code{t} has an entry on @code{ivy-re-builders-alist}.
-@item
-@code{ivy--regex}.
-@end enumerate
-
-@menu
-* ivy--regex-plus::
-* ivy--regex-ignore-order::
-* ivy--regex-fuzzy::
-@end menu
-
-@node ivy--regex-plus
-@section ivy--regex-plus
-
-@code{ivy--regex-plus} is Ivy's default completion method.
-
-@code{ivy--regex-plus} matches by splitting the input by spaces and
-rebuilding it into a regex.
-
-As the search string is typed in Ivy's minibuffer, it is transformed
-into valid regex syntax. If the string is @code{"for example"}, it is
-transformed into
-
-@lisp
-"\\(for\\).*\\(example\\)"
-@end lisp
-
-which in regex terminology matches @code{"for"} followed by a wild card and
-then @code{"example"}. Note how Ivy uses the space character to build wild
-cards. To match a literal white space, use an extra space. So to match
-one space type two spaces, to match two spaces type three spaces, and
-so on.
-
-As Ivy transforms typed characters into regex strings, it provides an
-intuitive feedback through font highlights.
-
-Ivy supports regexp negation with @code{"!"}.
-For example, @code{"define key ! ivy quit"} first selects everything
-matching @code{"define.*key"}, then removes everything matching @code{"ivy"},
-and finally removes everything matching @code{"quit"}. What remains is the
-final result set of the negation regexp.
-
-Since Ivy treats minibuffer input as a regexp, the standard regexp
-identifiers work: @code{"^"}, @code{"$"}, @code{"\b"} or @code{"[a-z]"}. The 
exceptions
-are spaces, which translate to @code{".*"}, and @code{"!"} that signal the
-beginning of a negation group.
-
-@node ivy--regex-ignore-order
-@section ivy--regex-ignore-order
-
-@code{ivy--regex-ignore-order} ignores the order of regexp tokens when
-searching for matching candidates. For instance, the input
-@code{"for example"} will match @code{"example test for"}.
-
-@node ivy--regex-fuzzy
-@section ivy--regex-fuzzy
-
-@code{ivy--regex-fuzzy} splits each character with a wild card. Searching
-for @code{"for"} returns all @code{"f.*o.*r"} matches, resulting in a large
-number of hits.  Yet some searches need these extra hits. Ivy sorts
-such large lists using @code{flx} package's scoring mechanism, if it's
-installed.
-
-@kbd{C-o m} toggles the current regexp builder.
-
-@node Customization
-@chapter Customization
-
-@menu
-* Faces::
-* Defcustoms::
-* Actions::
-* Packages::
-@end menu
-
-@node Faces
-@section Faces
-
-@subsubheading @code{ivy-current-match}
-@vindex ivy-current-match
-@indentedblock
-Highlights the currently selected candidate.
-@end indentedblock
-@subsubheading @code{ivy-minibuffer-match-face-1}
-@vindex ivy-minibuffer-match-face-1
-@indentedblock
-Highlights the background of the match.
-@end indentedblock
-@subsubheading @code{ivy-minibuffer-match-face-2}
-@vindex ivy-minibuffer-match-face-2
-@indentedblock
-Highlights the first (modulo 3) matched group.
-@end indentedblock
-@subsubheading @code{ivy-minibuffer-match-face-3}
-@vindex ivy-minibuffer-match-face-3
-@indentedblock
-Highlights the second (modulo 3) matched group.
-@end indentedblock
-@subsubheading @code{ivy-minibuffer-match-face-4}
-@vindex ivy-minibuffer-match-face-4
-@indentedblock
-Highlights the third (modulo 3) matched group.
-@end indentedblock
-@subsubheading @code{ivy-confirm-face}
-@vindex ivy-confirm-face
-@indentedblock
-Highlights the "(confirm)" part of the prompt.
-
-When @code{confirm-nonexistent-file-or-buffer} set to @code{t}, then
-confirming non-existent files in @code{ivy-mode} requires an
-additional @kbd{RET}.
-
-The confirmation prompt will use this face.
-
-For example:
-
-@lisp
-(setq confirm-nonexistent-file-or-buffer t)
-@end lisp
-
-Then call @code{find-file}, enter "eldorado" and press @kbd{RET} - the
-prompt will be appended with "(confirm)". Press @kbd{RET} once more
-to confirm, or any key to continue the completion.
-@end indentedblock
-@subsubheading @code{ivy-match-required-face}
-@vindex ivy-match-required-face
-@indentedblock
-Highlights the "(match required)" part of the prompt.
-
-When completions have to match available candidates and cannot
-take random input, the "(match required)" prompt signals this
-constraint.
-
-For example, call @code{describe-variable}, enter "waldo" and press
-@kbd{RET} - "(match required)" is prompted.
-Press any key for the prompt to disappear.
-@end indentedblock
-@subsubheading @code{ivy-subdir}
-@vindex ivy-subdir
-@indentedblock
-Highlights directories when completing file names.
-@end indentedblock
-@subsubheading @code{ivy-remote}
-@vindex ivy-remote
-@indentedblock
-Highlights remote files when completing file names.
-@end indentedblock
-@subsubheading @code{ivy-virtual}
-@vindex ivy-virtual
-@indentedblock
-Highlights virtual buffers when completing buffer names.
-
-Virtual buffers correspond to bookmarks and recent files list,
-@code{recentf}.
-
-Enable virtual buffers with:
-
-@lisp
-(setq ivy-use-virtual-buffers t)
-@end lisp
-@end indentedblock
-
-@node Defcustoms
-@section Defcustoms
-
-@defopt ivy-count-format
-A string that specifies display of number of candidates and
-current candidate, if one exists.
-
-The number of matching candidates by default is shown as a right-
-padded integer value.
-
-To disable showing the number of candidates:
-
-@lisp
-(setq ivy-count-format "")
-@end lisp
-
-To also display the current candidate:
-
-@lisp
-(setq ivy-count-format "(%d/%d) ")
-@end lisp
-
-The @code{format}-style switches this variable uses are described
-in the @code{format} documentation.
-@end defopt
-
-@defopt ivy-display-style
-Specifies highlighting candidates in the minibuffer.
-
-The default setting is @code{'fancy} in Emacs versions 24.4 or newer.
-
-Set @code{ivy-display-style} to @code{nil} for a plain minibuffer.
-@end defopt
-
-@defopt ivy-on-del-error-function
-Specifies what to do when @kbd{DEL} (@code{ivy-backward-delete-char}) fails.
-
-This is usually the case when there is no text left to delete,
-i.e., when @kbd{DEL} is typed at the beginning of the minibuffer.
-
-The default behavior is to quit the completion after @kbd{DEL} -- a
-handy key to invoke after mistakenly triggering a completion.
-@end defopt
-
-@node Actions
-@section Actions
-
-@menu
-* What are actions?::
-* How can different actions be called?::
-* How to modify the actions list?::
-* Example - add two actions to each command::
-* Example - define a new command with several actions::
-@end menu
-
-@node What are actions?
-@subsection What are actions?
-
-An action is a function that is called after you select a candidate
-during completion. This function takes a single string argument, which
-is the selected candidate.
-
-@subsubheading Window context when calling an action
-@indentedblock
-Currently, the action is executed in the minibuffer window
-context. This means e.g. that if you call @code{insert} the text will
-be inserted into the minibuffer.
-
-If you want to execute the action in the initial window from
-which the completion started, use the @code{with-ivy-window} wrapper
-macro.
-
-@lisp
-(defun ivy-insert-action (x)
-  (with-ivy-window
-    (insert x)))
-@end lisp
-@end indentedblock
-
-@node How can different actions be called?
-@subsection How can different actions be called?
-
-@itemize
-@item
-@kbd{C-m} (@code{ivy-done}) calls the current action.
-@item
-@kbd{M-o} (@code{ivy-dispatching-done}) presents available actions for
-selection, calls it after selection, and then exits.
-@item
-@kbd{C-M-o} (@code{ivy-dispatching-call}) presents available actions for
-selection, calls it after selection, and then does not exit.
-@end itemize
-
-@node How to modify the actions list?
-@subsection How to modify the actions list?
-
-Currently, you can append any amount of your own actions to the
-default list of actions. This can be done either for a specific
-command, or for all commands at once.
-
-Usually, the command has only one default action. The convention is to
-use single letters when selecting a command, and the letter @kbd{o} is
-designated for the default command. This way, @kbd{M-o o} should be always
-equivalent to @kbd{C-m}.
-
-@node Example - add two actions to each command
-@subsection Example - add two actions to each command
-
-The first action inserts the current candidate into the Ivy window -
-the window from which @code{ivy-read} was called.
-
-The second action copies the current candidate to the kill ring.
-
-@lisp
-(defun ivy-yank-action (x)
-  (kill-new x))
-
-(defun ivy-copy-to-buffer-action (x)
-  (with-ivy-window
-    (insert x)))
-
-(ivy-set-actions
- t
- '(("i" ivy-copy-to-buffer-action "insert")
-   ("y" ivy-yank-action "yank")))
-@end lisp
-
-Then in any completion session, @kbd{M-o y} invokes @code{ivy-yank-action}, and
-@kbd{M-o i} invokes @code{ivy-copy-to-buffer-action}.
-
-@menu
-* How to undo adding the two actions::
-* How to add actions to a specific command::
-@end menu
-
-@node How to undo adding the two actions
-@subsubsection How to undo adding the two actions
-
-Since @code{ivy-set-actions} modifies the internal dictionary with new
-data, set the extra actions list to @code{nil} by assigning @code{nil} value to
-the @code{t} key as follows:
-
-@lisp
-(ivy-set-actions t nil)
-@end lisp
-
-@node How to add actions to a specific command
-@subsubsection How to add actions to a specific command
-
-Use the command name as the key:
-
-@lisp
-(ivy-set-actions
- 'swiper
- '(("i" ivy-copy-to-buffer-action "insert")
-   ("y" ivy-yank-action "yank")))
-@end lisp
-
-@node Example - define a new command with several actions
-@subsection Example - define a new command with several actions
-
-@lisp
-(defun my-action-1 (x)
-  (message "action-1: %s" x))
-
-(defun my-action-2 (x)
-  (message "action-2: %s" x))
-
-(defun my-action-3 (x)
-  (message "action-3: %s" x))
-
-(defun my-command-with-3-actions ()
-  (interactive)
-  (ivy-read "test: " '("foo" "bar" "baz")
-           :action '(1
-                     ("o" my-action-1 "action 1")
-                     ("j" my-action-2 "action 2")
-                     ("k" my-action-3 "action 3"))))
-@end lisp
-
-The number 1 above is the index of the default action. Each
-action has its own string description for easy selection.
-
-@menu
-* Test the above function with @code{ivy-occur}::
-@end menu
-
-@node Test the above function with @code{ivy-occur}
-@subsubsection Test the above function with @code{ivy-occur}
-
-To examine each action with each candidate in a key-efficient way, try:
-
-@itemize
-@item
-Call @code{my-command-with-3-actions}
-@item
-Press @kbd{C-c C-o} to close the completion window and move to an
-ivy-occur buffer
-@item
-Press @kbd{kkk} to move to the first candidate, since the point is most
-likely at the end of the buffer
-@item
-Press @kbd{oo} to call the first action
-@item
-Press @kbd{oj} and @kbd{ok} to call the second and the third actions
-@item
-Press @kbd{j} to move to the next candidate
-@item
-Press @kbd{oo}, @kbd{oj}, @kbd{ok}
-@item
-Press @kbd{j} to move to the next candidate
-@item
-and so on@dots{}
-@end itemize
-
-@node Packages
-@section Packages
-
-@subsubheading @code{org-mode}
-@indentedblock
-@code{org-mode} versions 8.3.3 or later obey
-@code{completing-read-function} (which @code{ivy-mode} sets). Try refiling
-headings with similar names to appreciate @code{ivy-mode}.
-@end indentedblock
-@subsubheading @code{magit}
-@indentedblock
-Magit requires this setting for ivy completion:
-
-@lisp
-(setq magit-completing-read-function 'ivy-completing-read)
-@end lisp
-@end indentedblock
-@subsubheading @code{find-file-in-project}
-@indentedblock
-It uses ivy by default if Ivy is installed.
-@end indentedblock
-@subsubheading @code{projectile}
-@indentedblock
-Projectile requires this setting for ivy completion:
-
-@lisp
-(setq projectile-completion-system 'ivy)
-@end lisp
-@end indentedblock
-@subsubheading @code{helm-make}
-@indentedblock
-Helm-make requires this setting for ivy completion.
-
-@lisp
-(setq helm-make-completion-method 'ivy)
-@end lisp
-@end indentedblock
-
-@node Commands
-@chapter Commands
-
-@menu
-* File Name Completion::
-* Buffer Name Completion::
-* Counsel commands::
-@end menu
-
-@node File Name Completion
-@section File Name Completion
-
-Since file name completion is ubiquitous, Ivy provides extra
-bindings that work here:
-
-
-@subsubheading @kbd{C-j} (@code{ivy-alt-done})
-@vindex ivy-alt-done
-@kindex C-j
-@indentedblock
-On a directory, restarts completion from that directory.
-
-On a file or @code{./}, exit completion with the selected candidate.
-@end indentedblock
-@subsubheading @kbd{DEL} (@code{ivy-backward-delete-char})
-@vindex ivy-backward-delete-char
-@kindex DEL
-@indentedblock
-Restart the completion in the parent directory if current input
-is empty.
-@end indentedblock
-@subsubheading @kbd{//} (@code{self-insert-command})
-@kindex //
-@indentedblock
-Switch to the root directory.
-@end indentedblock
-@subsubheading @kbd{~} (@code{self-insert-command})
-@kindex ~
-@indentedblock
-Switch to the home directory.
-@end indentedblock
-@subsubheading @kbd{/} (@code{self-insert-command})
-@kindex /
-@indentedblock
-If the current input matches an existing directory name exactly,
-switch the completion to that directory.
-@end indentedblock
-@subsubheading @kbd{M-r} (@code{ivy-toggle-regexp-quote})
-@vindex ivy-toggle-regexp-quote
-@kindex M-r
-@indentedblock
-Toggle between input as regexp or not.
-
-Switch to matching literally since file names include @code{.}, which
-is for matching any char in regexp mode.
-@end indentedblock
-@defopt ivy-extra-directories
-Decide if you want to see @code{../} and @code{./} during file name
-completion.
-
-Reason to remove: @code{../} is the same as @kbd{DEL}.
-
-Reason not to remove: navigate anywhere with only @kbd{C-n}, @kbd{C-p}
-and @kbd{C-j}.
-
-Likewise, @code{./} can be removed.
-@end defopt
-
-@subsubheading History
-@indentedblock
-File history works the same with @kbd{M-p}, @kbd{M-n}, and @kbd{C-r}, but
-uses a custom code for file name completion that cycles through
-files previously opened. It also works with TRAMP files.
-@end indentedblock
-
-@menu
-* Using TRAMP::
-@end menu
-
-@node Using TRAMP
-@subsection Using TRAMP
-
-From any directory, with the empty input, inputting @code{/ssh:} and pressing
-@kbd{C-j} (or @kbd{RET}, which is the same thing) completes for host and user
-names.
-
-For @code{/ssh:user@@} input, completes the domain name.
-
-@kbd{C-i} works in a similar way to the default completion.
-
-You can also get sudo access for the current directory by inputting
-@code{/sudo::} @kbd{RET}. Using @code{/sudo:} (i.e. single colon instead of 
double) will
-result in a completion session for the desired user.
-
-Multi-hopping is possible, although a bit complex.
-
-@subsubheading Example : connect to a remote host @code{cloud} and open a file 
with @code{sudo} there
-@indentedblock
-@itemize
-@item
-@kbd{C-x C-f} @code{/ssh:cloud|sudo:root:/}.
-@end itemize
-@end indentedblock
-
-@node Buffer Name Completion
-@section Buffer Name Completion
-
-@defopt ivy-use-virtual-buffers
-When non-nil, add @code{recentf-mode} and bookmarks to
-@code{ivy-switch-buffer} completion candidates.
-
-Adding this to Emacs init file:
-
-@lisp
-(setq ivy-use-virtual-buffers t)
-@end lisp
-will add additional virtual buffers to the buffers list for recent
-files. Selecting such virtual buffers, which are highlighted with
-@code{ivy-virtual} face, will open the corresponding file.
-@end defopt
-
-@node Counsel commands
-@section Counsel commands
-
-The main advantages of @code{counsel-} functions over their basic
-equivalents in @code{ivy-mode} are:
-
-@enumerate
-@item
-Multi-actions and non-exiting actions work.
-@item
-@code{ivy-resume} can resume the last completion session.
-@item
-Customize @code{ivy-set-actions}, @code{ivy-re-builders-alist}.
-@item
-Customize individual keymaps, such as @code{counsel-describe-map},
-@code{counsel-git-grep-map}, or @code{counsel-find-file-map}, instead of
-customizing @code{ivy-minibuffer-map} that applies to all completion
-sessions.
-@end enumerate
-
-@node API
-@chapter API
-
-The main (and only) entry point is the @code{ivy-read} function. It takes
-two required arguments and many optional arguments that can be passed
-by a key. The optional @code{:action} argument is highly recommended for
-features such as multi-actions, non-exiting actions, @code{ivy-occur} and
-@code{ivy-resume}.
-
-@menu
-* Required arguments for @code{ivy-read}::
-* Optional arguments for @code{ivy-read}::
-* Example - @code{counsel-describe-function}::
-* Example - @code{counsel-locate}::
-* Example - @code{ivy-read-with-extra-properties}::
-@end menu
-
-@node Required arguments for @code{ivy-read}
-@section Required arguments for @code{ivy-read}
-
-@subsubheading @code{prompt}
-@indentedblock
-A prompt string normally ending in a colon and a space.
-@code{ivy-count-format} is prepended to it during completion.
-@end indentedblock
-@subsubheading @code{collection}
-@indentedblock
-Either a list of strings, a function, an alist or a hash table.
-
-If a function, then it has to be compatible with
-@code{all-completions}.
-@end indentedblock
-
-@node Optional arguments for @code{ivy-read}
-@section Optional arguments for @code{ivy-read}
-
-@subsubheading @code{predicate}
-@indentedblock
-Is a function to filter the initial collection. It has to be
-compatible with @code{all-completions}. Tip: most of the time, it's
-simpler to just apply this filter to the @code{collection} argument
-itself, e.g. @code{(cl-remove-if-not predicate collection)}.
-@end indentedblock
-@subsubheading @code{require-match}
-@indentedblock
-When set to a non-nil value, input must match one of the
-candidates. Custom input is not accepted.
-@end indentedblock
-@subsubheading @code{initial-input}
-@indentedblock
-This string argument is included for compatibility with
-@code{completing-read}, which inserts it into the minibuffer.
-
-It's recommended to use the @code{preselect} argument instead of this.
-@end indentedblock
-@subsubheading @code{history}
-@indentedblock
-Name of the symbol to store history. See @code{completing-read}.
-@end indentedblock
-@subsubheading @code{preselect}
-@indentedblock
-When set to a string value, select the first candidate matching
-this value.
-
-When set to an integer value, select the candidate with that
-index value.
-
-Every time the input becomes empty, the item corresponding to to
-@code{preselect} is selected.
-@end indentedblock
-@subsubheading @code{keymap}
-@indentedblock
-A keymap to be composed with @code{ivy-minibuffer-map}. This keymap
-has priority over @code{ivy-minibuffer-map} and can be modified at any
-later stage.
-@end indentedblock
-@subsubheading @code{update-fn}
-@indentedblock
-Is the function called each time the current candidate changes.
-This function takes no arguments and is called in the
-minibuffer's @code{post-command-hook}. See @code{swiper} for an example
-usage.
-@end indentedblock
-@subsubheading @code{sort}
-@indentedblock
-When non-nil, use @code{ivy-sort-functions-alist} to sort the
-collection as long as the collection is not larger than
-@code{ivy-sort-max-size}.
-@end indentedblock
-@subsubheading @code{action}
-@indentedblock
-Is the function to call after selection. It takes a string
-argument.
-@end indentedblock
-@subsubheading @code{unwind}
-@indentedblock
-Is the function to call before exiting completion. It takes no
-arguments. This function is called even if the completion is
-interrupted with @kbd{C-g}. See @code{swiper} for an example usage.
-@end indentedblock
-@subsubheading @code{re-builder}
-@indentedblock
-Is a function that takes a string and returns a valid regex. See
-@code{Completion Styles} for details.
-@end indentedblock
-@subsubheading @code{matcher}
-@indentedblock
-Is a function that takes a regex string and a list of strings and
-returns a list of strings matching the regex. Any ordinary Emacs
-matching function will suffice, yet finely tuned matching
-functions can be used. See @code{counsel-find-file} for an example
-usage.
-@end indentedblock
-@subsubheading @code{dynamic-collection}
-@indentedblock
-When non-nil, @code{collection} will be used to dynamically generate
-the candidates each time the input changes, instead of being used
-once statically with @code{all-completions} to generate a list of
-strings. See @code{counsel-locate} for an example usage.
-@end indentedblock
-@subsubheading @code{caller}
-@indentedblock
-Is a symbol that uniquely identifies the function that called
-@code{ivy-read}, which may be useful for further customizations.
-@end indentedblock
-
-@node Example - @code{counsel-describe-function}
-@section Example - @code{counsel-describe-function}
-
-This is a typical example of a function with a non-async collection,
-which is a collection where all the strings in the collection are
-known prior to any input from the user.
-
-Only the first two arguments (along with @code{action}) are essential - the
-rest of the arguments are for fine-tuning, and could be omitted.
-
-The @code{action} argument could also be omitted - but then @code{ivy-read}
-would do nothing except returning the string result, which you could
-later use yourself. However, it's recommended that you use the
-@code{action} argument.
-
-@lisp
-(defun counsel-describe-function ()
-  "Forward to `describe-function'."
-  (interactive)
-  (ivy-read "Describe function: "
-           (let (cands)
-             (mapatoms
-              (lambda (x)
-                (when (fboundp x)
-                  (push (symbol-name x) cands))))
-             cands)
-           :keymap counsel-describe-map
-           :preselect (ivy-thing-at-point)
-           :history 'counsel-describe-symbol-history
-           :require-match t
-           :sort t
-           :action (lambda (x)
-                     (describe-function
-                      (intern x)))
-           :caller 'counsel-describe-function))
-@end lisp
-
-Here are the interesting features of the above function, in the order that 
they appear:
-
-@itemize
-@item
-The @code{prompt} argument is a simple string ending in ": ".
-@item
-The @code{collection} argument evaluates to a (large) list of strings.
-@item
-The @code{keymap} argument is for a custom keymap to supplement 
@code{ivy-minibuffer-map}.
-@item
-The @code{preselect} is provided by @code{ivy-thing-at-point}, which
-returns a symbol near the point. Ivy then selects the first
-candidate from the collection that matches this symbol. To select
-this pre-selected candidate, a @kbd{RET} will suffice. No further user
-input is necessary.
-@item
-The @code{history} argument is for keeping the history of this command
-separate from the common history in @code{ivy-history}.
-@item
-The @code{require-match} is set to @code{t} since it doesn't make sense to
-call @code{describe-function} on an un-interned symbol.
-@item
-The @code{sort} argument is set to @code{t} so choosing between similar
-candidates becomes easier. Sometimes, the collection size will
-exceed @code{ivy-sort-max-size}, which is 30000 by default. In that case
-the sorting will not happen to avoid delays.
-
-Adjust this variable to choose between sorting time and completion
-start-up time.
-@item
-The @code{action} argument calls @code{describe-function} on the interned
-selected candidate.
-@item
-The @code{caller} argument identifies this completion session. This is
-important, since with the collection being a list of strings and not
-a function name, the only other way for @code{ivy-read} to identify
-"who's calling" and to apply the appropriate customizations is to
-examine @code{this-command}. But @code{this-command} would be modified if
-another command called @code{counsel-describe-function}.
-@end itemize
-
-@node Example - @code{counsel-locate}
-@section Example - @code{counsel-locate}
-
-This is a typical example of a function with an async collection.
-Since the collection function cannot pre-compute all the locatable
-files in memory within reasonable limits (time or memory), it relies
-on user input to filter the universe of possible candidates to a
-manageable size while also continuing to search asynchronously for
-possible candidates. Both the filtering and searching continues with
-each character change of the input with rapid updates to the
-collection presented without idle waiting times. This live update will
-continue as long as there are likely candidates. Eventually updates to
-the minibuffer will stop after user input, filtering, and searching
-have exhausted looking for possible candidates.
-
-Async collections suit long-running shell commands, such as @code{locate}.
-With each new input, a new process starts while the old process is
-killed. The collection is refreshed anew with each new process.
-Meanwhile the user can provide more input characters (for further
-narrowing) or select a candidate from the visible collection.
-
-@lisp
-(defun counsel-locate-function (str)
-  (or
-   (ivy-more-chars)
-   (progn
-     (counsel--async-command
-      (format "locate %s '%s'"
-             (mapconcat #'identity counsel-locate-options " ")
-             (counsel--elisp-to-pcre
-              (ivy--regex str))))
-     '("" "working..."))))
-
-;;;###autoload
-(defun counsel-locate (&optional initial-input)
-  "Call the \"locate\" shell command.
-INITIAL-INPUT can be given as the initial minibuffer input."
-  (interactive)
-  (ivy-read "Locate: " #'counsel-locate-function
-           :initial-input initial-input
-           :dynamic-collection t
-           :history 'counsel-locate-history
-           :action (lambda (file)
-                     (with-ivy-window
-                       (when file
-                         (find-file file))))
-           :unwind #'counsel-delete-process
-           :caller 'counsel-locate))
-@end lisp
-
-Here are the interesting features of the above functions, in the order
-that they appear:
-
-@itemize
-@item
-@code{counsel-locate-function} takes a string argument and returns a list
-of strings. Note that it's not compatible with @code{all-completions},
-but since we're not using that here, might as well use one argument
-instead of three.
-@item
-@code{ivy-more-chars} is a simple function that returns e.g.
-@code{'("2 chars more")} asking the user for more input.
-@item
-@code{counsel--async-command} is a very easy API simplification that
-takes a single string argument suitable for
-@code{shell-command-to-string}. So you could prototype your function as
-non-async using @code{shell-command-to-string} and @code{split-string} to
-produce a collection, then decide that you want async and simply swap in
-@code{counsel--async-command}.
-@item
-@code{counsel-locate} is an interactive function with an optional 
@code{initial-input}.
-@item
-@code{#'counsel-locate-function} is passed as the @code{collection} argument.
-@item
-@code{dynamic-collection} is set to t, since this is an async collection.
-@item
-@code{action} argument uses @code{with-ivy-window} wrapper, since we want to 
open the
-selected file in the same window from which @code{counsel-locate} was
-called.
-@item
-@code{unwind} argument is set to @code{#'counsel-delete-process}: when we 
press @kbd{C-g}
-we want to kill the running process created by
-@code{counsel--async-command}.
-@item
-@code{caller} argument identifies this command for easier customization.
-@end itemize
-
-@node Example - @code{ivy-read-with-extra-properties}
-@section Example - @code{ivy-read-with-extra-properties}
-
-This is another example to show how to associate additional values to each
-displayed strings.
-
-@lisp
-(defun find-candidates-function (str pred _)
-  (let ((props '(1 2))
-       (strs '("foo" "foo2")))
-    (cl-mapcar (lambda (s p) (propertize s 'property p))
-              strs
-              props)))
-
-(defun find-candidates ()
-  (interactive)
-  (ivy-read "Find symbols: "
-           #'find-candidates-function
-           :action (lambda (x)
-                     (message "Value: %s" (get-text-property 0 'property x)
-                      ))))
-@end lisp
-
-Here are the interesting features of the above function:
-
-@itemize
-@item
-@code{find-candidates-function} builds up a list of strings and associates 
"foo" with
-the value 1 and "foo2" with 2.
-@item
-@code{find-candidates} is an interactive function.
-@item
-@code{#'find-candidates} is passed as the @code{collection} argument.
-@item
-@code{action} gets passed the selected string with the associated value. It
-then retrieves that value and displays it.
-@end itemize
-
-@node Variable Index
-@unnumbered Variable Index
-
-@printindex vr
-
-@node Keystroke Index
-@unnumbered Keystroke Index
-
-@printindex ky
-
-@bye
\ No newline at end of file
diff --git a/packages/ivy/ivy-hydra.el b/packages/ivy/ivy-hydra.el
index 5b0054e..c4fa573 100644
--- a/packages/ivy/ivy-hydra.el
+++ b/packages/ivy/ivy-hydra.el
@@ -4,8 +4,8 @@
 
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.11.0
-;; Package-Requires: ((emacs "24.1") (ivy "0.11.0") (hydra "0.13.4"))
+;; Version: 0.12.0
+;; Package-Requires: ((emacs "24.1") (ivy "0.12.0") (hydra "0.13.4"))
 ;; Keywords: convenience
 
 ;; This file is part of GNU Emacs.
@@ -46,8 +46,8 @@
   "
 ^ ^ ^ ^ ^ ^ | ^Call^      ^ ^  | ^Cancel^ | ^Options^ | Action _w_/_s_/_a_: 
%-14s(ivy-action-name)
 
^-^-^-^-^-^-+-^-^---------^-^--+-^-^------+-^-^-------+-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------------
-^ ^ _k_ ^ ^ | _f_ollow occ_u_r | _i_nsert | _c_: calling %-5s(if ivy-calling 
\"on\" \"off\") _C_ase-fold: %-10`ivy-case-fold-search
-_h_ ^+^ _l_ | _d_one      ^ ^  | _o_ops   | _m_: matcher 
%-5s(ivy--matcher-desc)^^^^^^^^^^^^ _t_runcate: %-11`truncate-lines
+^ ^ _k_ ^ ^ | _f_ollow occ_U_r | _i_nsert | _c_: calling %-5s(if ivy-calling 
\"on\" \"off\") _C_ase-fold: %-10`ivy-case-fold-search
+_h_ ^+^ _l_ | _d_one      ^ ^  | _o_ops   | _M_: matcher 
%-5s(ivy--matcher-desc)^^^^^^^^^^^^ _T_runcate: %-11`truncate-lines
 ^ ^ _j_ ^ ^ | _g_o        ^ ^  | ^ ^      | _<_/_>_: 
shrink/grow^^^^^^^^^^^^^^^^^^^^^^^^^^^^ _D_efinition of this menu
 "
   ;; arrows
@@ -55,8 +55,14 @@ _h_ ^+^ _l_ | _d_one      ^ ^  | _o_ops   | _m_: matcher 
%-5s(ivy--matcher-desc)
   ("j" ivy-next-line)
   ("k" ivy-previous-line)
   ("l" ivy-end-of-buffer)
+  ;; mark
+  ("m" ivy-mark)
+  ("u" ivy-unmark)
+  ("DEL" ivy-unmark-backward)
+  ("t" ivy-toggle-marks)
   ;; actions
   ("o" keyboard-escape-quit :exit t)
+  ("r" ivy-dispatching-done-hydra :exit t)
   ("C-g" keyboard-escape-quit :exit t)
   ("i" nil)
   ("C-o" nil)
@@ -66,15 +72,15 @@ _h_ ^+^ _l_ | _d_one      ^ ^  | _o_ops   | _m_: matcher 
%-5s(ivy--matcher-desc)
   ("g" ivy-call)
   ("C-m" ivy-done :exit t)
   ("c" ivy-toggle-calling)
-  ("m" ivy-rotate-preferred-builders)
+  ("M" ivy-rotate-preferred-builders)
   (">" ivy-minibuffer-grow)
   ("<" ivy-minibuffer-shrink)
   ("w" ivy-prev-action)
   ("s" ivy-next-action)
   ("a" ivy-read-action)
-  ("t" (setq truncate-lines (not truncate-lines)))
+  ("T" (setq truncate-lines (not truncate-lines)))
   ("C" ivy-toggle-case-fold)
-  ("u" ivy-occur :exit t)
+  ("U" ivy-occur :exit t)
   ("D" (ivy-exit-with-action
         (lambda (_) (find-function 'hydra-ivy/body)))
        :exit t))
@@ -82,14 +88,24 @@ _h_ ^+^ _l_ | _d_one      ^ ^  | _o_ops   | _m_: matcher 
%-5s(ivy--matcher-desc)
 (defvar ivy-dispatching-done-columns 2
   "Number of columns to use if the hint does not fit on one line.")
 
+(defvar ivy-dispatching-done-idle nil
+  "When non-nil, the hint will be delayed by this many seconds.")
+
+(defvar ivy-dispatching-done-hydra-exit-keys '(("M-o" nil "back")
+                                               ("C-g" nil))
+  "Keys that can be used to exit `ivy-dispatching-done-hydra'.")
+
 (defun ivy-dispatching-done-hydra ()
   "Select one of the available actions and call `ivy-done'."
   (interactive)
   (let* ((actions (ivy-state-action ivy-last))
-         (estimated-len (+ 25 (length
-                               (mapconcat
-                                (lambda (x) (format "[%s] %s" (nth 0 x) (nth 2 
x)))
-                                (cdr actions) ", "))))
+         (extra-actions ivy-dispatching-done-hydra-exit-keys)
+         (doc (concat "action: "
+                      (mapconcat
+                       (lambda (x) (format "[%s] %s" (nth 0 x) (nth 2 x)))
+                       (append (cdr actions)
+                               extra-actions) ", ")))
+         (estimated-len (length doc))
          (n-columns (if (> estimated-len (window-width))
                         ivy-dispatching-done-columns
                       nil)))
@@ -97,7 +113,7 @@ _h_ ^+^ _l_ | _d_one      ^ ^  | _o_ops   | _m_: matcher 
%-5s(ivy--matcher-desc)
         (ivy-done)
       (funcall
        (eval
-        `(defhydra ivy-read-action (:color teal :columns ,n-columns)
+        `(defhydra ivy-read-action (:color teal :columns ,n-columns :idle 
,ivy-dispatching-done-idle)
            "action"
            ,@(mapcar (lambda (x)
                        (list (nth 0 x)
@@ -106,8 +122,7 @@ _h_ ^+^ _l_ | _d_one      ^ ^  | _o_ops   | _m_: matcher 
%-5s(ivy--matcher-desc)
                                 (ivy-done))
                              (nth 2 x)))
                      (cdr actions))
-           ("M-o" nil "back")
-           ("C-g" nil)))))))
+           ,@extra-actions))))))
 
 (define-key ivy-minibuffer-map (kbd "M-o") 'ivy-dispatching-done-hydra)
 
diff --git a/packages/ivy/ivy-overlay.el b/packages/ivy/ivy-overlay.el
index 5a2e5e7..7f56c6e 100644
--- a/packages/ivy/ivy-overlay.el
+++ b/packages/ivy/ivy-overlay.el
@@ -27,8 +27,10 @@
 ;;; Code:
 
 (defface ivy-cursor
-  '((t (:background "black"
-        :foreground "white")))
+  '((((class color) (background light))
+     :background "black" :foreground "white")
+    (((class color) (background dark))
+     :background "white" :foreground "black"))
   "Cursor face for inline completion."
   :group 'ivy-faces)
 
@@ -77,6 +79,7 @@ Then attach the overlay to the character before point."
   (overlay-put ivy-overlay-at 'after-string ""))
 
 (declare-function org-current-level "org")
+(declare-function org-at-heading-p "org")
 (defvar org-indent-indentation-per-level)
 (defvar ivy-height)
 (defvar ivy-last)
@@ -88,16 +91,14 @@ Then attach the overlay to the character before point."
 (declare-function ivy-state-window "ivy")
 (declare-function ivy--remove-prefix "ivy")
 
-(defun ivy-overlay-impossible-p (str)
+(defun ivy-overlay-impossible-p (_str)
   (or
    (and (eq major-mode 'org-mode)
         (plist-get (text-properties-at (point)) 'src-block))
    (<= (window-height) (+ ivy-height 3))
    (= (point) (point-min))
    (< (- (+ (window-width) (window-hscroll)) (current-column))
-      (apply #'max
-             (mapcar #'string-width
-                     (split-string str "\n"))))))
+      30)))
 
 (defun ivy-display-function-overlay (str)
   "Called from the minibuffer, display STR in an overlay in Ivy window.
@@ -111,35 +112,37 @@ Hide the minibuffer contents and cursor."
           (insert str)))
     (ivy-add-face-text-property (minibuffer-prompt-end) (point-max)
                                 '(:foreground "white"))
-    (let ((cursor-pos (1+ (- (point) (minibuffer-prompt-end))))
-          (ivy-window (ivy--get-window ivy-last)))
+    (setq cursor-type nil)
+    (with-selected-window (ivy--get-window ivy-last)
+      (when cursor-type
+        (setq ivy--old-cursor-type cursor-type))
       (setq cursor-type nil)
-      (with-selected-window ivy-window
-        (when cursor-type
-          (setq ivy--old-cursor-type cursor-type))
-        (setq cursor-type nil)
-        (let ((overlay-str
-               (apply
-                #'concat
-                (buffer-substring (max (point-min) (1- (point))) (point))
-                ivy-text
-                (and (eolp) " ")
-                (buffer-substring (point) (line-end-position))
-                (and (> (length str) 0)
-                     (list "\n"
-                           (ivy-left-pad
-                            (ivy--remove-prefix "\n" str)
-                            (+ (if (and (eq major-mode 'org-mode)
-                                        (bound-and-true-p org-indent-mode))
-                                   (* org-indent-indentation-per-level
-                                      (org-current-level))
-                                 0)
-                               (save-excursion
-                                 (goto-char ivy-completion-beg)
-                                 (current-column)))))))))
-          (ivy-add-face-text-property cursor-pos (1+ cursor-pos)
-                                      'ivy-cursor overlay-str t)
-          (ivy-overlay-show-after overlay-str))))))
+      (let ((overlay-str
+             (apply
+              #'concat
+              (buffer-substring (max (point-min) (1- (point))) (point))
+              ivy-text
+              (and (eolp) " ")
+              (buffer-substring (point) (line-end-position))
+              (and (> (length str) 0)
+                   (list "\n"
+                         (ivy-left-pad
+                          (ivy--remove-prefix "\n" str)
+                          (+
+                           (if (and (eq major-mode 'org-mode)
+                                    (bound-and-true-p org-indent-mode))
+                               (if (org-at-heading-p)
+                                   (1- (org-current-level))
+                                 (* org-indent-indentation-per-level 
(org-current-level)))
+                             0)
+                           (save-excursion
+                             (when ivy-completion-beg
+                               (goto-char ivy-completion-beg))
+                             (current-column)))))))))
+        (let ((cursor-offset (1+ (length ivy-text))))
+          (ivy-add-face-text-property cursor-offset (1+ cursor-offset)
+                                      'ivy-cursor overlay-str t))
+        (ivy-overlay-show-after overlay-str)))))
 
 (provide 'ivy-overlay)
 
diff --git a/packages/ivy/ivy-test.el b/packages/ivy/ivy-test.el
index 7fc34be..386fe9c 100644
--- a/packages/ivy/ivy-test.el
+++ b/packages/ivy/ivy-test.el
@@ -35,6 +35,8 @@
 (require 'ivy)
 (require 'counsel)
 
+(message "%s" (emacs-version))
+
 (defvar ivy-expr nil
   "Holds a test expression to evaluate with `ivy-eval'.")
 
@@ -48,12 +50,21 @@
 
 (global-set-key (kbd "C-c e") 'ivy-eval)
 
-(defun ivy-with (expr keys)
+(cl-defun ivy-with (expr keys &key dir)
   "Evaluate EXPR followed by KEYS."
-  (let ((ivy-expr expr))
-    (execute-kbd-macro
-     (vconcat (kbd "C-c e")
-              (kbd keys)))
+  (let ((ivy-expr expr)
+        (inhibit-message t)
+        (buf (current-buffer)))
+    (save-window-excursion
+      (unwind-protect
+           (progn
+             ;; `execute-kbd-macro' doesn't pick up `default-directory'
+             (when dir
+               (dired (expand-file-name dir (counsel-locate-git-root))))
+             (execute-kbd-macro
+              (vconcat (kbd "C-c e")
+                       (kbd keys))))
+        (switch-to-buffer buf)))
     ivy-result))
 
 (defun command-execute-setting-this-command (cmd &rest args)
@@ -172,6 +183,15 @@ will bring the behavior in line with the newer Emacsen."
   (should (string= (swiper--re-builder "^a b")
                    "^ \\(a\\).*?\\(b\\)")))
 
+(ert-deftest swiper--re-builder-char-fold ()
+  :expected-result (if (>= emacs-major-version 25)
+                       :passed
+                     :failed)
+  (let ((search-default-mode 'char-fold-to-regexp))
+    (should (string= (swiper--re-builder "f b")
+                     
"\\(\\(?:ḟ\\|[fᶠḟⓕf𝐟𝑓𝒇𝒻𝓯𝔣𝕗𝖋𝖿𝗳𝘧𝙛𝚏]\\)\\).*?\\(\\(?:b[̣̱̇]\\|[bᵇḃḅḇⓑb𝐛𝑏𝒃𝒷𝓫𝔟𝕓𝖇𝖻𝗯𝘣𝙗𝚋]\\)\\)"))
+    (should (= ivy--subexps 2))))
+
 (ert-deftest ivy--split ()
   (should (equal (ivy--split "King of the who?")
                  '("King" "of" "the" "who?")))
@@ -196,7 +216,10 @@ will bring the behavior in line with the newer Emacsen."
                  
"\\(\\(?:interactive\\|swiper\\)\\).*?\\(\\(?:list\\|symbol\\)\\)"))
   (should (equal (ivy--regex
                   "foo[")
-                 "foo\\[")))
+                 "foo\\["))
+  (should (equal (ivy--regex
+                  ".org")
+                 "\\.org")))
 
 (ert-deftest ivy--split-negation ()
   (should (equal (ivy--split-negation "") ()))
@@ -253,13 +276,13 @@ will bring the behavior in line with the newer Emacsen."
 
 (ert-deftest ivy--regex-fuzzy ()
   (should (string= (ivy--regex-fuzzy "tmux")
-                   "\\(t\\)[^m]*\\(m\\)[^u]*\\(u\\)[^x]*\\(x\\)"))
+                   "\\(t\\)[^m\n]*\\(m\\)[^u\n]*\\(u\\)[^x\n]*\\(x\\)"))
   (should (string= (ivy--regex-fuzzy ".tmux")
-                   
"\\(\\.\\)[^t]*\\(t\\)[^m]*\\(m\\)[^u]*\\(u\\)[^x]*\\(x\\)"))
+                   
"\\(\\.\\)[^t\n]*\\(t\\)[^m\n]*\\(m\\)[^u\n]*\\(u\\)[^x\n]*\\(x\\)"))
   (should (string= (ivy--regex-fuzzy "^tmux")
-                   "^\\(t\\)[^m]*\\(m\\)[^u]*\\(u\\)[^x]*\\(x\\)"))
+                   "^\\(t\\)[^m\n]*\\(m\\)[^u\n]*\\(u\\)[^x\n]*\\(x\\)"))
   (should (string= (ivy--regex-fuzzy "^tmux$")
-                   "^\\(t\\)[^m]*\\(m\\)[^u]*\\(u\\)[^x]*\\(x\\)$"))
+                   "^\\(t\\)[^m\n]*\\(m\\)[^u\n]*\\(u\\)[^x\n]*\\(x\\)$"))
   (should (string= (ivy--regex-fuzzy "")
                    ""))
   (should (string= (ivy--regex-fuzzy "^")
@@ -301,7 +324,8 @@ will bring the behavior in line with the newer Emacsen."
 
 (ert-deftest ivy--format ()
   (should (string= (let ((ivy--index 10)
-                         (ivy-format-function (lambda (x) (mapconcat 
#'identity x "\n")))
+                         (ivy-format-functions-alist
+                          '((t . (lambda (x) (mapconcat #'identity x "\n")))))
                          (cands '("NAME"
                                   "SYNOPSIS"
                                   "DESCRIPTION"
@@ -344,7 +368,16 @@ will bring the behavior in line with the newer Emacsen."
                  "bar.*baz"))
   (should (equal (counsel--elisp-to-pcre
                   '(("foo\\|bar" . t) ("blah\\|bloop") ("blick" . t) 
("\\(baz\\)\\|quux" . t)))
-                 "(?:foo|bar).*blick.*(?:(baz)|quux)")))
+                 "(?:foo|bar).*blick.*(?:(baz)|quux)"))
+  (should (equal (counsel--elisp-to-pcre
+                  '(("ivy" . t) ("-")) t)
+                 "^(?=.*ivy)(?!.*-)"))
+  (should (equal (counsel--elisp-to-pcre
+                  '(("foo" . t)) t)
+                 "foo"))
+  (should (equal (counsel--elisp-to-pcre
+                  '(("foo")) t)
+                 "^(?!.*foo)")))
 
 (defmacro ivy--string-buffer (text &rest body)
   "Test helper that wraps TEXT in a temp buffer while running BODY."
@@ -690,8 +723,9 @@ will bring the behavior in line with the newer Emacsen."
        (switch-to-buffer standard-output t)
        ,expr
        (ivy-mode)
-       (execute-kbd-macro
-        ,(apply #'vconcat (mapcar #'kbd keys))))))
+       (let ((inhibit-message t))
+         (execute-kbd-macro
+          ,(apply #'vconcat (mapcar #'kbd keys)))))))
 
 (ert-deftest ivy-completion-in-region ()
   (should (string=
@@ -937,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 ()
@@ -979,6 +1020,294 @@ a buffer visiting a file."
         (should (equal out expected))
         (should (equal match-data-orig (match-data)))))))
 
+(ert-deftest counsel--grep-regex ()
+  ;; negative lookahead: lines with "ivy", without "-"
+  (should
+   (string=
+    (let ((counsel--regex-look-around t)
+          (ivy--regex-function 'ivy--regex-plus))
+      (counsel--grep-regex "ivy ! -"))
+    "^(?=.*ivy)(?!.*-)"))
+  (should
+   (string=
+    (let ((counsel--regex-look-around t)
+          (ivy--regex-function 'ivy--regex-fuzzy))
+      (counsel--grep-regex "ivy"))
+    "(i)[^v\n]*(v)[^y\n]*(y)")))
+
+(defmacro ivy-with-text (text &rest body)
+  (let ((old-bindings
+         (delq nil (mapcar
+                    (lambda (x)
+                      (when (and (listp x)
+                                 (eq (car x) 'global-set-key))
+                        (let ((key (eval (cadr x))))
+                          (list key (lookup-key global-map key)))))
+                    body))))
+    `(let ((temp-buffer (generate-new-buffer " *temp*")))
+       (save-window-excursion
+         (unwind-protect
+              (progn
+                (switch-to-buffer temp-buffer)
+                (insert ,text)
+                (search-backward "|")
+                (delete-char 1)
+                (setq current-prefix-arg nil)
+                (let ((inhibit-message t))
+                  ,@(mapcar (lambda (x)
+                              (if (and (listp x)
+                                       (stringp (car x)))
+                                  `(execute-kbd-macro
+                                    (vconcat ,@(mapcar #'kbd x)))
+                                x))
+                            body))
+                (insert "|")
+                (buffer-substring-no-properties
+                 (point-min)
+                 (point-max)))
+           (dolist (old-binding ',old-bindings)
+             (apply #'global-set-key old-binding))
+           (and (buffer-name temp-buffer)
+                (kill-buffer temp-buffer)))))))
+
+(ert-deftest swiper-isearch ()
+  (should
+   (string=
+    (ivy-with-text
+     "abc\na|sdf123 def\ndem"
+     (global-set-key (kbd "C-s") #'isearch-forward-regexp)
+     ("C-s" "de" "" "RET"))
+    "abc\nasd|f123 def\ndem"))
+  (should
+   (string=
+    (ivy-with-text
+     "abc\na|sdf123 def\ndem"
+     (global-set-key (kbd "C-s") #'swiper-isearch)
+     ("C-s" "de" "" "RET"))
+    "abc\nasd|f123 def\ndem"))
+  (should
+   (string=
+    (ivy-with-text
+     "|(defun foo)\nasdf\n(defvar bar)"
+     (global-set-key (kbd "C-s") #'isearch-forward-regexp)
+     ("C-s" "defun\\|defvar" "RET"))
+    "(defun| foo)\nasdf\n(defvar bar)"))
+  (should
+   (string=
+    (ivy-with-text
+     "|(defun foo)\nasdf\n(defvar bar)"
+     (global-set-key (kbd "C-s") #'swiper-isearch)
+     ("C-s" "defun\\|defvar" "RET"))
+    "(defun| foo)\nasdf\n(defvar bar)"))
+  (should
+   (string=
+    (ivy-with-text
+     "|(defun foo)\nasdf\n(defvar bar)"
+     (global-set-key (kbd "C-s") #'swiper-isearch)
+     ("C-s" "defun\\|defvar" "C-n RET"))
+    "(defun foo)\nasdf\n(defvar| bar)")))
+
+(ert-deftest swiper-isearch-backward ()
+  (should
+   (string=
+    (ivy-with-text
+     "abc\nasdf123 def\ndem|"
+     (global-set-key (kbd "C-r") #'isearch-backward-regexp)
+     ("C-r" "de" "" "RET"))
+    "abc\nasdf123 def\n|dem"))
+  (should
+   (string=
+    (ivy-with-text
+     "abc\nasdf123 def\ndem|"
+     (global-set-key (kbd "C-r") #'swiper-isearch-backward)
+     ("C-r" "de" "" "RET"))
+    "abc\nasdf123 def\n|dem"))
+  (should
+   (string=
+    (ivy-with-text
+     "(defun foo)\nasdf\n(defvar bar)|"
+     (global-set-key (kbd "C-r") #'isearch-backward-regexp)
+     ("C-r" "defun\\|defvar" "RET"))
+    "(defun foo)\nasdf\n(|defvar bar)"))
+  ;; NOTE: The following two behaviors do not match
+  ;; `isearch-backward-regexp', but they match that of
+  ;; `swiper-isearch-forward', as `swiper-isearch' does not reset the
+  ;; point when the regexp becomes invalid, meaning the point is left
+  ;; at the initial match of the first part of the regexp.
+  (should
+   (string=
+    (ivy-with-text
+     "(defun foo)\nasdf\n(defvar bar)|"
+     (global-set-key (kbd "C-r") #'swiper-isearch-backward)
+     ("C-r" "defun\\|defvar" "RET"))
+    "(|defun foo)\nasdf\n(defvar bar)"))
+  (should
+   (string=
+    (ivy-with-text
+     "(defun foo)\nasdf\n(defvar bar)|"
+     (global-set-key (kbd "C-r") #'swiper-isearch-backward)
+     ("C-r" "defun\\|defvar" "C-n RET"))
+    "(defun foo)\nasdf\n(|defvar bar)"))
+  (should
+   (string=
+    (ivy-with-text
+     "(defun foo)\nasdf\n(|defun bar)"
+     (global-set-key (kbd "C-r") #'isearch-backward)
+     ("C-r" "defun" "RET"))
+    "(|defun foo)\nasdf\n(defun bar)"))
+  (should
+   (string=
+    (ivy-with-text
+     "(defun foo)\nasdf\n(|defun bar)"
+     (global-set-key (kbd "C-r") #'swiper-isearch-backward)
+     ("C-r" "defun" "RET"))
+    "(|defun foo)\nasdf\n(defun bar)")))
+
+(ert-deftest swiper-isearch-backward-backspace ()
+  (should
+   (string=
+    (ivy-with-text
+     "(while (when |))"
+     (global-set-key (kbd "C-r") #'swiper-isearch-backward)
+     ("C-r" "whi" "" "RET"))
+    "(while (|when ))"))
+  (should
+   (string=
+    (ivy-with-text
+     "(while (when |))"
+     (global-set-key (kbd "C-r") #'isearch-backward-regexp)
+     ("C-r" "whi" "" "RET"))
+    "(while (|when ))")))
+
+(ert-deftest swiper-isearch-case-fold ()
+  (should
+   (string=
+    (ivy-with-text
+     "|Foo\nfoo\nFOO\n"
+     (global-set-key (kbd "C-s") #'swiper-isearch)
+     ("C-s" "foo" "C-n RET"))
+    "Foo\nfoo|\nFOO\n"))
+  (should
+   (string=
+    (let ((ivy-case-fold-search-default 'auto))
+      (ivy-with-text
+       "|Foo\nfoo\nFOO\n"
+       (global-set-key (kbd "C-s") #'swiper-isearch)
+       ("C-s" "Foo" "C-n RET")))
+    "Foo|\nfoo\nFOO\n"))
+  (should
+   (string=
+    (let ((ivy-case-fold-search-default t))
+      (ivy-with-text
+       "|Foo\nfoo\nFOO\n"
+       (global-set-key (kbd "C-s") #'swiper-isearch)
+       ("C-s" "Foo" "C-n RET")))
+    "Foo\nfoo|\nFOO\n")))
+
+(ert-deftest swiper--isearch-format ()
+  (setq swiper--isearch-point-history
+        (list
+         (cons "" 1)))
+  (with-temp-buffer
+    (insert
+     "line0\nline1\nline line\nline line\nline5")
+    (let* ((input "li")
+           (cands (swiper--isearch-function input))
+           (len (length cands)))
+      (should (equal cands '(3 9 15 20 25 30 35)))
+      (dotimes (index len)
+        (should (string= (substring-no-properties
+                          (swiper--isearch-format
+                           index len
+                           cands
+                           input
+                           (nth index cands)
+                           (current-buffer)))
+                         "line0\nline1\nline line\nline line\nline5"))))))
+
+(ert-deftest ivy-use-selectable-prompt ()
+  (let ((ivy-use-selectable-prompt t)
+        (completing-read-function #'ivy-completing-read))
+    (should (string= (ivy-with '(ivy-read "prompt: " '("foo" "bar")
+                                 :require-match t)
+                               "C-p C-m")
+                     "foo"))
+    (should (string= (ivy-with '(ivy-read "prompt: " '("" "foo" "bar")
+                                 :require-match t)
+                               "C-p C-m")
+                     ""))
+    (should (string= (ivy-with '(completing-read "Position: " '(("") ("t") 
("b")) nil t)
+                               "C-p C-m")
+                     ""))))
+
+(ert-deftest ivy--minibuffer-index-bounds ()
+  (should (equal (ivy--minibuffer-index-bounds 0 1 10) '(0 1 0)))
+  (should (equal (ivy--minibuffer-index-bounds 0 10 10) '(0 9 0)))
+  (should (equal (ivy--minibuffer-index-bounds 0 11 10) '(0 9 0)))
+  (should (equal (ivy--minibuffer-index-bounds 1 11 10) '(0 9 1)))
+  (should (equal (ivy--minibuffer-index-bounds 5 11 10) '(0 9 5)))
+  (should (equal (ivy--minibuffer-index-bounds 6 11 10) '(1 10 5)))
+  (should (equal (ivy--minibuffer-index-bounds 7 11 10) '(2 11 5)))
+  (should (equal (ivy--minibuffer-index-bounds 8 11 10) '(2 11 6)))
+  (should (equal (ivy--minibuffer-index-bounds 10 11 10) '(2 11 8)))
+  (should (equal (ivy--minibuffer-index-bounds 1 3 10) '(0 3 1))))
+
+(defun counsel--setup-test-files ()
+  (unless (file-exists-p "tests/")
+    (shell-command
+     "git clone -b test --single-branch https://github.com/abo-abo/swiper/ 
tests"))
+  (let ((default-directory (expand-file-name "tests/"))
+        (version "066ec1d"))
+    (shell-command
+     (format "git checkout %s || git fetch && git checkout %s" version 
version))))
+
+(ert-deftest counsel-find-file-with-dollars ()
+  (counsel--setup-test-files)
+  (should (string=
+           (file-relative-name
+            (ivy-with '(counsel-find-file) "fo C-m"
+                      :dir "tests/find-file/files-with-dollar/"))
+           "tests/find-file/files-with-dollar/foo$")))
+
+(ert-deftest counsel-find-file-with-dotfiles ()
+  (counsel--setup-test-files)
+  (should (string=
+           (file-relative-name
+            (ivy-with '(counsel-find-file) "f C-m"
+                      :dir "tests/find-file/dotfiles/"))
+           "tests/find-file/dotfiles/foo/"))
+  (should (string=
+           (file-relative-name
+            (ivy-with '(counsel-find-file) "foob C-m"
+                      :dir "tests/find-file/dotfiles/"))
+           "tests/find-file/dotfiles/.foobar1")))
+
+(ert-deftest counsel-find-file-with-spaces ()
+  (counsel--setup-test-files)
+  (let ((ivy-extra-directories nil))
+    (should (string=
+             (file-relative-name
+              (ivy-with '(counsel-find-file) "TAB TAB TAB TAB"
+                        :dir "tests/find-file/directories-with-spaces/"))
+             "tests/find-file/directories-with-spaces/bar baz i/file1"))
+    (should (string=
+             (file-relative-name
+              (ivy-with '(counsel-find-file) "C-n TAB TAB TAB TAB"
+                        :dir "tests/find-file/directories-with-spaces/"))
+             "tests/find-file/directories-with-spaces/bar baz ii/file2"))
+    (should (string=
+             (file-relative-name
+              (ivy-with '(counsel-find-file) "TAB C-n TAB TAB TAB TAB"
+                        :dir "tests/find-file/directories-with-spaces/"))
+             "tests/find-file/directories-with-spaces/bar baz ii/file2"))))
+
+(ert-deftest ivy-avy ()
+  (when (require 'avy nil t)
+    (let ((enable-recursive-minibuffers t)
+          (read-numbers '(ivy-read "test: " (mapcar #'number-to-string 
(number-sequence 1 100)))))
+      (should (string= (ivy-with read-numbers "C-' a") "1"))
+      (should (string= (ivy-with read-numbers "C-v C-' d") "7")))))
+
 (provide 'ivy-test)
 
 ;;; ivy-test.el ends here
diff --git a/packages/ivy/ivy.el b/packages/ivy/ivy.el
index 7d833a6..c4633ca 100644
--- a/packages/ivy/ivy.el
+++ b/packages/ivy/ivy.el
@@ -4,7 +4,7 @@
 
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.11.0
+;; Version: 0.12.0
 ;; Package-Requires: ((emacs "24.1"))
 ;; Keywords: matching
 
@@ -42,6 +42,7 @@
 (require 'ffap)
 (require 'ivy-overlay)
 (require 'colir)
+(require 'ring)
 
 ;;* Customization
 (defgroup ivy nil
@@ -224,7 +225,7 @@ Only \"./\" and \"../\" apply here.  They appear in reverse 
order."
   "When non-nil, add recent files and bookmarks to `ivy-switch-buffer'."
   :type 'boolean)
 
-(defcustom ivy-display-function nil
+(defvar ivy-display-function nil
   "Determine where to display candidates.
 When nil (the default), candidates are shown in the minibuffer.
 Otherwise, this can be set to a function which takes a string
@@ -235,21 +236,38 @@ This user option acts as a global default for Ivy-based
 completion commands.  You can customize the display function on a
 per-command basis via `ivy-display-functions-alist', which see.
 See also URL
-`https://github.com/abo-abo/swiper/wiki/ivy-display-function'."
-  :type '(choice
-          (const :tag "Minibuffer" nil)
-          (const :tag "LV" ivy-display-function-lv)
-          (const :tag "Popup" ivy-display-function-popup)
-          (const :tag "Overlay" ivy-display-function-overlay)))
+`https://github.com/abo-abo/swiper/wiki/ivy-display-function'.")
+
+(make-obsolete-variable
+ 'ivy-display-function 'ivy-display-functions-alist "<2019-12-05 Mon>")
+
+(defvar ivy--display-function nil
+  "The display-function is used in current.")
 
 (defvar ivy-display-functions-props
   '((ivy-display-function-overlay :cleanup ivy-overlay-cleanup))
   "Map Ivy display functions to their property lists.
 Examples of properties include associated `:cleanup' functions.")
 
-(defvar ivy-display-functions-alist
-  '((ivy-completion-in-region . ivy-display-function-overlay))
-  "An alist for customizing `ivy-display-function'.")
+(defcustom ivy-display-functions-alist
+  '((ivy-completion-in-region . ivy-display-function-overlay)
+    (t . nil))
+  "An alist for customizing display-function.
+
+display-function determine where to display candidates. it takes
+a string argument comprising the current matching candidates and
+displays it somewhere.
+
+When display-function is nil, candidates are shown in the
+minibuffer."
+  :type '(alist
+          :key-type symbol
+          :value-type (choice
+                       (const :tag "Minibuffer" nil)
+                       (const :tag "LV" ivy-display-function-lv)
+                       (const :tag "Popup" ivy-display-function-popup)
+                       (const :tag "Overlay" ivy-display-function-overlay)
+                       (function :tag "Custom function"))))
 
 (defvar ivy-completing-read-dynamic-collection nil
   "Run `ivy-completing-read' with `:dynamic-collection t`.")
@@ -266,7 +284,7 @@ Examples of properties include associated `:cleanup' 
functions.")
     (Info-virtual-index . ivy-completing-read-with-empty-string-def)
     (info-display-manual . ivy-completing-read-with-empty-string-def))
   "An alist of handlers to replace `completing-read' in `ivy-mode'."
-  :type '(alist :key-type function :value-type function))
+  :type '(alist :key-type symbol :value-type function))
 
 (defcustom ivy-height-alist nil
   "An alist to customize `ivy-height'.
@@ -305,6 +323,26 @@ ACTIONS that have the same key."
                     (append (plist-get ivy--actions-list cmd) actions)
                     :key #'car :test #'equal))))
 
+(defun ivy--compute-extra-actions (action caller)
+  "Add extra actions to ACTION based on CALLER."
+  (let ((extra-actions (cl-delete-duplicates
+                        (append (plist-get ivy--actions-list t)
+                                (plist-get ivy--actions-list this-command)
+                                (plist-get ivy--actions-list caller))
+                        :key #'car :test #'equal)))
+    (if extra-actions
+        (cond ((functionp action)
+               `(1
+                 ("o" ,action "default")
+                 ,@extra-actions))
+              ((null action)
+               `(1
+                 ("o" identity "default")
+                 ,@extra-actions))
+              (t
+               (delete-dups (append action extra-actions))))
+      action)))
+
 (defvar ivy--prompts-list nil)
 
 (defun ivy-set-prompt (caller prompt-fn)
@@ -354,6 +392,17 @@ Example:
   (setq ivy--sources-list
         (plist-put ivy--sources-list cmd sources)))
 
+(defun ivy--compute-extra-candidates (caller)
+  (let ((extra-sources (or (plist-get ivy--sources-list caller)
+                           '((original-source))))
+        (result nil))
+    (dolist (source extra-sources)
+      (cond ((equal source '(original-source))
+             (push source result))
+            ((null (cdr source))
+             (push (list (car source) (funcall (car source))) result))))
+    result))
+
 (defvar ivy-current-prefix-arg nil
   "Prefix arg to pass to actions.
 This is a global variable that is set by ivy functions for use in
@@ -399,6 +448,7 @@ action functions.")
     (define-key map (kbd "M-r") 'ivy-toggle-regexp-quote)
     (define-key map (kbd "M-j") 'ivy-yank-word)
     (define-key map (kbd "M-i") 'ivy-insert-current)
+    (define-key map (kbd "C-M-y") 'ivy-insert-current-full)
     (define-key map (kbd "C-o") 'hydra-ivy/body)
     (define-key map (kbd "M-o") 'ivy-dispatching-done)
     (define-key map (kbd "C-M-o") 'ivy-dispatching-call)
@@ -412,6 +462,7 @@ action functions.")
     (define-key map (kbd "C-c C-a") 'ivy-toggle-ignore)
     (define-key map (kbd "C-c C-s") 'ivy-rotate-sort)
     (define-key map [remap describe-mode] 'ivy-help)
+    (define-key map "$" 'ivy-magic-read-file-env)
     map)
   "Keymap used in the minibuffer.")
 (autoload 'hydra-ivy/body "ivy-hydra" "" t)
@@ -449,7 +500,8 @@ action functions.")
   directory
   caller
   current
-  def)
+  def
+  multi-action)
 
 (defvar ivy-last (make-ivy-state)
   "The last parameters passed to `ivy-read'.
@@ -474,20 +526,25 @@ the restoring themselves.")
   "Return a string that corresponds to the current thing at point."
   (substring-no-properties
    (cond
-    ((thing-at-point 'url))
-    ((and (eq (ivy-state-collection ivy-last) #'read-file-name-internal)
-          (let ((inhibit-message t))
-            (ignore-errors
-              (ffap-file-at-point)))))
-    ((let ((s (thing-at-point 'symbol)))
-       (and (stringp s)
-            (if (string-match "\\`[`']?\\(.*?\\)'?\\'" s)
-                (match-string 1 s)
-              s))))
-    ((looking-at "(+\\(\\(?:\\sw\\|\\s_\\)+\\)\\_>")
-     (match-string-no-properties 1))
-    (t
-     ""))))
+     ((use-region-p)
+      (let* ((beg (region-beginning))
+             (end (region-end))
+             (eol (save-excursion (goto-char beg) (line-end-position))))
+        (buffer-substring-no-properties beg (min end eol))))
+     ((thing-at-point 'url))
+     ((and (eq (ivy-state-collection ivy-last) #'read-file-name-internal)
+           (let ((inhibit-message t))
+             (ignore-errors
+               (ffap-file-at-point)))))
+     ((let ((s (thing-at-point 'symbol)))
+        (and (stringp s)
+             (if (string-match "\\`[`']?\\(.*?\\)'?\\'" s)
+                 (match-string 1 s)
+               s))))
+     ((looking-at "(+\\(\\(?:\\sw\\|\\s_\\)+\\)\\_>")
+      (match-string-no-properties 1))
+     (t
+      ""))))
 
 (defvar ivy-history nil
   "History list of candidates entered in the minibuffer.
@@ -575,6 +632,20 @@ Either a string or a list for `ivy-re-match'.")
 (defvar ivy--old-text ""
   "Store old `ivy-text' for dynamic completion.")
 
+(defvar ivy--trying-to-resume-dynamic-collection nil
+  "Non-nil if resuming from a dynamic collection.
+When non-nil, ivy will wait until the first chunk of asynchronous
+candidates has been received before selecting the last
+preselected candidate.")
+
+(defun ivy--set-index-dynamic-collection ()
+  (when ivy--trying-to-resume-dynamic-collection
+    (let ((preselect-index
+           (ivy--preselect-index (ivy-state-preselect ivy-last) 
ivy--all-candidates)))
+      (when preselect-index
+        (ivy-set-index preselect-index)))
+    (setq ivy--trying-to-resume-dynamic-collection nil)))
+
 (defcustom ivy-case-fold-search-default
   (if search-upper-case
       'auto
@@ -660,14 +731,16 @@ N is obtained from `ivy-more-chars-alist'."
 
 (defun ivy--done (text)
   "Insert TEXT and exit minibuffer."
-  (insert
-   (setf (ivy-state-current ivy-last)
-         (if (and ivy--directory
-                  (not (eq (ivy-state-history ivy-last) 'grep-files-history)))
-             (expand-file-name text ivy--directory)
-           text)))
-  (setq ivy-exit 'done)
-  (exit-minibuffer))
+  (if (member (ivy-state-prompt ivy-last) '("Create directory: " "Make 
directory: "))
+      (ivy-immediate-done)
+    (insert
+     (setf (ivy-state-current ivy-last)
+           (if (and ivy--directory
+                    (not (eq (ivy-state-history ivy-last) 
'grep-files-history)))
+               (expand-file-name text ivy--directory)
+             text)))
+    (setq ivy-exit 'done)
+    (exit-minibuffer)))
 
 (defcustom ivy-use-selectable-prompt nil
   "When non-nil, make the prompt line selectable like a candidate.
@@ -684,15 +757,24 @@ prompt is selected wraps around to the last candidate, 
while calling
 candidate, not the prompt."
   :type 'boolean)
 
+(defvar ivy--use-selectable-prompt nil
+  "Store the effective `ivy-use-selectable-prompt' for current session.")
+
 (defun ivy--prompt-selectable-p ()
   "Return t if the prompt line is selectable."
   (and ivy-use-selectable-prompt
-       (memq (ivy-state-require-match ivy-last)
-             '(nil confirm confirm-after-completion))))
+       (or (memq (ivy-state-require-match ivy-last)
+                 '(nil confirm confirm-after-completion))
+           ;; :require-match is t, but "" is in the collection
+           (let ((coll (ivy-state-collection ivy-last)))
+             (and (listp coll)
+                  (if (consp (car coll))
+                      (member '("") coll)
+                    (member "" coll)))))))
 
 (defun ivy--prompt-selected-p ()
   "Return t if the prompt line is selected."
-  (and (ivy--prompt-selectable-p)
+  (and ivy--use-selectable-prompt
        (= ivy--index -1)))
 
 ;;* Commands
@@ -803,6 +885,7 @@ selection, non-nil otherwise."
                                       (cdr actions)))
                     (not (string= key (car (nth action-idx (cdr actions))))))
           (setq key (concat key (string (read-key hint)))))
+        (ivy-shrink-after-dispatching)
         (cond ((member key '("" ""))
                nil)
               ((null action-idx)
@@ -926,7 +1009,6 @@ contains a single candidate.")
              (user (match-string 2 ivy-text))
              (rest (match-string 3 ivy-text))
              res)
-         (require 'tramp)
          (dolist (x (tramp-get-completion-function method))
            (setq res (append res (funcall (car x) (cadr x)))))
          (setq res (delq nil res))
@@ -1005,6 +1087,7 @@ If the text hasn't changed as a result, forward to 
`ivy-alt-done'."
                                         ivy--old-cands)))))
     (cond ((eq new t) nil)
           ((string= new ivy-text) nil)
+          ((string= (car tail) new) nil)
           (new
            (delete-region (minibuffer-prompt-end) (point-max))
            (setcar tail
@@ -1015,7 +1098,7 @@ If the text hasn't changed as a result, forward to 
`ivy-alt-done'."
             (setq ivy-text
                   (concat
                    (mapconcat #'identity parts " ")
-                   (and ivy-tab-space " "))))
+                   (and ivy-tab-space (not (= (length ivy--old-cands) 1)) " 
"))))
            (when (and
                   (eq (ivy-state-collection ivy-last) 
#'read-file-name-internal)
                   (= 1 (length
@@ -1042,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))
@@ -1155,7 +1232,7 @@ If the input is empty, select the previous history 
element instead."
   (interactive "p")
   (setq arg (or arg 1))
   (let ((index (- ivy--index arg))
-        (min-index (if (ivy--prompt-selectable-p) -1 0)))
+        (min-index (if ivy--use-selectable-prompt -1 0)))
     (if (< index min-index)
         (if ivy-wrap
             (ivy-end-of-buffer)
@@ -1166,7 +1243,7 @@ If the input is empty, select the previous history 
element instead."
   "Move cursor vertically up ARG candidates.
 If the input is empty, select the previous history element instead."
   (interactive "p")
-  (when (and (zerop ivy--index) (string= ivy-text ""))
+  (when (string= ivy-text "")
     (ivy-previous-history-element 1))
   (ivy-previous-line arg))
 
@@ -1261,6 +1338,16 @@ See variable `ivy-recursive-restore' for further 
information."
              (not (eq ivy-last ivy-recursive-last)))
     (ivy--reset-state (setq ivy-last ivy-recursive-last))))
 
+(defvar ivy-marked-candidates nil
+  "List of marked candidates.
+Use `ivy-mark' to populate this.
+
+When this list is non-nil at the end of the session, the action
+will be called for each element of this list.")
+
+(defvar ivy-mark-prefix ">"
+  "Prefix used by `ivy-mark'.")
+
 (defun ivy-call ()
   "Call the current action without exiting completion."
   (interactive)
@@ -1271,32 +1358,49 @@ See variable `ivy-recursive-restore' for further 
information."
                                ivy-alt-done
                                ivy-dispatching-done))
     (setq ivy-current-prefix-arg current-prefix-arg))
-  (let ((action (and (not ivy-inhibit-action)
-                     (ivy--get-action ivy-last))))
+  (let ((action
+         (if (functionp ivy-inhibit-action)
+             ivy-inhibit-action
+           (and (not ivy-inhibit-action)
+                (ivy--get-action ivy-last)))))
     (when action
       (let* ((collection (ivy-state-collection ivy-last))
              (current (ivy-state-current ivy-last))
              (x (cond
-                 ;; Alist type.
-                 ((and (consp (car-safe collection))
-                       ;; Previously, the cdr of the selected
-                       ;; candidate would be returned.  Now, the
-                       ;; whole candidate is returned.
-                       (let ((idx (get-text-property 0 'idx current)))
-                         (if idx
-                             (nth idx collection)
-                           (assoc current collection)))))
-                 (ivy--directory
-                  (expand-file-name current ivy--directory))
-                 ((equal current "")
-                  ivy-text)
-                 (t
-                  current))))
+                  ;; Alist type.
+                  ((and (consp (car-safe collection))
+                        ;; Previously, the cdr of the selected
+                        ;; candidate would be returned.  Now, the
+                        ;; whole candidate is returned.
+                        (let ((idx (get-text-property 0 'idx current)))
+                          (if idx
+                              (nth idx collection)
+                            (assoc current collection)))))
+                  (ivy--directory
+                   (expand-file-name current ivy--directory))
+                  ((equal current "")
+                   ivy-text)
+                  (t
+                   current))))
         (if (eq action #'identity)
-            (funcall action x)
+            (prog1 x
+              (ivy-recursive-restore))
           (select-window (ivy--get-window ivy-last))
           (set-buffer (ivy-state-buffer ivy-last))
-          (prog1 (unwind-protect (funcall action x)
+          (prog1 (unwind-protect
+                      (if ivy-marked-candidates
+                          (let ((prefix-len (length ivy-mark-prefix)))
+                            (setq ivy-marked-candidates
+                                  (mapcar (lambda (s) (substring s prefix-len))
+                                          ivy-marked-candidates))
+                            (if (ivy-state-multi-action ivy-last)
+                                (funcall
+                                 (ivy-state-multi-action ivy-last)
+                                 ivy-marked-candidates)
+                              (dolist (c ivy-marked-candidates)
+                                (let ((default-directory (ivy-state-directory 
ivy-last)))
+                                  (funcall action c)))))
+                        (funcall action x))
                    (ivy-recursive-restore))
             (unless (or (eq ivy-exit 'done)
                         (minibuffer-window-active-p (selected-window))
@@ -1334,12 +1438,21 @@ Call the permanent action if possible."
   (move-end-of-line 1)
   (ivy--maybe-scroll-history))
 
+(defun ivy--insert-symbol-boundaries ()
+  (undo-boundary)
+  (beginning-of-line)
+  (insert "\\_<")
+  (end-of-line)
+  (insert "\\_>"))
+
 (defun ivy-next-history-element (arg)
   "Forward to `next-history-element' with ARG."
   (interactive "p")
   (if (and (= minibuffer-history-position 0)
            (equal ivy-text ""))
       (progn
+        (when minibuffer-default
+          (setq ivy--default (car minibuffer-default)))
         (insert ivy--default)
         (when (and (with-ivy-window (derived-mode-p 'prog-mode))
                    (eq (ivy-state-caller ivy-last) 'swiper)
@@ -1347,11 +1460,7 @@ Call the permanent action if possible."
                    (not (ffap-url-p ivy--default))
                    (not (ivy-state-dynamic-collection ivy-last))
                    (> (point) (minibuffer-prompt-end)))
-          (undo-boundary)
-          (insert "\\_>")
-          (goto-char (minibuffer-prompt-end))
-          (insert "\\_<")
-          (forward-char (+ 2 (length ivy--default)))))
+          (ivy--insert-symbol-boundaries)))
     (next-history-element arg))
   (ivy--cd-maybe)
   (move-end-of-line 1)
@@ -1496,16 +1605,28 @@ minibuffer."
 (defvar avy-keys-alist)
 (defvar avy-style)
 (defvar avy-styles-alist)
-(declare-function avy--process "ext:avy")
+(declare-function avy-process "ext:avy")
 (declare-function avy--style-fn "ext:avy")
 
-(defcustom ivy-format-function #'ivy-format-function-default
-  "Function to transform the list of candidates into a string.
+(defcustom ivy-format-functions-alist
+  '((t . ivy-format-function-default))
+  "An alist of functions that transform the list of candidates into a string.
 This string is inserted into the minibuffer."
-  :type '(choice
-          (const :tag "Default" ivy-format-function-default)
-          (const :tag "Arrow prefix" ivy-format-function-arrow)
-          (const :tag "Full line" ivy-format-function-line)))
+  :type '(alist
+          :key-type symbol
+          :value-type
+          (choice
+           (const :tag "Default" ivy-format-function-default)
+           (const :tag "Arrow prefix" ivy-format-function-arrow)
+           (const :tag "Full line" ivy-format-function-line)
+           (function :tag "Custom function"))))
+
+(defvar ivy-format-function #'ivy-format-function-default
+  "Function to transform the list of candidates into a string.
+This string is inserted into the minibuffer.")
+
+(make-obsolete-variable
+ 'ivy-format-function 'ivy-format-functions-alist "<2019-06-03 Mon>")
 
 (eval-after-load 'avy
   '(add-to-list 'avy-styles-alist '(ivy-avy . pre)))
@@ -1529,9 +1650,28 @@ This string is inserted into the minibuffer."
 
 (defun ivy--avy-action (pt)
   (when (number-or-marker-p pt)
-    (ivy--done
-     (substring-no-properties
-      (nth (- (line-number-at-pos pt) 2) ivy--old-cands)))))
+    (let ((bnd (ivy--minibuffer-index-bounds
+                ivy--index ivy--length ivy-height)))
+      (ivy--done
+       (substring-no-properties
+        (nth (+ (car bnd) (- (line-number-at-pos pt) 2)) ivy--old-cands))))))
+
+(defun ivy--avy-handler-function (char)
+  (let (cmd)
+    (cond ((memq char '(27 ?\C-g))
+           ;; exit silently
+           (throw 'done 'abort))
+          ((memq (setq cmd (lookup-key ivy-minibuffer-map (vector char)))
+                 '(ivy-scroll-up-command
+                   ivy-scroll-down-command))
+           (funcall cmd)
+           (ivy--exhibit)
+           (throw 'done 'exit))
+          ;; ignore wrong key
+          (t
+           (throw 'done 'restart)))))
+
+(defvar avy-handler-function)
 
 (defun ivy-avy ()
   "Jump to one of the current ivy candidates."
@@ -1543,9 +1683,12 @@ This string is inserted into the minibuffer."
                        avy-keys))
          (avy-style (or (cdr (assq 'ivy-avy avy-styles-alist))
                         avy-style))
-         (avy-action #'ivy--avy-action))
-    (avy--process
-     (ivy--avy-candidates))))
+         (avy-action #'identity)
+         (avy-handler-function #'ivy--avy-handler-function)
+         res)
+    (while (eq (setq res (avy-process (ivy--avy-candidates))) t))
+    (when res
+      (ivy--avy-action res))))
 
 (defun ivy-sort-file-function-default (x y)
   "Compare two files X and Y.
@@ -1669,7 +1812,7 @@ like.")
     (ivy--regex-plus . ivy--highlight-default))
   "An alist of highlighting functions for each regex buidler function.")
 
-(defvar ivy-initial-inputs-alist
+(defcustom ivy-initial-inputs-alist
   '((org-refile . "^")
     (org-agenda-refile . "^")
     (org-capture-refile . "^")
@@ -1682,7 +1825,9 @@ like.")
   "An alist associating commands with their initial input.
 
 Each cdr is either a string or a function called in the context
-of a call to `ivy-read'.")
+of a call to `ivy-read'."
+  :type '(alist :key-type (symbol)
+                :value-type (choice (string) (function))))
 
 (defcustom ivy-hooks-alist nil
   "An alist associating commands to setup functions.
@@ -1706,8 +1851,9 @@ May supersede `ivy-initial-inputs-alist'."
 Directories come first."
   (let* ((default-directory dir)
          (seq (condition-case nil
-                  (all-completions "" #'read-file-name-internal
-                                   (ivy-state-predicate ivy-last))
+                  (mapcar (lambda (s) (replace-regexp-in-string "\\$\\$" "$" 
s))
+                          (all-completions "" #'read-file-name-internal
+                                           (ivy-state-predicate ivy-last)))
                 (error
                  (directory-files dir))))
          sort-fn)
@@ -1744,7 +1890,8 @@ found, it falls back to the key t."
 
 (defun ivy--remove-props (str &rest props)
   "Return STR with text PROPS destructively removed."
-  (remove-list-of-text-properties 0 (length str) props str)
+  (ignore-errors
+    (remove-list-of-text-properties 0 (length str) props str))
   str)
 
 ;;** Entry Point
@@ -1753,7 +1900,8 @@ found, it falls back to the key t."
                     &key
                       predicate require-match initial-input
                       history preselect def keymap update-fn sort
-                      action unwind re-builder matcher
+                      action multi-action
+                      unwind re-builder matcher
                       dynamic-collection caller)
   "Read a string in the minibuffer, with completion.
 
@@ -1761,7 +1909,7 @@ PROMPT is a string, normally ending in a colon and a 
space.
 `ivy-count-format' is prepended to PROMPT during completion.
 
 COLLECTION is either a list of strings, a function, an alist, or
-a hash table.
+a hash table, supplied for `minibuffer-completion-table'.
 
 PREDICATE is applied to filter out the COLLECTION immediately.
 This argument is for compatibility with `completing-read'.
@@ -1777,8 +1925,13 @@ history.
 
 KEYMAP is composed with `ivy-minibuffer-map'.
 
-If PRESELECT is not nil, then select the corresponding candidate
-out of the ones that match the INITIAL-INPUT.
+PRESELECT, when non-nil, determines which one of the candidates
+matching INITIAL-INPUT to select initially.  An integer stands
+for the position of the desired candidate in the collection,
+counting from zero.  Otherwise, use the first occurrence of
+PRESELECT in the collection.  Comparison is first done with
+`equal'.  If that fails, and when applicable, match PRESELECT as
+a regular expression.
 
 DEF is for compatibility with `completing-read'.
 
@@ -1790,6 +1943,11 @@ to sort candidates before displaying them.
 ACTION is a function to call after selecting a candidate.
 It takes the candidate, which is a string, as its only argument.
 
+MULTI-ACTION, when non-nil, is called instead of ACTION when
+there are marked candidates. It takes the list of candidates as
+its only argument. When it's nil, ACTION is called on each marked
+candidate.
+
 UNWIND is a function of no arguments to call before exiting.
 
 RE-BUILDER is a function transforming input text into a regex
@@ -1805,49 +1963,13 @@ candidates is updated after each input by calling 
COLLECTION.
 CALLER is a symbol to uniquely identify the caller to `ivy-read'.
 It is used, along with COLLECTION, to determine which
 customizations apply to the current completion session."
-  (let ((extra-actions (delete-dups
-                        (append (plist-get ivy--actions-list t)
-                                (plist-get ivy--actions-list this-command)
-                                (plist-get ivy--actions-list caller)))))
-    (when extra-actions
-      (setq action
-            (cond ((functionp action)
-                   `(1
-                     ("o" ,action "default")
-                     ,@extra-actions))
-                  ((null action)
-                   `(1
-                     ("o" identity "default")
-                     ,@extra-actions))
-                  (t
-                   (delete-dups (append action extra-actions)))))))
-  (unless caller
-    (setq caller this-command))
-  (let ((extra-sources (plist-get ivy--sources-list caller)))
-    (if extra-sources
-        (progn
-          (setq ivy--extra-candidates nil)
-          (dolist (source extra-sources)
-            (cond ((equal source '(original-source))
-                   (setq ivy--extra-candidates
-                         (cons source ivy--extra-candidates)))
-                  ((null (cdr source))
-                   (setq ivy--extra-candidates
-                         (cons
-                          (list (car source) (funcall (car source)))
-                          ivy--extra-candidates))))))
-      (setq ivy--extra-candidates '((original-source)))))
-  (let ((ivy-recursive-last (and (active-minibuffer-window) ivy-last))
-        (transformer-fn
-         (plist-get ivy--display-transformers-list
-                    (cond (caller)
-                          ((functionp collection)
-                           collection))))
-        (ivy-display-function
-         (unless (window-minibuffer-p)
-           (or ivy-display-function
-               (ivy-alist-setting ivy-display-functions-alist caller))))
-        (height (ivy--height caller)))
+  (setq caller (or caller this-command))
+  (let* ((ivy-recursive-last (and (active-minibuffer-window) ivy-last))
+         (ivy--display-function
+          (when (or ivy-recursive-last
+                    (not (window-minibuffer-p)))
+            (ivy-alist-setting ivy-display-functions-alist caller)))
+         result)
     (setq ivy-last
           (make-ivy-state
            :prompt prompt
@@ -1858,9 +1980,14 @@ customizations apply to the current completion session."
            :history history
            :preselect preselect
            :keymap keymap
-           :update-fn update-fn
+           :update-fn (if (eq update-fn 'auto)
+                          (lambda ()
+                            (funcall (ivy--get-action ivy-last)
+                                     (ivy-state-current ivy-last)))
+                        update-fn)
            :sort sort
-           :action action
+           :action (ivy--compute-extra-actions action caller)
+           :multi-action multi-action
            :frame (selected-frame)
            :window (selected-window)
            :buffer (current-buffer)
@@ -1868,60 +1995,64 @@ customizations apply to the current completion session."
            :re-builder re-builder
            :matcher matcher
            :dynamic-collection dynamic-collection
-           :display-transformer-fn transformer-fn
+           :display-transformer-fn (plist-get ivy--display-transformers-list 
caller)
            :directory default-directory
            :caller caller
            :def def))
     (ivy--reset-state ivy-last)
-    (prog1
-        (unwind-protect
-             (minibuffer-with-setup-hook
-                 #'ivy--minibuffer-setup
-               (let* ((hist (or history 'ivy-history))
-                      (minibuffer-completion-table collection)
-                      (minibuffer-completion-predicate predicate)
-                      (ivy-height height)
-                      (resize-mini-windows (unless (display-graphic-p)
-                                             'grow-only)))
-                 (if (and ivy-auto-select-single-candidate
-                          ivy--all-candidates
-                          (null (cdr ivy--all-candidates)))
-                     (progn
-                       (setf (ivy-state-current ivy-last)
-                             (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
-                    hist))
-                 (when (eq ivy-exit 'done)
-                   (let ((item (if ivy--directory
-                                   (ivy-state-current ivy-last)
-                                 ivy-text)))
-                     (unless (equal item "")
-                       (set hist (cons (propertize item 'ivy-index ivy--index)
-                                       (delete item
-                                               (cdr (symbol-value hist))))))))
-                 (ivy-state-current ivy-last)))
-          ;; Fixes a bug in ESS, #1660
-          (put 'post-command-hook 'permanent-local nil)
-          (remove-hook 'post-command-hook #'ivy--queue-exhibit)
-          (let ((cleanup (ivy--display-function-prop :cleanup)))
-            (when (functionp cleanup)
-              (funcall cleanup)))
-          (when (setq unwind (ivy-state-unwind ivy-last))
-            (funcall unwind))
-          (ivy--pulse-cleanup)
-          (unless (eq ivy-exit 'done)
-            (ivy-recursive-restore)))
-      (ivy-call)
-      (ivy--remove-props (ivy-state-current ivy-last) 'idx))))
+    (unwind-protect
+         (minibuffer-with-setup-hook
+             #'ivy--minibuffer-setup
+           (let* ((hist (or history 'ivy-history))
+                  (minibuffer-completion-table collection)
+                  (minibuffer-completion-predicate predicate)
+                  (ivy-height (ivy--height caller))
+                  (resize-mini-windows (unless (display-graphic-p)
+                                         'grow-only)))
+             (if (and ivy-auto-select-single-candidate
+                      ivy--all-candidates
+                      (null (cdr ivy--all-candidates)))
+                 (progn
+                   (setf (ivy-state-current ivy-last)
+                         (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
+                hist))
+             (when (eq ivy-exit 'done)
+               (let ((item (if ivy--directory
+                               (ivy-state-current ivy-last)
+                             ivy-text)))
+                 (unless (equal item "")
+                   (set hist (cons (propertize item 'ivy-index ivy--index)
+                                   (delete item
+                                           (cdr (symbol-value hist))))))))
+             (setq result (ivy-state-current ivy-last))))
+      (ivy--cleanup))
+    (ivy-call)
+    (ivy--remove-props (ivy-state-current ivy-last) 'idx)
+    result))
+
+(defun ivy--cleanup ()
+  ;; Fixes a bug in ESS, #1660
+  (put 'post-command-hook 'permanent-local nil)
+  (remove-hook 'post-command-hook #'ivy--queue-exhibit)
+  (let ((cleanup (ivy--display-function-prop :cleanup))
+        (unwind (ivy-state-unwind ivy-last)))
+    (when (functionp cleanup)
+      (funcall cleanup))
+    (when unwind
+      (funcall unwind)))
+  (ivy--pulse-cleanup)
+  (unless (eq ivy-exit 'done)
+    (ivy-recursive-restore)))
 
 (defun ivy--display-function-prop (prop)
-  "Return PROP associated with current `ivy-display-function'."
-  (plist-get (cdr (assq ivy-display-function
+  "Return PROP associated with current `ivy--display-function'."
+  (plist-get (cdr (assq ivy--display-function
                         ivy-display-functions-props))
              prop))
 
@@ -1930,6 +2061,7 @@ customizations apply to the current completion session."
 (defun ivy--reset-state (state)
   "Reset the ivy to STATE.
 This is useful for recursive `ivy-read'."
+  (setq ivy-marked-candidates nil)
   (unless (equal (selected-frame) (ivy-state-frame state))
     (select-window (active-minibuffer-window)))
   (let* ((prompt (or (ivy-state-prompt state) ""))
@@ -1950,6 +2082,7 @@ This is useful for recursive `ivy-read'."
                       (t
                        init)))))
          (def (ivy-state-def state)))
+    (setq ivy--extra-candidates (ivy--compute-extra-candidates caller))
     (setq ivy--directory nil)
     (setq ivy-case-fold-search ivy-case-fold-search-default)
     (setq ivy--regex-function
@@ -1978,16 +2111,17 @@ This is useful for recursive `ivy-read'."
                                 (all-completions "(" collection predicate)))
                      (all-completions "" collection predicate))))
             ((eq collection #'read-file-name-internal)
+             (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
@@ -2026,7 +2160,15 @@ This is useful for recursive `ivy-read'."
                          (equal (ivy--get-action ivy-last) 'identity))
                  (setq initial-input nil))))
             ((eq collection #'internal-complete-buffer)
-             (setq coll (ivy--buffer-list "" ivy-use-virtual-buffers 
predicate)))
+             (setq prompt
+                   (replace-regexp-in-string "RET to end" "C-M-j to end" 
prompt))
+             (setq coll (ivy--buffer-list
+                         ""
+                         (and ivy-use-virtual-buffers
+                              (member caller '(ivy-switch-buffer
+                                               ivy-switch-buffer-other-window
+                                               counsel-switch-buffer)))
+                         predicate)))
             (dynamic-collection
              (setq coll (funcall collection ivy-text)))
             ((consp (car-safe collection))
@@ -2068,13 +2210,15 @@ This is useful for recursive `ivy-read'."
       (setq coll (ivy--set-candidates coll))
       (setq ivy--old-re nil)
       (setq ivy--old-cands nil)
-      (when (integerp preselect)
-        (setq ivy--old-re "")
-        (ivy-set-index preselect))
       (when initial-input
         ;; Needed for anchor to work
         (setq ivy--old-cands coll)
         (setq ivy--old-cands (ivy--filter initial-input coll)))
+      (unless (setq ivy--trying-to-resume-dynamic-collection
+                    (and preselect dynamic-collection))
+        (when (integerp preselect)
+          (setq ivy--old-re "")
+          (ivy-set-index preselect)))
       (setq ivy--all-candidates coll)
       (unless (integerp preselect)
         (ivy-set-index (or
@@ -2093,6 +2237,7 @@ This is useful for recursive `ivy-read'."
               (buffer-substring (region-beginning) (region-end))
             (ivy-thing-at-point)))
     (setq ivy--prompt (ivy-add-prompt-count (ivy--quote-format-string prompt)))
+    (setq ivy--use-selectable-prompt (ivy--prompt-selectable-p))
     (setf (ivy-state-initial-input ivy-last) initial-input)))
 
 (defun ivy-add-prompt-count (prompt)
@@ -2211,6 +2356,7 @@ The previous string is between `ivy-completion-beg' and 
`ivy-completion-end'."
         (delete-region beg end))
       (setq ivy-completion-beg (point))
       (insert (substring-no-properties str))
+      (completion--done str 'exact)
       (setq ivy-completion-end (point))
       (save-excursion
         (dolist (cursor fake-cursors)
@@ -2294,7 +2440,8 @@ See `completion-in-region' for further information."
                          :unwind (lambda ()
                                    (unless (eq ivy-exit 'done)
                                      (goto-char ivy-completion-beg)
-                                     (insert initial)))
+                                     (when initial
+                                       (insert initial))))
                          :caller 'ivy-completion-in-region)
                t))))))
 
@@ -2339,12 +2486,8 @@ Minibuffer bindings:
   (cond ((integerp preselect)
          preselect)
         ((cl-position preselect candidates :test #'equal))
-        ((stringp preselect)
-         (let ((re preselect))
-           (cl-position-if
-            (lambda (x)
-              (string-match-p re x))
-            candidates)))))
+        ((ivy--regex-p preselect)
+         (cl-position preselect candidates :test #'string-match-p))))
 
 ;;* Implementation
 ;;** Regex
@@ -2433,7 +2576,9 @@ When GREEDY is non-nil, join words in a greedy way."
                       (if (= (length subs) 1)
                           (cons
                            (setq ivy--subexps 0)
-                           (car subs))
+                           (if (string-match-p "\\`\\.[^.]" (car subs))
+                               (concat "\\." (substring (car subs) 1))
+                             (car subs)))
                         (cons
                          (setq ivy--subexps (length subs))
                          (mapconcat
@@ -2445,17 +2590,13 @@ When GREEDY is non-nil, join words in a greedy way."
                           (if greedy ".*" ".*?")))))
                     ivy--regex-hash)))))
 
-(defun ivy--legal-regex-p (str)
-  "Return t if STR is valid regular expression."
-  (condition-case nil
-      (progn
-        (string-match-p str "")
-        t)
-    (invalid-regexp nil)))
+(defun ivy--regex-p (object)
+  "Return OBJECT if it is a valid regular expression, else nil."
+  (ignore-errors (string-match-p object "") object))
 
 (defun ivy--regex-or-literal (str)
-  "If STR isn't a legal regex, escape it."
-  (if (ivy--legal-regex-p str) str (regexp-quote str)))
+  "If STR isn't a legal regexp, escape it."
+  (or (ivy--regex-p str) (regexp-quote str)))
 
 (defun ivy--split-negation (str)
   "Split STR into text before and after ! delimiter.
@@ -2558,7 +2699,7 @@ Insert .* between each char."
                     (apply #'concat
                            (cl-mapcar
                             #'concat
-                            (cons "" (cdr (mapcar (lambda (c) (format "[^%c]*" 
c))
+                            (cons "" (cdr (mapcar (lambda (c) (format 
"[^%c\n]*" c))
                                                   lst)))
                             (mapcar (lambda (x) (format "\\(%s\\)" 
(regexp-quote (char-to-string x))))
                                     lst))))
@@ -2582,6 +2723,7 @@ tries to ensure that it does not change depending on the 
number of candidates."
   (setq-local mwheel-scroll-up-function 'ivy-next-line)
   (setq-local mwheel-scroll-down-function 'ivy-previous-line)
   (setq-local completion-show-inline-help nil)
+  (setq-local line-spacing nil)
   (setq-local minibuffer-default-add-function
               (lambda ()
                 (list ivy--default)))
@@ -2598,9 +2740,7 @@ tries to ensure that it does not change depending on the 
number of candidates."
   (add-hook 'post-command-hook #'ivy--queue-exhibit nil t)
   (let ((hook (ivy-alist-setting ivy-hooks-alist)))
     (when (functionp hook)
-      (funcall hook)))
-  ;; Show completions with empty input.
-  (ivy--exhibit))
+      (funcall hook))))
 
 (defun ivy--input ()
   "Return the current minibuffer input."
@@ -2609,7 +2749,7 @@ tries to ensure that it does not change depending on the 
number of candidates."
    (minibuffer-prompt-end)
    (line-end-position)))
 
-(defun ivy--cleanup ()
+(defun ivy--minibuffer-cleanup ()
   "Delete the displayed completion candidates."
   (save-excursion
     (goto-char (minibuffer-prompt-end))
@@ -2724,9 +2864,8 @@ parts beyond their respective faces `ivy-confirm-face' and
         ;; Mark prompt as selected if the user moves there or it is the only
         ;; option left.  Since the user input stays put, we have to manually
         ;; remove the face as well.
-        (when (ivy--prompt-selectable-p)
-          (if (or (= ivy--index -1)
-                  (= ivy--length 0))
+        (when ivy--use-selectable-prompt
+          (if (= ivy--index -1)
               (ivy-add-face-text-property
                (minibuffer-prompt-end) (line-end-position) 'ivy-prompt-match)
             (remove-list-of-text-properties
@@ -2761,6 +2900,20 @@ Possible choices are 
'ivy-magic-slash-non-match-cd-selected,
   (make-directory dir)
   (ivy--cd dir))
 
+(defun ivy--magic-file-doubleslash-directory ()
+  "Return an appropriate directory for when two slashes are entered."
+  (let (remote)
+    (cond
+      ;; Windows
+      ((string-match "\\`[[:alpha:]]:/" ivy--directory)
+       (match-string 0 ivy--directory))
+      ;; Remote root if on remote
+      ((setq remote (file-remote-p ivy--directory))
+       (concat remote "/"))
+      ;; Local root
+      (t
+       "/"))))
+
 (defun ivy--magic-file-slash ()
   "Handle slash when completing file names."
   (when (or (and (eq this-command #'self-insert-command)
@@ -2771,9 +2924,8 @@ Possible choices are 
'ivy-magic-slash-non-match-cd-selected,
       (cond ((member ivy-text ivy--all-candidates)
              (ivy--cd canonical))
             ((string-match-p "//\\'" ivy-text)
-             (ivy--cd (if (string-match "\\`[[:alpha:]]:/" default-directory)
-                          (match-string 0 default-directory)
-                        "/")))
+             (ivy--cd
+              (ivy--magic-file-doubleslash-directory)))
             ((string-match-p "\\`/ssh:" ivy-text)
              (ivy--cd (file-name-directory ivy-text)))
             ((string-match "[[:alpha:]]:/\\'" ivy-text)
@@ -2798,6 +2950,49 @@ Possible choices are 
'ivy-magic-slash-non-match-cd-selected,
                   magic)
              (ivy--create-and-cd canonical))))))
 
+(defun ivy-magic-read-file-env ()
+  "If reading filename, jump to environment variable location."
+  (interactive)
+  (if (and ivy--directory
+           (equal ivy-text ""))
+      (let* ((cands (cl-loop for pair in process-environment
+                       for (var val) = (split-string pair "=" t)
+                       if (and val (not (equal "" val)))
+                       if (file-exists-p
+                           (if (file-name-absolute-p val)
+                               val
+                             (setq val
+                                   (expand-file-name val ivy--directory))))
+                       collect (cons var val)))
+             (enable-recursive-minibuffers t)
+             (x (ivy-read "Env: " cands))
+             (path (cdr (assoc x cands))))
+        (insert (if (file-accessible-directory-p path)
+                    (file-name-as-directory path)
+                  path))
+        (ivy--cd-maybe))
+    (insert last-input-event)))
+
+(defun ivy-make-magic-action (caller key)
+  "Return a command that does the equivalent of `ivy-read-action' and KEY.
+This happens only when the input is empty.
+The intention is to bind the result to keys that are typically
+bound to `self-insert-command'."
+  (let* ((alist (assoc key
+                       (plist-get
+                        ivy--actions-list
+                        caller)))
+         (doc (format "%s (`%S')"
+                      (nth 2 alist)
+                      (nth 1 alist))))
+    `(lambda (&optional arg)
+       ,doc
+       (interactive "p")
+       (if (string= "" ivy-text)
+           (execute-kbd-macro
+            (kbd ,(concat "M-o " key)))
+         (self-insert-command arg)))))
+
 (defcustom ivy-magic-tilde t
   "When non-nil, ~ will move home when selecting files.
 Otherwise, ~/ will move home."
@@ -2824,6 +3019,14 @@ Should be run via minibuffer `post-command-hook'."
                'ivy--exhibit)))
     (ivy--exhibit)))
 
+(defun ivy--magic-tilde-directory ()
+  "Return an appropriate directory for when ~ or ~/ are entered."
+  (expand-file-name
+   (let (remote)
+     (if (setq remote (file-remote-p ivy--directory))
+         (concat remote "~/")
+       "~/"))))
+
 (defun ivy--exhibit ()
   "Insert Ivy completions display.
 Should be run via minibuffer `post-command-hook'."
@@ -2843,13 +3046,14 @@ Should be run via minibuffer `post-command-hook'."
               (setq ivy--old-text ivy-text)))
           (when (or ivy--all-candidates
                     (not (get-process " *counsel*")))
+            (ivy--set-index-dynamic-collection)
             (ivy--insert-minibuffer
              (ivy--format ivy--all-candidates))))
       (cond (ivy--directory
              (cond ((or (string= "~/" ivy-text)
                         (and (string= "~" ivy-text)
                              ivy-magic-tilde))
-                    (ivy--cd (expand-file-name "~/")))
+                    (ivy--cd (ivy--magic-tilde-directory)))
                    ((string-match "/\\'" ivy-text)
                     (ivy--magic-file-slash))))
             ((eq (ivy-state-collection ivy-last) #'internal-complete-buffer)
@@ -2883,14 +3087,14 @@ Should be run via minibuffer `post-command-hook'."
         deactivate-mark)
     (when win
       (with-selected-window win
-        (ivy--cleanup)
+        (ivy--minibuffer-cleanup)
         (when update-fn
           (funcall update-fn))
         (ivy--insert-prompt)
         ;; Do nothing if while-no-input was aborted.
         (when (stringp text)
-          (if ivy-display-function
-              (funcall ivy-display-function text)
+          (if ivy--display-function
+              (funcall ivy--display-function text)
             (ivy-display-function-fallback text)))
         (ivy--resize-minibuffer-to-fit)
         ;; prevent region growing due to text remove/add
@@ -2961,18 +3165,20 @@ In any Ivy completion session, the case folding starts 
with
 RE is a list of cons cells, with a regexp car and a boolean cdr.
 When the cdr is t, the car must match.
 Otherwise, the car must not match."
-  (ignore-errors
-    (dolist (re (if (stringp re) (list (cons re t)) re))
-      (let* ((re-str (car re))
-             (pred
-              (if mkpred
-                  (funcall mkpred re-str)
-                (lambda (x) (string-match-p re-str x)))))
-        (setq candidates
-              (cl-remove nil candidates
-                         (if (cdr re) :if-not :if)
-                         pred))))
-    candidates))
+  (if (equal re "")
+      candidates
+    (ignore-errors
+      (dolist (re (if (stringp re) (list (cons re t)) re))
+        (let* ((re-str (car re))
+               (pred
+                (if mkpred
+                    (funcall mkpred re-str)
+                  (lambda (x) (string-match-p re-str x)))))
+          (setq candidates
+                (cl-remove nil candidates
+                           (if (cdr re) :if-not :if)
+                           pred))))
+      candidates)))
 
 (defun ivy--filter (name candidates)
   "Return all items that match NAME in CANDIDATES.
@@ -2988,8 +3194,6 @@ CANDIDATES are assumed to be static."
              (matcher (ivy-state-matcher ivy-last))
              (case-fold-search (ivy--case-fold-p name))
              (cands (cond
-                      (matcher
-                       (funcall matcher re candidates))
                       ((and ivy--old-re
                             (stringp re)
                             (stringp ivy--old-re)
@@ -3000,17 +3204,19 @@ CANDIDATES are assumed to be static."
                                        (substring ivy--old-re 0 -2)
                                      ivy--old-re)
                                    re)
-                                  '(0 2)))
-                       (ignore-errors
-                         (cl-remove-if-not
-                          (lambda (x) (string-match-p re x))
-                          ivy--old-cands)))
+                                  '(0 2))
+                            ivy--old-cands
+                            (ivy--re-filter re ivy--old-cands)))
+                      (matcher
+                       (funcall matcher re candidates))
                       (t
                        (ivy--re-filter re candidates)))))
         (if (memq (cdr (assq (ivy-state-caller ivy-last)
                              ivy-index-functions-alist))
                   '(ivy-recompute-index-swiper
-                    ivy-recompute-index-swiper-async))
+                    ivy-recompute-index-swiper-async
+                    ivy-recompute-index-swiper-async-backward
+                    ivy-recompute-index-swiper-backward))
             (progn
               (ivy--recompute-index name re-str cands)
               (setq ivy--old-cands (ivy--sort name cands)))
@@ -3033,8 +3239,18 @@ CANDIDATES are assumed to be static."
                    res))))
     (setq ivy--all-candidates res)))
 
+(defun ivy--shorter-matches-first (_name cands)
+  "Sort CANDS according to their length."
+  (if (< (length cands) ivy-sort-max-size)
+      (cl-sort
+       (copy-sequence cands)
+       (lambda (s1 s2)
+         (< (length s1) (length s2))))
+    cands))
+
 (defcustom ivy-sort-matches-functions-alist
   '((t . nil)
+    (ivy-completion-in-region . ivy--shorter-matches-first)
     (ivy-switch-buffer . ivy-sort-function-buffer))
   "An alist of functions for sorting matching candidates.
 
@@ -3067,16 +3283,12 @@ The alist VAL is a sorting function with the signature 
of
 (defun ivy--sort (name candidates)
   "Re-sort candidates by NAME.
 All CANDIDATES are assumed to match NAME."
-  (let ((key (or (ivy-state-caller ivy-last)
-                 (when (functionp (ivy-state-collection ivy-last))
-                   (ivy-state-collection ivy-last))
-                 this-command))
-        fun)
-    (cond ((and ivy--flx-featurep
+  (let (fun)
+    (cond ((setq fun (ivy-alist-setting ivy-sort-matches-functions-alist))
+           (funcall fun name candidates))
+          ((and ivy--flx-featurep
                 (eq ivy--regex-function 'ivy--regex-fuzzy))
            (ivy--flx-sort name candidates))
-          ((setq fun (ivy-alist-setting ivy-sort-matches-functions-alist key))
-           (funcall fun name candidates))
           (t
            candidates))))
 
@@ -3120,20 +3332,22 @@ before substring matches."
           (= (aref name 0) ?^))
       candidates
     (let* ((base-re (ivy-re-to-str (funcall ivy--regex-function name)))
-           (re-prefix (concat "\\`\\*" base-re))
+           (re-star-prefix (concat "\\`\\*" base-re))
+           (re-prefix (concat "\\`" base-re))
            res-prefix
            res-noprefix
            res-virtual-prefix
            res-virtual-noprefix)
-      (unless (cl-find-if (lambda (s) (string-match-p re-prefix s)) candidates)
-        (setq re-prefix (concat "\\`" base-re)))
       (dolist (s candidates)
         (cond
-          ((and (assoc s ivy--virtual-buffers) (string-match-p re-prefix s))
+          ((and (assoc s ivy--virtual-buffers)
+                (or (string-match-p re-star-prefix s)
+                    (string-match-p re-prefix s)))
            (push s res-virtual-prefix))
           ((assoc s ivy--virtual-buffers)
            (push s res-virtual-noprefix))
-          ((string-match-p re-prefix s)
+          ((or (string-match-p re-star-prefix s)
+               (string-match-p re-prefix s))
            (push s res-prefix))
           (t
            (push s res-noprefix))))
@@ -3143,6 +3357,15 @@ before substring matches."
        (nreverse res-virtual-prefix)
        (nreverse res-virtual-noprefix)))))
 
+(defvar ivy-flx-limit 200
+  "Used to conditionally turn off flx sorting.
+
+When the amount of matching candidates exceeds this limit, then
+no sorting is done.")
+
+(defvar ivy--recompute-index-inhibit nil
+  "When non-nil, `ivy--recompute-index' is a no-op.")
+
 (defun ivy--recompute-index (name re-str cands)
   "Recompute index of selected candidate matching NAME.
 RE-STR is the regexp, CANDS are the current candidates."
@@ -3153,39 +3376,43 @@ RE-STR is the regexp, CANDS are the current candidates."
         (preselect (ivy-state-preselect ivy-last))
         (current (ivy-state-current ivy-last))
         (empty (string= name "")))
-    (unless (eq this-command 'ivy-resume)
+    (unless (or (memq this-command '(ivy-resume ivy-partial-or-done))
+                ivy--recompute-index-inhibit)
       (ivy-set-index
-       (or
-        (cl-position (ivy--remove-prefix "^" name)
-                     cands
-                     :test #'ivy--case-fold-string=)
-        (and ivy--directory
-             (cl-position (concat re-str "/")
-                          cands
-                          :test #'ivy--case-fold-string=))
-        (and (eq caller 'ivy-switch-buffer)
-             (not empty)
-             0)
-        (and (not empty)
-             (not (eq caller 'swiper))
-             (not (and ivy--flx-featurep
-                       (eq ivy--regex-function 'ivy--regex-fuzzy)
-                       ;; Limit to 200 candidates
-                       (null (nthcdr 200 cands))))
-             ;; If there was a preselected candidate, don't try to
-             ;; keep it selected even if the regexp still matches it.
-             ;; See issue #1563.  See also `ivy--preselect-index',
-             ;; which this logic roughly mirrors.
-             (not (or
-                   (and (integerp preselect)
-                        (= ivy--index preselect))
-                   (equal current preselect)
-                   (and (stringp preselect)
-                        (stringp current)
-                        (string-match-p preselect current))))
-             ivy--old-cands
-             (cl-position current cands :test #'equal))
-        (funcall func re-str cands))))
+       (if (or (string= name "")
+               (and (> (length cands) 10000) (eq func 
#'ivy-recompute-index-zero)))
+           0
+         (or
+          (cl-position (ivy--remove-prefix "^" name)
+                       cands
+                       :test #'ivy--case-fold-string=)
+          (and ivy--directory
+               (cl-position (concat re-str "/")
+                            cands
+                            :test #'ivy--case-fold-string=))
+          (and (eq caller 'ivy-switch-buffer)
+               (not empty)
+               0)
+          (and (not empty)
+               (not (eq caller 'swiper))
+               (not (and ivy--flx-featurep
+                         (eq ivy--regex-function 'ivy--regex-fuzzy)
+                         ;; Limit to configured number of candidates
+                         (null (nthcdr ivy-flx-limit cands))))
+               ;; If there was a preselected candidate, don't try to
+               ;; keep it selected even if the regexp still matches it.
+               ;; See issue #1563.  See also `ivy--preselect-index',
+               ;; which this logic roughly mirrors.
+               (not (or
+                     (and (integerp preselect)
+                          (= ivy--index preselect))
+                     (equal current preselect)
+                     (and (ivy--regex-p preselect)
+                          (stringp current)
+                          (string-match-p preselect current))))
+               ivy--old-cands
+               (cl-position current cands :test #'equal))
+          (funcall func re-str cands)))))
     (when (or empty (string= name "^"))
       (ivy-set-index
        (or (ivy--preselect-index preselect cands)
@@ -3218,6 +3445,16 @@ CANDS are the current candidates."
               res))))
     (error 0)))
 
+(defun ivy-recompute-index-swiper-backward (re-str cands)
+  "Recompute index of selected candidate when using `swiper-backward'.
+CANDS are the current candidates."
+  (let ((idx (ivy-recompute-index-swiper re-str cands)))
+    (if (or (= idx -1)
+            (<= (read (get-text-property 0 'swiper-line-number (nth idx 
cands)))
+                (line-number-at-pos)))
+        idx
+      (- idx 1))))
+
 (defun ivy-recompute-index-swiper-async (_re-str cands)
   "Recompute index of selected candidate when using `swiper' asynchronously.
 CANDS are the current candidates."
@@ -3242,6 +3479,18 @@ CANDS are the current candidates."
             (or idx 0))
         ivy--index))))
 
+(defun ivy-recompute-index-swiper-async-backward (re-str cands)
+  "Recompute index of selected candidate when using `swiper-backward'
+asynchronously. CANDS are the current candidates."
+  (if (= (length cands) 0)
+      0
+    (let ((idx (ivy-recompute-index-swiper-async re-str cands)))
+      (if
+          (<= (string-to-number (nth idx cands))
+              (with-ivy-window (line-number-at-pos)))
+          idx
+        (- idx 1)))))
+
 (defun ivy-recompute-index-zero (_re-str _cands)
   "Recompute index of selected candidate.
 This function serves as a fallback when nothing else is available."
@@ -3261,12 +3510,6 @@ This function serves as a fallback when nothing else is 
available."
            (const ivy-minibuffer-match-face-4)
            (face :tag "Other face"))))
 
-(defvar ivy-flx-limit 200
-  "Used to conditionally turn off flx sorting.
-
-When the amount of matching candidates exceeds this limit, then
-no sorting is done.")
-
 (defun ivy--minibuffer-face (n)
   "Return Nth face from `ivy-minibuffer-faces'.
 N wraps around, but skips the first element of the list."
@@ -3425,32 +3668,35 @@ Note: The usual last two arguments are flipped for 
convenience.")
   "Highlight STR, using the default method."
   (unless ivy--old-re
     (setq ivy--old-re (funcall ivy--regex-function ivy-text)))
-  (let ((start
-         (if (and (memq (ivy-state-caller ivy-last) 
ivy-highlight-grep-commands)
-                  (string-match "\\`[^:]+:[^:]+:" str))
-             (match-end 0)
-           0))
-        (regexps
+  (let ((regexps
          (if (listp ivy--old-re)
              (mapcar #'car (cl-remove-if-not #'cdr ivy--old-re))
-           (list ivy--old-re))))
+           (list ivy--old-re)))
+        start)
     (dolist (re regexps)
       (ignore-errors
         (while (and (string-match re str start)
                     (> (- (match-end 0) (match-beginning 0)) 0))
           (setq start (match-end 0))
-          (let ((i 0))
+          (let ((i 0)
+                (n 0)
+                prev)
             (while (<= i ivy--subexps)
-              (let ((face
-                     (cond ((zerop ivy--subexps)
-                            (cadr ivy-minibuffer-faces))
-                           ((zerop i)
-                            (car ivy-minibuffer-faces))
-                           (t
-                            (ivy--minibuffer-face i)))))
-                (ivy-add-face-text-property
-                 (match-beginning i) (match-end i)
-                 face str))
+              (let ((beg (match-beginning i))
+                    (end (match-end i)))
+                (when (and beg end)
+                  (unless (and prev (= prev beg))
+                    (cl-incf n))
+                  (let ((face
+                         (cond ((zerop ivy--subexps)
+                                (cadr ivy-minibuffer-faces))
+                               ((zerop i)
+                                (car ivy-minibuffer-faces))
+                               (t
+                                (ivy--minibuffer-face n)))))
+                    (ivy-add-face-text-property beg end face str))
+                  (unless (zerop i)
+                    (setq prev end))))
               (cl-incf i)))))))
   str)
 
@@ -3458,7 +3704,14 @@ Note: The usual last two arguments are flipped for 
convenience.")
   "Format line STR for use in minibuffer."
   (let* ((str (ivy-cleanup-string (copy-sequence str)))
          (str (if (eq ivy-display-style 'fancy)
-                  (funcall ivy--highlight-function str)
+                  (if (memq (ivy-state-caller ivy-last)
+                            ivy-highlight-grep-commands)
+                      (let* ((start (if (string-match "\\`[^:]+:[^:]+:" str)
+                                        (match-end 0) 0))
+                             (file (substring str 0 start))
+                             (match (substring str start)))
+                        (concat file (funcall ivy--highlight-function match)))
+                    (funcall ivy--highlight-function str))
                 str))
          (olen (length str))
          (annot (plist-get completion-extra-properties :annotation-function)))
@@ -3482,6 +3735,8 @@ Note: The usual last two arguments are flipped for 
convenience.")
 (ivy-set-display-transformer
  'counsel-find-file 'ivy-read-file-transformer)
 (ivy-set-display-transformer
+ 'counsel-dired 'ivy-read-file-transformer)
+(ivy-set-display-transformer
  'read-file-name-internal 'ivy-read-file-transformer)
 
 (defun ivy-read-file-transformer (str)
@@ -3490,6 +3745,14 @@ Note: The usual last two arguments are flipped for 
convenience.")
       (propertize str 'face 'ivy-subdir)
     str))
 
+(defun ivy--minibuffer-index-bounds (idx len wnd-len)
+  (let* ((half-height (/ wnd-len 2))
+         (start (max 0
+                     (min (- idx half-height)
+                          (- len (1- wnd-len)))))
+         (end (min (+ start (1- wnd-len)) len)))
+    (list start end (- idx start))))
+
 (defun ivy--format (cands)
   "Return a string for CANDS suitable for display in the minibuffer.
 CANDS is a list of strings."
@@ -3498,14 +3761,15 @@ CANDS is a list of strings."
     (ivy-set-index (max (1- ivy--length) 0)))
   (if (null cands)
       (setf (ivy-state-current ivy-last) "")
-    (setf (ivy-state-current ivy-last) (copy-sequence (nth ivy--index cands)))
-    (let* ((half-height (/ ivy-height 2))
-           (start (max 0 (- ivy--index half-height)))
-           (end (min (+ start (1- ivy-height)) ivy--length))
-           (start (max 0 (min start (- end (1- ivy-height)))))
-           (wnd-cands (cl-subseq cands start end))
+    (let ((cur (nth ivy--index cands)))
+      (setf (ivy-state-current ivy-last) (if (stringp cur)
+                                             (copy-sequence cur)
+                                           cur)))
+    (let* ((bnd (ivy--minibuffer-index-bounds
+                 ivy--index ivy--length ivy-height))
+           (wnd-cands (cl-subseq cands (car bnd) (cadr bnd)))
            transformer-fn)
-      (setq ivy--window-index (- ivy--index start))
+      (setq ivy--window-index (nth 2 bnd))
       (when (setq transformer-fn (ivy-state-display-transformer-fn ivy-last))
         (with-ivy-window
           (with-current-buffer (ivy-state-buffer ivy-last)
@@ -3514,10 +3778,12 @@ CANDS is a list of strings."
 
 (defun ivy--wnd-cands-to-str (wnd-cands)
   (let ((str (concat "\n"
-                     (funcall ivy-format-function
-                              (mapcar
-                               #'ivy--format-minibuffer-line
-                               wnd-cands)))))
+                     (funcall (ivy-alist-setting ivy-format-functions-alist)
+                              (condition-case nil
+                                  (mapcar
+                                   #'ivy--format-minibuffer-line
+                                   wnd-cands)
+                                (error wnd-cands))))))
     (put-text-property 0 (length str) 'read-only nil str)
     str))
 
@@ -3729,26 +3995,32 @@ Use `ivy-pop-view' to delete any item from `ivy-views'."
          (let* ((wnd1 (selected-window))
                 (wnd2 (split-window-vertically))
                 (views (cdr view))
-                (v (pop views)))
+                (v (pop views))
+                (temp-wnd))
            (with-selected-window wnd1
              (ivy-set-view-recur v))
            (while (setq v (pop views))
              (with-selected-window wnd2
-               (ivy-set-view-recur v))
-             (when views
-               (setq wnd2 (split-window-vertically))))))
+               (when views
+                 (setq temp-wnd (split-window-vertically)))
+               (ivy-set-view-recur v)
+               (when views
+                 (setq wnd2 temp-wnd))))))
         ((eq (car view) 'horz)
          (let* ((wnd1 (selected-window))
                 (wnd2 (split-window-horizontally))
                 (views (cdr view))
-                (v (pop views)))
+                (v (pop views))
+                (temp-wnd))
            (with-selected-window wnd1
              (ivy-set-view-recur v))
            (while (setq v (pop views))
              (with-selected-window wnd2
-               (ivy-set-view-recur v))
-             (when views
-               (setq wnd2 (split-window-horizontally))))))
+               (when views
+                 (setq temp-wnd (split-window-horizontally)))
+               (ivy-set-view-recur v)
+               (when views
+                 (setq wnd2 temp-wnd))))))
         ((eq (car view) 'file)
          (let* ((name (nth 1 view))
                 (virtual (assoc name ivy--virtual-buffers))
@@ -3810,9 +4082,12 @@ BUFFER may be a string or nil."
 
 (defun ivy--find-file-action (buffer)
   "Find file from BUFFER's directory."
-  (let ((default-directory (buffer-local-value 'default-directory
-                                               (or (get-buffer buffer)
-                                                   (current-buffer)))))
+  (let* ((virtual (assoc buffer ivy--virtual-buffers))
+         (default-directory (if virtual
+                                (file-name-directory (cdr virtual))
+                              (buffer-local-value 'default-directory
+                                                  (or (get-buffer buffer)
+                                                      (current-buffer))))))
     (call-interactively (if (functionp 'counsel-find-file)
                             #'counsel-find-file
                           #'find-file))))
@@ -3824,31 +4099,34 @@ BUFFER may be a string or nil."
                         (cdr (assoc buffer ivy--virtual-buffers))
                         recentf-list))))
 
+(defun ivy--kill-current-candidate ()
+  (setf (ivy-state-preselect ivy-last) ivy--index)
+  (setq ivy--old-re nil)
+  (setq ivy--all-candidates (delete (ivy-state-current ivy-last) 
ivy--all-candidates))
+  (let ((ivy--recompute-index-inhibit t))
+    (ivy--exhibit)))
+
 (defun ivy--kill-buffer-action (buffer)
   "Kill BUFFER."
   (ivy--kill-buffer-or-virtual buffer)
   (unless (buffer-live-p (ivy-state-buffer ivy-last))
-    (setf (ivy-state-buffer ivy-last) (current-buffer)))
-  (setq ivy--index 0)
-  (ivy--reset-state ivy-last))
+    (setf (ivy-state-buffer ivy-last)
+          (with-ivy-window (current-buffer))))
+  (ivy--kill-current-candidate))
 
 (defvar ivy-switch-buffer-map
   (let ((map (make-sparse-keymap)))
-    (define-key map (kbd "C-c C-k") 'ivy-switch-buffer-kill)
+    (define-key map (kbd "C-k") 'ivy-switch-buffer-kill)
     map))
 
 (defun ivy-switch-buffer-kill ()
-  "Kill the current buffer in `ivy-switch-buffer'."
+  "When at end-of-line, kill the current buffer in `ivy-switch-buffer'.
+Otherwise, forward to `ivy-kill-line'."
   (interactive)
-  (let ((bn (ivy-state-current ivy-last)))
-    (ivy--kill-buffer-or-virtual bn)
-    (unless (buffer-live-p (ivy-state-buffer ivy-last))
-      (setf (ivy-state-buffer ivy-last)
-            (with-ivy-window (current-buffer))))
-    (setf (ivy-state-preselect ivy-last) ivy--index)
-    (setq ivy--old-re nil)
-    (setq ivy--all-candidates (delete bn ivy--all-candidates))
-    (ivy--exhibit)))
+  (if (not (eolp))
+      (ivy-kill-line)
+    (ivy--kill-buffer-action
+     (ivy-state-current ivy-last))))
 
 (ivy-set-actions
  'ivy-switch-buffer
@@ -3915,7 +4193,13 @@ Skip buffers that match `ivy-ignore-buffers'."
 
 (defun ivy-switch-buffer-occur ()
   "Occur function for `ivy-switch-buffer' using `ibuffer'."
-  (ibuffer nil (buffer-name) (list (cons 'name ivy--old-re))))
+  (ibuffer
+   nil (buffer-name)
+   `((or ,@(cl-mapcan
+            (lambda (cand)
+              (unless (eq (get-text-property 0 'face cand) 'ivy-virtual)
+                `((name . ,(format "\\_<%s\\_>" (regexp-quote cand))))))
+            ivy--old-cands)))))
 
 ;;;###autoload
 (defun ivy-switch-buffer ()
@@ -4054,13 +4338,19 @@ If the region is active, forward to `kill-ring-save' 
instead."
 Don't finish completion."
   (interactive)
   (delete-minibuffer-contents)
-  (if (and ivy--directory
-           (ivy--dirname-p (ivy-state-current ivy-last)))
-      (insert (substring (ivy-state-current ivy-last) 0 -1))
-    (insert (ivy-state-current ivy-last))))
+  (let ((end (and ivy--directory
+                  (ivy--dirname-p (ivy-state-current ivy-last))
+                  -1)))
+    (insert (substring-no-properties
+             (ivy-state-current ivy-last) 0 end))))
+
+(defun ivy-insert-current-full ()
+  "Insert the full Yank the current directory into the minibuffer."
+  (interactive)
+  (insert ivy--directory))
 
 (define-obsolete-variable-alias 'ivy--preferred-re-builders
-    'ivy-preferred-re-builders "0.10.0")
+  'ivy-preferred-re-builders "0.10.0")
 
 (defcustom ivy-preferred-re-builders
   '((ivy--regex-plus . "ivy")
@@ -4088,22 +4378,70 @@ This list can be rotated with 
`ivy-rotate-preferred-builders'."
       (setq ivy--regex-function 'ivy--regex-plus)
     (setq ivy--regex-function 'ivy--regex-fuzzy)))
 
+(defvar ivy--reverse-i-search-symbol nil
+  "Store the history symbol.")
+
+(defun ivy-reverse-i-search-kill ()
+  "Remove the current item from history"
+  (interactive)
+  (if (not (eolp))
+      (ivy-kill-line)
+    (let ((current (ivy-state-current ivy-last)))
+      (if (symbolp ivy--reverse-i-search-symbol)
+          (set
+           ivy--reverse-i-search-symbol
+           (delete current (symbol-value ivy--reverse-i-search-symbol)))
+        (ring-remove
+         ivy--reverse-i-search-symbol
+         (ring-member ivy--reverse-i-search-symbol (ivy-state-current 
ivy-last)))))
+    (ivy--kill-current-candidate)))
+
+(defvar ivy-reverse-i-search-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map (kbd "C-k") 'ivy-reverse-i-search-kill)
+    map))
+
+(defun ivy-history-contents (sym-or-ring)
+  "Copy contents of SYM-OR-RING.
+A copy is necessary so that we don't clobber any string attributes.
+Also set `ivy--reverse-i-search-symbol' to SYM-OR-RING."
+  (setq ivy--reverse-i-search-symbol sym-or-ring)
+  (cond ((symbolp sym-or-ring)
+         (delete-dups
+          (copy-sequence (symbol-value sym-or-ring))))
+        ((ring-p sym-or-ring)
+         (delete-dups
+          (when (> (ring-size sym-or-ring) 0)
+            (ring-elements sym-or-ring))))
+        (t
+         (error "Expected a symbol or a ring: %S" sym-or-ring))))
+
 (defun ivy-reverse-i-search ()
   "Enter a recursive `ivy-read' session using the current history.
-The selected history element will be inserted into the minibuffer."
+The selected history element will be inserted into the minibuffer.
+\\<ivy-reverse-i-search-map>
+You can also delete an element from history with 
\\[ivy-reverse-i-search-kill]."
   (interactive)
-  (let ((enable-recursive-minibuffers t)
-        (history (symbol-value (ivy-state-history ivy-last)))
-        (old-last ivy-last)
-        (ivy-recursive-restore nil))
-    (ivy-read "Reverse-i-search: "
-              (delete-dups (copy-sequence history))
-              :action (lambda (x)
-                        (ivy--reset-state
-                         (setq ivy-last old-last))
-                        (delete-minibuffer-contents)
-                        (insert (substring-no-properties x))
-                        (ivy--cd-maybe)))))
+  (cond
+    ((= (minibuffer-depth) 0)
+     (user-error
+      "This command is intended to be called with \"C-r\" from `ivy-read'."))
+    ;; don't recur
+    ((and (> (minibuffer-depth) 1)
+          (eq (ivy-state-caller ivy-last) 'ivy-reverse-i-search)))
+    (t
+     (let ((enable-recursive-minibuffers t)
+           (old-last ivy-last))
+       (ivy-read "Reverse-i-search: "
+                 (ivy-history-contents (ivy-state-history ivy-last))
+                 :keymap ivy-reverse-i-search-map
+                 :action (lambda (x)
+                           (ivy--reset-state
+                            (setq ivy-last old-last))
+                           (delete-minibuffer-contents)
+                           (insert (substring-no-properties x))
+                           (ivy--cd-maybe))
+                 :caller 'ivy-reverse-i-search)))))
 
 (defun ivy-restrict-to-matches ()
   "Restrict candidates to current input and erase input."
@@ -4247,21 +4585,23 @@ When `ivy-calling' isn't nil, call `ivy-occur-press'."
 (defun ivy--occur-insert-lines (cands)
   "Insert CANDS into `ivy-occur' buffer."
   (font-lock-mode -1)
-  (dolist (str cands)
-    (setq str (ivy--highlight-fuzzy (copy-sequence str)))
+  (dolist (cand cands)
+    (setq cand
+          (if (string-match "\\`\\(.*:[0-9]+:\\)\\(.*\\)\\'" cand)
+              (let ((file-and-line (match-string 1 cand))
+                    (grep-line (match-string 2 cand)))
+                (concat
+                 (propertize file-and-line 'face 'ivy-grep-info)
+                 (ivy--highlight-fuzzy grep-line)))
+            (ivy--highlight-fuzzy (copy-sequence cand))))
     (add-text-properties
-     0 (length str)
+     0 (length cand)
      '(mouse-face
        highlight
        help-echo "mouse-1: call ivy-action")
-     str)
-    (insert (if (string-match-p "\\`.[/\\]" str) "" "    ")
-            str ?\n))
-  (goto-char (point-min))
-  (forward-line 4)
-  (while (re-search-forward "^.*:[[:digit:]]+:" nil t)
-    (ivy-add-face-text-property
-     (match-beginning 0) (match-end 0) 'ivy-grep-info nil t)))
+     cand)
+    (insert (if (string-match-p "\\`.[/\\]" cand) "" "    ")
+            cand ?\n)))
 
 (defun ivy-occur ()
   "Stop completion and put the current candidates into a new buffer.
@@ -4295,8 +4635,7 @@ There is no limit on the number of *ivy-occur* buffers."
             (ivy--occur-insert-lines
              ivy--old-cands)))
         (setf (ivy-state-text ivy-last) ivy-text)
-        (setq ivy-occur-last ivy-last)
-        (setq-local ivy--directory ivy--directory))
+        (setq ivy-occur-last ivy-last))
       (ivy-exit-with-action
        (lambda (_) (pop-to-buffer buffer))))))
 
@@ -4312,7 +4651,7 @@ updated original buffer."
   (interactive)
   (let ((caller (ivy-state-caller ivy-occur-last))
         (ivy-last ivy-occur-last))
-    (cond ((eq caller 'swiper)
+    (cond ((member caller '(swiper swiper-isearch))
            (let ((buffer (ivy-state-buffer ivy-occur-last)))
              (unless (buffer-live-p buffer)
                (error "Buffer was killed"))
@@ -4321,9 +4660,12 @@ updated original buffer."
                (funcall (plist-get ivy--occurs-list caller) t)
                (ivy-occur-grep-mode))))
           ((memq caller '(counsel-git-grep counsel-grep counsel-ag counsel-rg))
-           (let ((inhibit-read-only t))
+           (let ((inhibit-read-only t)
+                 (line (line-number-at-pos)))
              (erase-buffer)
-             (funcall (plist-get ivy--occurs-list caller)))))
+             (funcall (plist-get ivy--occurs-list caller))
+             (goto-char (point-min))
+             (forward-line (1- line)))))
     (setq ivy-occur-last ivy-last)))
 
 (declare-function wgrep-change-to-wgrep-mode "ext:wgrep")
@@ -4371,15 +4713,19 @@ EVENT gives the mouse position."
 
 (defun ivy--occur-press-update-window ()
   (cl-case (ivy-state-caller ivy-occur-last)
-    ((swiper counsel-git-grep counsel-grep counsel-ag counsel-rg)
+    ((swiper swiper-isearch counsel-git-grep counsel-grep counsel-ag 
counsel-rg)
      (let ((window (ivy-state-window ivy-occur-last))
            (buffer (ivy-state-buffer ivy-occur-last)))
-       (when (and (or (not (window-live-p window))
-                      (equal window (selected-window)))
-                  (buffer-live-p buffer))
-         (save-selected-window
-           (setf (ivy-state-window ivy-occur-last)
-                 (display-buffer buffer))))))
+       (if (not (buffer-live-p buffer))
+           (error "Buffer was killed")
+         (cond ((or (not (window-live-p window))
+                    (equal window (selected-window)))
+                (save-selected-window
+                  (setf (ivy-state-window ivy-occur-last)
+                        (display-buffer buffer))))
+               ((not (equal (window-buffer window) buffer))
+                (with-selected-window window
+                  (switch-to-buffer buffer)))))))
 
     ((counsel-describe-function counsel-describe-variable)
      (setf (ivy-state-window ivy-occur-last)
@@ -4404,19 +4750,23 @@ EVENT gives the mouse position."
            (str (buffer-substring
                  (match-beginning 1)
                  (match-end 1)))
+           (offset (or (get-text-property 0 'offset str) 0))
            (coll (ivy-state-collection ivy-last))
            (action (ivy--get-action ivy-last))
            (ivy-exit 'done))
       (with-ivy-window
         (setq counsel-grep-last-line nil)
         (with-current-buffer (ivy--occur-press-buffer)
-          (funcall action
-                   (if (and (consp coll)
-                            (consp (car coll)))
-                       (assoc str coll)
-                     str)))
+          (save-restriction
+            (widen)
+            (funcall action
+                     (if (and (consp coll)
+                              (consp (car coll)))
+                         (assoc str coll)
+                       (substring str offset)))))
         (if (memq (ivy-state-caller ivy-last)
-                  '(swiper counsel-git-grep counsel-grep counsel-ag 
counsel-rg))
+                  '(swiper swiper-isearch
+                    counsel-git-grep counsel-grep counsel-ag counsel-rg))
             (with-current-buffer (window-buffer (selected-window))
               (swiper--cleanup)
               (swiper--add-overlays
@@ -4435,6 +4785,60 @@ EVENT gives the mouse position."
   (ivy-occur-press)
   (select-window (ivy--get-window ivy-occur-last)))
 
+(defun ivy--marked-p ()
+  (member (ivy-state-current ivy-last) ivy-marked-candidates))
+
+(defun ivy--unmark (cand)
+  (setcar (member cand ivy--all-candidates)
+          (setcar (member cand ivy--old-cands)
+                  (substring cand (length ivy-mark-prefix))))
+  (setq ivy-marked-candidates
+        (delete cand ivy-marked-candidates)))
+
+(defun ivy--mark (cand)
+  (let ((marked-cand (concat ivy-mark-prefix cand)))
+    (setcar (member cand ivy--all-candidates)
+            (setcar (member cand ivy--old-cands) marked-cand))
+    (setq ivy-marked-candidates
+          (append ivy-marked-candidates (list marked-cand)))))
+
+(defun ivy-mark ()
+  "Mark the selected candidate and move to the next one.
+
+In `ivy-call', :action will be called in turn for all marked
+candidates.
+
+However, if :multi-action was supplied to `ivy-read', then it
+will be called with `ivy-marked-candidates'. This way, it can
+make decisions based on the whole marked list."
+  (interactive)
+  (unless (ivy--marked-p)
+    (ivy--mark (ivy-state-current ivy-last)))
+  (ivy-next-line))
+
+(defun ivy-unmark ()
+  "Unmark the selected candidate and move to the next one."
+  (interactive)
+  (when (ivy--marked-p)
+    (ivy--unmark (ivy-state-current ivy-last)))
+  (ivy-next-line))
+
+(defun ivy-unmark-backward ()
+  "Move to the previous candidate and unmark it."
+  (interactive)
+  (ivy-previous-line)
+  (ivy--exhibit)
+  (when (ivy--marked-p)
+    (ivy--unmark (ivy-state-current ivy-last))))
+
+(defun ivy-toggle-marks ()
+  "Toggle mark for all narrowed candidates."
+  (interactive)
+  (dolist (cand ivy--old-cands)
+    (if (member cand ivy-marked-candidates)
+        (ivy--unmark cand)
+      (ivy--mark cand))))
+
 (defconst ivy-help-file (let ((default-directory
                                (if load-file-name
                                    (file-name-directory load-file-name)
@@ -4445,6 +4849,8 @@ EVENT gives the mouse position."
                                 (expand-file-name "doc/ivy-help.org"))))
   "The file for `ivy-help'.")
 
+(defvar org-hide-emphasis-markers)
+
 (defun ivy-help ()
   "Help for `ivy'."
   (interactive)
@@ -4454,8 +4860,11 @@ EVENT gives the mouse position."
       (with-current-buffer buf
         (insert-file-contents ivy-help-file)
         (org-mode)
+        (setq-local org-hide-emphasis-markers t)
         (view-mode)
-        (goto-char (point-min))))
+        (goto-char (point-min))
+        (let ((inhibit-message t))
+          (org-cycle '(64)))))
     (if (eq this-command 'ivy-help)
         (switch-to-buffer buf)
       (with-ivy-window
diff --git a/packages/ivy/ivy.info b/packages/ivy/ivy.info
new file mode 100644
index 0000000..80263fd
--- /dev/null
+++ b/packages/ivy/ivy.info
@@ -0,0 +1,1930 @@
+This is ivy.info, produced by makeinfo version 6.5 from ivy.texi.
+
+Ivy manual, version 0.11.0
+
+   Ivy is an interactive interface for completion in Emacs.  Emacs uses
+completion mechanism in a variety of contexts: code, menus, commands,
+variables, functions, etc.  Completion entails listing, sorting,
+filtering, previewing, and applying actions on selected items.  When
+active, ‘ivy-mode’ completes the selection process by narrowing
+available choices while previewing in the minibuffer.  Selecting the
+final candidate is either through simple keyboard character inputs or
+through powerful regular expressions.
+
+   Copyright (C) 2015-2018 Free Software Foundation, Inc.
+
+     Permission is granted to copy, distribute and/or modify this
+     document under the terms of the GNU Free Documentation License,
+     Version 1.3 or any later version published by the Free Software
+     Foundation; with no Invariant Sections, with the Front-Cover Texts
+     being “A GNU Manual,” and with the Back-Cover Texts as in (a)
+     below.  A copy of the license is included in the section entitled
+     “GNU Free Documentation License.”
+
+     (a) The FSF’s Back-Cover Text is: “You have the freedom to copy and
+     modify this GNU manual.”
+INFO-DIR-SECTION Emacs
+START-INFO-DIR-ENTRY
+* Ivy: (ivy).           Using Ivy for completion.
+END-INFO-DIR-ENTRY
+
+
+File: ivy.info,  Node: Top,  Next: Introduction,  Up: (dir)
+
+Ivy User Manual
+***************
+
+* Menu:
+
+* Introduction::
+* Installation::
+* Getting started::
+* Key bindings::
+* Completion Styles::
+* Customization::
+* Commands::
+* API::
+* Variable Index::
+* Keystroke Index::
+
+— The Detailed Node Listing —
+
+Installation
+
+* Installing from Emacs Package Manager::
+* Installing from the Git repository::
+
+Getting started
+
+* Basic customization::
+
+Key bindings
+
+* Global key bindings::
+* Minibuffer key bindings::
+
+Minibuffer key bindings
+
+* Key bindings for navigation::
+* Key bindings for single selection, action, then exit minibuffer: Key 
bindings for single selection action then exit minibuffer.
+* Key bindings for multiple selections and actions, keep minibuffer open: Key 
bindings for multiple selections and actions keep minibuffer open.
+* Key bindings that alter the minibuffer input::
+* Other key bindings::
+* Hydra in the minibuffer::
+* Saving the current completion session to a buffer::
+
+Completion Styles
+
+* ivy--regex-plus::
+* ivy--regex-ignore-order::
+* ivy--regex-fuzzy::
+
+Customization
+
+* Faces::
+* Defcustoms::
+* Actions::
+* Packages::
+
+Actions
+
+* What are actions?::
+* How can different actions be called?::
+* How to modify the actions list?::
+* Example - add two actions to each command::
+* Example - define a new command with several actions::
+
+Example - add two actions to each command
+
+* How to undo adding the two actions::
+* How to add actions to a specific command::
+
+Example - define a new command with several actions
+
+* Test the above function with ivy-occur::
+
+Commands
+
+* File Name Completion::
+* Buffer Name Completion::
+* Counsel commands::
+
+File Name Completion
+
+* Using TRAMP::
+
+API
+
+* Required arguments for ivy-read::
+* Optional arguments for ivy-read::
+* Example - counsel-describe-function::
+* Example - counsel-locate::
+* Example - ivy-read-with-extra-properties::
+
+
+
+File: ivy.info,  Node: Introduction,  Next: Installation,  Prev: Top,  Up: Top
+
+1 Introduction
+**************
+
+Ivy is for quick and easy selection from a list.  When Emacs prompts for
+a string from a list of several possible choices, Ivy springs into
+action to assist in narrowing and picking the right string from a vast
+number of choices.
+
+   Ivy strives for minimalism, simplicity, customizability and
+discoverability.
+
+Minimalism
+..........
+
+     Uncluttered minibuffer is minimalism.  Ivy shows the completion
+     defaults, the number of matches, and 10 candidate matches below the
+     input line.  Customize ‘ivy-height’ to adjust the number of
+     candidate matches displayed in the minibuffer.
+
+Simplicity
+..........
+
+     Simplicity is about Ivy’s behavior in the minibuffer.  It is also
+     about the code interface to extend Ivy’s functionality.  The
+     minibuffer area behaves as close to ‘fundamental-mode’ as possible.
+     ‘SPC’ inserts a space, for example, instead of being bound to the
+     more complex ‘minibuffer-complete-word’.  Ivy’s code uses
+     easy-to-examine global variables; avoids needless complications
+     with branch-introducing custom macros.
+
+Customizability
+...............
+
+     Customizability is about being able to use different methods and
+     interfaces of completion to tailor the selection process.  For
+     example, adding a custom display function that points to a selected
+     candidate with ‘>’, instead of highlighting the selected candidate
+     with the ‘ivy-current-match’ face (see
+     ‘ivy-format-functions-alist’).  Or take the customization of
+     actions, say after the candidate function is selected.  ‘RET’ uses
+     ‘counsel-describe-function’ to describe the function, whereas ‘M-o
+     d’ jumps to that function’s definition in the code.  The ‘M-o’
+     prefix can be uniformly used with characters like ‘d’ to group
+     similar actions.
+
+Discoverability
+...............
+
+     Ivy displays easily discoverable commands through the hydra
+     facility.  ‘C-o’ in the minibuffer displays a hydra menu.  It opens
+     up within an expanded minibuffer area.  Each menu item comes with
+     short documentation strings and highlighted one-key completions.
+     So discovering even seldom used keys is simply a matter of ‘C-o’ in
+     the minibuffer while in the midst of the Ivy interaction.  This
+     discoverability minimizes exiting Ivy interface for documentation
+     look-ups.
+
+
+File: ivy.info,  Node: Installation,  Next: Getting started,  Prev: 
Introduction,  Up: Top
+
+2 Installation
+**************
+
+Install Ivy automatically through Emacs’s package manager, or manually
+from Ivy’s development repository.
+
+   Emacs 24.3 is the oldest version to run Ivy.  Emacs 24.4 is the
+oldest version that runs Ivy with fancy faces display.
+
+* Menu:
+
+* Installing from Emacs Package Manager::
+* Installing from the Git repository::
+
+
+File: ivy.info,  Node: Installing from Emacs Package Manager,  Next: 
Installing from the Git repository,  Up: Installation
+
+2.1 Installing from Emacs Package Manager
+=========================================
+
+‘M-x’ ‘package-install’ ‘RET’ ‘ivy’ ‘RET’
+
+   Ivy is installed as part of ‘ivy’ package, which is available from
+two different package archives, GNU ELPA and MELPA. For the latest
+stable version, use the GNU ELPA archives using the above M-x command.
+
+   For current hourly builds, use the MELPA archives.  In MELPA, Ivy is
+split into three packages: ‘ivy’, ‘swiper’ and ‘counsel’; you can simply
+install ‘counsel’ which will bring in the other two as dependencies.
+See the code below for adding MELPA to the list of package archives:
+
+     (require 'package)
+     (add-to-list 'package-archives
+            '("melpa" . "https://melpa.org/packages/";))
+
+   After this do ‘M-x’ ‘package-refresh-contents’ ‘RET’, followed by
+‘M-x’ ‘package-install’ ‘RET’ ‘counsel’ ‘RET’.
+
+   For package manager details, see *note (emacs)Packages::.
+
+
+File: ivy.info,  Node: Installing from the Git repository,  Prev: Installing 
from Emacs Package Manager,  Up: Installation
+
+2.2 Installing from the Git repository
+======================================
+
+Why install from Git?
+.....................
+
+        • No need to wait for MELPA’s hourly builds
+        • Easy to revert to previous versions
+        • Contribute to Ivy’s development; send patches; pull requests
+
+Configuration steps
+...................
+
+     First clone the Swiper repository with:
+
+          cd ~/git && git clone https://github.com/abo-abo/swiper
+          cd swiper && make compile
+
+     Second, add these lines to the Emacs init file:
+
+          (add-to-list 'load-path "~/git/swiper/")
+          (require 'ivy)
+
+     Then, update the code with:
+
+          git pull
+          make
+
+
+File: ivy.info,  Node: Getting started,  Next: Key bindings,  Prev: 
Installation,  Up: Top
+
+3 Getting started
+*****************
+
+First enable Ivy completion everywhere:
+
+     (ivy-mode 1)
+
+   Note: ‘ivy-mode’ can be toggled on and off with ‘M-x’ ‘ivy-mode’.
+
+* Menu:
+
+* Basic customization::
+
+
+File: ivy.info,  Node: Basic customization,  Up: Getting started
+
+3.1 Basic customization
+=======================
+
+Here are some basic settings particularly useful for new Ivy users:
+
+     (setq ivy-use-virtual-buffers t)
+     (setq ivy-count-format "(%d/%d) ")
+
+   If you want, you can go without any customizations at all.  The above
+settings are the most bang for the buck in terms of customization.  So
+users that typically don’t like customize a lot are advised to look at
+these settings first.
+
+   For more advanced customizations, refer to ‘M-x describe-variable’
+documentation.
+
+
+File: ivy.info,  Node: Key bindings,  Next: Completion Styles,  Prev: Getting 
started,  Up: Top
+
+4 Key bindings
+**************
+
+* Menu:
+
+* Global key bindings::
+* Minibuffer key bindings::
+
+
+File: ivy.info,  Node: Global key bindings,  Next: Minibuffer key bindings,  
Up: Key bindings
+
+4.1 Global key bindings
+=======================
+
+Here is a list of commands that are useful to be bound globally, along
+with some sample bindings:
+
+Ivy-based interface to standard commands
+........................................
+
+          (global-set-key (kbd "C-s") 'swiper)
+          (global-set-key (kbd "M-x") 'counsel-M-x)
+          (global-set-key (kbd "C-x C-f") 'counsel-find-file)
+          (global-set-key (kbd "<f1> f") 'counsel-describe-function)
+          (global-set-key (kbd "<f1> v") 'counsel-describe-variable)
+          (global-set-key (kbd "<f1> l") 'counsel-find-library)
+          (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
+          (global-set-key (kbd "<f2> u") 'counsel-unicode-char)
+
+Ivy-based interface to shell and system tools
+.............................................
+
+          (global-set-key (kbd "C-c c") 'counsel-compile)
+          (global-set-key (kbd "C-c g") 'counsel-git)
+          (global-set-key (kbd "C-c j") 'counsel-git-grep)
+          (global-set-key (kbd "C-c k") 'counsel-ag)
+          (global-set-key (kbd "C-x l") 'counsel-locate)
+          (global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
+
+Ivy-resume and other commands
+.............................
+
+     ‘ivy-resume’ resumes the last Ivy-based completion.
+
+          (global-set-key (kbd "C-c C-r") 'ivy-resume)
+
+
+File: ivy.info,  Node: Minibuffer key bindings,  Prev: Global key bindings,  
Up: Key bindings
+
+4.2 Minibuffer key bindings
+===========================
+
+Ivy includes several minibuffer bindings, which are defined in the
+‘ivy-minibuffer-map’ keymap variable.  The most frequently used ones are
+described here.
+
+   ‘swiper’ or ‘counsel-M-x’ add more key bindings through the ‘keymap’
+argument to ‘ivy-read’.  These keys, also active in the minibuffer, are
+described under their respective commands.
+
+   A key feature of ‘ivy-minibuffer-map’ is its full editing capability
+where the familiar ‘C-a’, ‘C-f’, ‘M-d’, ‘M-DEL’, ‘M-b’, ‘M-w’, ‘C-k’,
+‘C-y’ key bindings work the same as in ‘fundamental-mode’.
+
+* Menu:
+
+* Key bindings for navigation::
+* Key bindings for single selection, action, then exit minibuffer: Key 
bindings for single selection action then exit minibuffer.
+* Key bindings for multiple selections and actions, keep minibuffer open: Key 
bindings for multiple selections and actions keep minibuffer open.
+* Key bindings that alter the minibuffer input::
+* Other key bindings::
+* Hydra in the minibuffer::
+* Saving the current completion session to a buffer::
+
+
+File: ivy.info,  Node: Key bindings for navigation,  Next: Key bindings for 
single selection action then exit minibuffer,  Up: Minibuffer key bindings
+
+4.2.1 Key bindings for navigation
+---------------------------------
+
+   • ‘C-n’ (‘ivy-next-line’) selects the next candidate
+   • ‘C-p’ (‘ivy-previous-line’) selects the previous candidate
+   • ‘M-<’ (‘ivy-beginning-of-buffer’) selects the first candidate
+   • ‘M->’ (‘ivy-end-of-buffer’) selects the last candidate
+   • ‘C-v’ (‘ivy-scroll-up-command’) scrolls up by ‘ivy-height’ lines
+   • ‘M-v’ (‘ivy-scroll-down-command’) scrolls down by ‘ivy-height’
+     lines
+
+ -- User Option: ivy-wrap
+     Specifies the wrap-around behavior for ‘C-n’ and ‘C-p’.  When
+     ‘ivy-wrap’ is set to ‘t’, ‘ivy-next-line’ and ‘ivy-previous-line’
+     will cycle past the last and the first candidates respectively.
+
+     Wrap-around behavior is off by default.
+
+ -- User Option: ivy-height
+     Use this option to adjust the minibuffer height, which also affects
+     scroll size when using ‘C-v’ and ‘M-v’ key bindings.
+
+     ‘ivy-height’ is 10 lines by default.
+
+
+File: ivy.info,  Node: Key bindings for single selection action then exit 
minibuffer,  Next: Key bindings for multiple selections and actions keep 
minibuffer open,  Prev: Key bindings for navigation,  Up: Minibuffer key 
bindings
+
+4.2.2 Key bindings for single selection, action, then exit minibuffer
+---------------------------------------------------------------------
+
+Ivy can offer several actions from which to choose which action to run.
+This "calling an action" operates on the selected candidate.  For
+example, when viewing a list of files, one action could open it for
+editing, one to view it, another to invoke a special function, and so
+on.  Custom actions can be added to this interface.  The precise action
+to call on the selected candidate can be delayed until after the
+narrowing is completed.  No need to exit the interface if unsure which
+action to run.  This delayed flexibility and customization of actions
+extends usability of lists in Emacs.
+
+‘C-m’ or ‘RET’ (‘ivy-done’)
+...........................
+
+     Calls the default action and then exits the minibuffer.
+
+‘M-o’ (‘ivy-dispatching-done’)
+..............................
+
+     Presents valid actions from which to choose.  When only one action
+     is available, there is no difference between ‘M-o’ and ‘C-m’.
+
+‘C-j’ (‘ivy-alt-done’)
+......................
+
+     When completing file names, selects the current directory candidate
+     and starts a new completion session there.  Otherwise, it is the
+     same as ‘ivy-done’.
+
+‘TAB’ (‘ivy-partial-or-done’)
+.............................
+
+     Attempts partial completion, extending current input as much as
+     possible.  ‘TAB TAB’ is the same as ‘C-j’ (‘ivy-alt-done’).
+
+     Example ERT test:
+
+          (should
+           (equal (ivy-with
+                '(progn
+                  (ivy-read "Test: " '("can do" "can't, sorry" "other"))
+                  ivy-text)
+                "c <tab>")
+               "can"))
+
+‘C-M-j’ (‘ivy-immediate-done’)
+..............................
+
+     Exits with _the current input_ instead of _the current candidate_
+     (like other commands).
+
+     This is useful e.g.  when you call ‘find-file’ to create a new
+     file, but the desired name matches an existing file.  In that case,
+     using ‘C-j’ would select that existing file, which isn’t what you
+     want - use this command instead.
+
+‘C-'’ (‘ivy-avy’)
+.................
+
+     Uses avy to select one of the candidates on the current candidate
+     page.  This can often be faster than multiple ‘C-n’ or ‘C-p’
+     keystrokes followed by ‘C-m’.
+
+
+File: ivy.info,  Node: Key bindings for multiple selections and actions keep 
minibuffer open,  Next: Key bindings that alter the minibuffer input,  Prev: 
Key bindings for single selection action then exit minibuffer,  Up: Minibuffer 
key bindings
+
+4.2.3 Key bindings for multiple selections and actions, keep minibuffer open
+----------------------------------------------------------------------------
+
+For repeatedly applying multiple actions or acting on multiple
+candidates, Ivy does not close the minibuffer between commands.  It
+keeps the minibuffer open for applying subsequent actions.
+
+   Adding an extra meta key to the normal key chord invokes the special
+version of the regular commands that enables applying multiple actions.
+
+‘C-M-m’ (‘ivy-call’)
+....................
+
+     Is the non-exiting version of ‘C-m’ (‘ivy-done’).
+
+     Instead of closing the minibuffer, ‘C-M-m’ allows selecting another
+     candidate or another action.  For example, ‘C-M-m’ on functions
+     list invokes ‘describe-function’.  When combined with ‘C-n’,
+     function descriptions can be invoked quickly in succession.
+
+‘C-M-o’ (‘ivy-dispatching-call’)
+................................
+
+     Is the non-exiting version of ‘M-o’ (‘ivy-dispatching-done’).
+
+     For example, during the ‘counsel-rhythmbox’ completion, press
+     ‘C-M-o e’ to en-queue the selected candidate, followed by ‘C-n C-m’
+     to play the next candidate - the current action reverts to the
+     default one after ‘C-M-o’.
+
+‘C-M-n’ (‘ivy-next-line-and-call’)
+..................................
+
+     Combines ‘C-n’ and ‘C-M-m’.  Applies an action and moves to next
+     line.
+
+     Comes in handy when opening multiple files from
+     ‘counsel-find-file’, ‘counsel-git-grep’, ‘counsel-ag’,
+     ‘counsel-rg’, or ‘counsel-locate’ lists.  Just hold ‘C-M-n’ for
+     rapid-fire default action on each successive element of the list.
+
+‘C-M-p’ (‘ivy-previous-line-and-call’)
+......................................
+
+     Combines ‘C-p’ and ‘C-M-m’.
+
+     Similar to the above except it moves through the list in the other
+     direction.
+
+‘ivy-resume’
+............
+
+     Recalls the state of the completion session just before its last
+     exit.
+
+     Useful after an accidental ‘C-m’ (‘ivy-done’).
+
+
+File: ivy.info,  Node: Key bindings that alter the minibuffer input,  Next: 
Other key bindings,  Prev: Key bindings for multiple selections and actions 
keep minibuffer open,  Up: Minibuffer key bindings
+
+4.2.4 Key bindings that alter the minibuffer input
+--------------------------------------------------
+
+‘M-n’ (‘ivy-next-history-element’)
+..................................
+
+     Cycles forward through the Ivy command history.
+
+     Ivy updates an internal history list after each action.  When this
+     history list is empty, ‘M-n’ inserts symbol (or URL) at point into
+     the minibuffer.
+
+‘M-p’ (‘ivy-previous-history-element’)
+......................................
+
+     Cycles forward through the Ivy command history.
+
+‘M-i’ (‘ivy-insert-current’)
+............................
+
+     Inserts the current candidate into the minibuffer.
+
+     Useful for copying and renaming files, for example: ‘M-i’ to insert
+     the original file name string, edit it, and then ‘C-m’ to complete
+     the renaming.
+
+‘M-j’ (‘ivy-yank-word’)
+.......................
+
+     Inserts the sub-word at point into the minibuffer.
+
+     This is similar to ‘C-s C-w’ with ‘isearch’.  Ivy reserves ‘C-w’
+     for ‘kill-region’.  See also ‘ivy-yank-symbol’ and ‘ivy-yank-char’.
+
+‘S-SPC’ (‘ivy-restrict-to-matches’)
+...................................
+
+     Deletes the current input, and resets the candidates list to the
+     currently restricted matches.
+
+     This is how Ivy provides narrowing in successive tiers.
+
+‘C-r’ (‘ivy-reverse-i-search’)
+..............................
+
+     Starts a recursive completion session through the command’s
+     history.
+
+     This works just like ‘C-r’ at the bash command prompt, where the
+     completion candidates are the history items.  Upon completion, the
+     selected candidate string is inserted into the minibuffer.
+
+
+File: ivy.info,  Node: Other key bindings,  Next: Hydra in the minibuffer,  
Prev: Key bindings that alter the minibuffer input,  Up: Minibuffer key bindings
+
+4.2.5 Other key bindings
+------------------------
+
+‘M-w’ (‘ivy-kill-ring-save’)
+............................
+
+     Copies selected candidates to the kill ring.
+
+     Copies the region if the region is active.
+
+
+File: ivy.info,  Node: Hydra in the minibuffer,  Next: Saving the current 
completion session to a buffer,  Prev: Other key bindings,  Up: Minibuffer key 
bindings
+
+4.2.6 Hydra in the minibuffer
+-----------------------------
+
+‘C-o’ (‘hydra-ivy/body’)
+........................
+
+     Invokes the hydra menu with short key bindings.
+
+   When Hydra is active, minibuffer editing is disabled and menus
+display short aliases:
+
+Short   Normal      Command name
+------------------------------------------------
+‘o’     ‘C-g’       ‘keyboard-escape-quit’
+‘j’     ‘C-n’       ‘ivy-next-line’
+‘k’     ‘C-p’       ‘ivy-previous-line’
+‘h’     ‘M-<’       ‘ivy-beginning-of-buffer’
+‘l’     ‘M->’       ‘ivy-end-of-buffer’
+‘d’     ‘C-m’       ‘ivy-done’
+‘f’     ‘C-j’       ‘ivy-alt-done’
+‘g’     ‘C-M-m’     ‘ivy-call’
+‘u’     ‘C-c C-o’   ‘ivy-occur’
+
+   Hydra reduces key strokes, for example: ‘C-n C-n C-n C-n’ is ‘C-o
+jjjj’ in Hydra.
+
+   Hydra menu offers these additional bindings:
+
+‘c’ (‘ivy-toggle-calling’)
+..........................
+
+     Toggle calling the action after each candidate change.  It modifies
+     ‘j’ to ‘jg’, ‘k’ to ‘kg’ etc.
+
+‘m’ (‘ivy-rotate-preferred-builders’)
+.....................................
+
+     Rotate the current regexp matcher.
+
+‘>’ (‘ivy-minibuffer-grow’)
+...........................
+
+     Increase ‘ivy-height’ for the current minibuffer.
+
+‘<’ (‘ivy-minibuffer-shrink’)
+.............................
+
+     Decrease ‘ivy-height’ for the current minibuffer.
+
+‘w’ (‘ivy-prev-action’)
+.......................
+
+     Select the previous action.
+
+‘s’ (‘ivy-next-action’)
+.......................
+
+     Select the next action.
+
+‘a’ (‘ivy-read-action’)
+.......................
+
+     Use a menu to select an action.
+
+‘C’ (‘ivy-toggle-case-fold’)
+............................
+
+     Toggle case folding (match both upper and lower case characters for
+     lower case input).
+
+
+File: ivy.info,  Node: Saving the current completion session to a buffer,  
Prev: Hydra in the minibuffer,  Up: Minibuffer key bindings
+
+4.2.7 Saving the current completion session to a buffer
+-------------------------------------------------------
+
+‘C-c C-o’ (‘ivy-occur’)
+.......................
+
+     Saves the current candidates to a new buffer and exits completion.
+
+   The new buffer is read-only and has a few useful bindings defined.
+
+‘RET’ or ‘f’ (‘ivy-occur-press’)
+................................
+
+     Call the current action on the selected candidate.
+
+‘mouse-1’ (‘ivy-occur-click’)
+.............................
+
+     Call the current action on the selected candidate.
+
+‘j’ (‘next-line’)
+.................
+
+     Move to next line.
+
+‘k’ (‘previous-line’)
+.....................
+
+     Move to previous line.
+
+‘a’ (‘ivy-occur-read-action’)
+.............................
+
+     Read an action and make it current for this buffer.
+
+‘o’ (‘ivy-occur-dispatch’)
+..........................
+
+     Read an action and call it on the selected candidate.
+
+‘q’ (‘quit-window’)
+...................
+
+     Bury the current buffer.
+
+   Ivy has no limit on the number of active buffers like these.
+
+   Ivy takes care of naming buffers uniquely by constructing descriptive
+names.  For example: ‘*ivy-occur counsel-describe-variable "function$*’.
+
+
+File: ivy.info,  Node: Completion Styles,  Next: Customization,  Prev: Key 
bindings,  Up: Top
+
+5 Completion Styles
+*******************
+
+Ivy’s completion functions rely on a regex builder - a function that
+transforms a string input to a string regex.  All current candidates
+simply have to match this regex.  Each collection can be assigned its
+own regex builder by customizing ‘ivy-re-builders-alist’.
+
+   The keys of this alist are collection names, and the values are one
+of the following:
+   • ‘ivy--regex’
+   • ‘ivy--regex-plus’
+   • ‘ivy--regex-ignore-order’
+   • ‘ivy--regex-fuzzy’
+   • ‘regexp-quote’
+
+   A catch-all key, ‘t’, applies to all collections that don’t have
+their own key.
+
+   The default is:
+
+     (setq ivy-re-builders-alist
+           '((t . ivy--regex-plus)))
+
+   This example shows a custom regex builder assigned to file name
+completion:
+
+     (setq ivy-re-builders-alist
+           '((read-file-name-internal . ivy--regex-fuzzy)
+       (t . ivy--regex-plus)))
+
+   Here, ‘read-file-name-internal’ is a function that is passed as the
+second argument to ‘completing-read’ for file name completion.
+
+   The regex builder resolves as follows (in order of priority):
+  1. ‘re-builder’ argument passed to ‘ivy-read’.
+  2. ‘collection’ argument passed to ‘ivy-read’ is a function and has an
+     entry on ‘ivy-re-builders-alist’.
+  3. ‘caller’ argument passed to ‘ivy-read’ has an entry on
+     ‘ivy-re-builders-alist’.
+  4. ‘this-command’ has an entry on ‘ivy-re-builders-alist’.
+  5. ‘t’ has an entry on ‘ivy-re-builders-alist’.
+  6. ‘ivy--regex’.
+
+* Menu:
+
+* ivy--regex-plus::
+* ivy--regex-ignore-order::
+* ivy--regex-fuzzy::
+
+
+File: ivy.info,  Node: ivy--regex-plus,  Next: ivy--regex-ignore-order,  Up: 
Completion Styles
+
+5.1 ivy–regex-plus
+==================
+
+‘ivy--regex-plus’ is Ivy’s default completion method.
+
+   ‘ivy--regex-plus’ matches by splitting the input by spaces and
+rebuilding it into a regex.
+
+   As the search string is typed in Ivy’s minibuffer, it is transformed
+into valid regex syntax.  If the string is ‘"for example"’, it is
+transformed into
+
+     "\\(for\\).*\\(example\\)"
+
+   which in regex terminology matches ‘"for"’ followed by a wild card
+and then ‘"example"’.  Note how Ivy uses the space character to build
+wild cards.  To match a literal white space, use an extra space.  So to
+match one space type two spaces, to match two spaces type three spaces,
+and so on.
+
+   As Ivy transforms typed characters into regex strings, it provides an
+intuitive feedback through font highlights.
+
+   Ivy supports regexp negation with ‘"!"’.  For example, ‘"define key !
+ivy quit"’ first selects everything matching ‘"define.*key"’, then
+removes everything matching ‘"ivy"’, and finally removes everything
+matching ‘"quit"’.  What remains is the final result set of the negation
+regexp.
+
+   Since Ivy treats minibuffer input as a regexp, the standard regexp
+identifiers work: ‘"^"’, ‘"$"’, ‘"\b"’ or ‘"[a-z]"’.  The exceptions are
+spaces, which translate to ‘".*"’, and ‘"!"’ that signal the beginning
+of a negation group.
+
+
+File: ivy.info,  Node: ivy--regex-ignore-order,  Next: ivy--regex-fuzzy,  
Prev: ivy--regex-plus,  Up: Completion Styles
+
+5.2 ivy–regex-ignore-order
+==========================
+
+‘ivy--regex-ignore-order’ ignores the order of regexp tokens when
+searching for matching candidates.  For instance, the input ‘"for
+example"’ will match ‘"example test for"’.
+
+
+File: ivy.info,  Node: ivy--regex-fuzzy,  Prev: ivy--regex-ignore-order,  Up: 
Completion Styles
+
+5.3 ivy–regex-fuzzy
+===================
+
+‘ivy--regex-fuzzy’ splits each character with a wild card.  Searching
+for ‘"for"’ returns all ‘"f.*o.*r"’ matches, resulting in a large number
+of hits.  Yet some searches need these extra hits.  Ivy sorts such large
+lists using ‘flx’ package’s scoring mechanism, if it’s installed.
+
+   ‘C-o m’ toggles the current regexp builder.
+
+
+File: ivy.info,  Node: Customization,  Next: Commands,  Prev: Completion 
Styles,  Up: Top
+
+6 Customization
+***************
+
+* Menu:
+
+* Faces::
+* Defcustoms::
+* Actions::
+* Packages::
+
+
+File: ivy.info,  Node: Faces,  Next: Defcustoms,  Up: Customization
+
+6.1 Faces
+=========
+
+‘ivy-current-match’
+...................
+
+     Highlights the currently selected candidate.
+
+‘ivy-minibuffer-match-face-1’
+.............................
+
+     Highlights the background of the match.
+
+‘ivy-minibuffer-match-face-2’
+.............................
+
+     Highlights the first (modulo 3) matched group.
+
+‘ivy-minibuffer-match-face-3’
+.............................
+
+     Highlights the second (modulo 3) matched group.
+
+‘ivy-minibuffer-match-face-4’
+.............................
+
+     Highlights the third (modulo 3) matched group.
+
+‘ivy-confirm-face’
+..................
+
+     Highlights the "(confirm)" part of the prompt.
+
+     When ‘confirm-nonexistent-file-or-buffer’ set to ‘t’, then
+     confirming non-existent files in ‘ivy-mode’ requires an additional
+     ‘RET’.
+
+     The confirmation prompt will use this face.
+
+     For example:
+
+          (setq confirm-nonexistent-file-or-buffer t)
+
+     Then call ‘find-file’, enter "eldorado" and press ‘RET’ - the
+     prompt will be appended with "(confirm)".  Press ‘RET’ once more to
+     confirm, or any key to continue the completion.
+
+‘ivy-match-required-face’
+.........................
+
+     Highlights the "(match required)" part of the prompt.
+
+     When completions have to match available candidates and cannot take
+     random input, the "(match required)" prompt signals this
+     constraint.
+
+     For example, call ‘describe-variable’, enter "waldo" and press
+     ‘RET’ - "(match required)" is prompted.  Press any key for the
+     prompt to disappear.
+
+‘ivy-subdir’
+............
+
+     Highlights directories when completing file names.
+
+‘ivy-remote’
+............
+
+     Highlights remote files when completing file names.
+
+‘ivy-virtual’
+.............
+
+     Highlights virtual buffers when completing buffer names.
+
+     Virtual buffers correspond to bookmarks and recent files list,
+     ‘recentf’.
+
+     Enable virtual buffers with:
+
+          (setq ivy-use-virtual-buffers t)
+
+‘ivy-modified-buffer’
+.....................
+
+     Highlights modified buffers when switching buffer.
+
+‘ivy-modified-outside-buffer’
+.............................
+
+     Highlights buffers modified outside Emacs when switching buffer.
+
+     This takes precedence over ‘ivy-modified-buffer’.
+
+
+File: ivy.info,  Node: Defcustoms,  Next: Actions,  Prev: Faces,  Up: 
Customization
+
+6.2 Defcustoms
+==============
+
+ -- User Option: ivy-count-format
+     A string that specifies display of number of candidates and current
+     candidate, if one exists.
+
+     The number of matching candidates by default is shown as a right-
+     padded integer value.
+
+     To disable showing the number of candidates:
+
+          (setq ivy-count-format "")
+
+     To also display the current candidate:
+
+          (setq ivy-count-format "(%d/%d) ")
+
+     The ‘format’-style switches this variable uses are described in the
+     ‘format’ documentation.
+
+ -- User Option: ivy-display-style
+     Specifies highlighting candidates in the minibuffer.
+
+     The default setting is ‘'fancy’ in Emacs versions 24.4 or newer.
+
+     Set ‘ivy-display-style’ to ‘nil’ for a plain minibuffer.
+
+ -- User Option: ivy-on-del-error-function
+     Specifies what to do when ‘DEL’ (‘ivy-backward-delete-char’) fails.
+
+     This is usually the case when there is no text left to delete,
+     i.e., when ‘DEL’ is typed at the beginning of the minibuffer.
+
+     The default behavior is to quit the completion after ‘DEL’ – a
+     handy key to invoke after mistakenly triggering a completion.
+
+
+File: ivy.info,  Node: Actions,  Next: Packages,  Prev: Defcustoms,  Up: 
Customization
+
+6.3 Actions
+===========
+
+* Menu:
+
+* What are actions?::
+* How can different actions be called?::
+* How to modify the actions list?::
+* Example - add two actions to each command::
+* Example - define a new command with several actions::
+
+
+File: ivy.info,  Node: What are actions?,  Next: How can different actions be 
called?,  Up: Actions
+
+6.3.1 What are actions?
+-----------------------
+
+An action is a function that is called after you select a candidate
+during completion.  This function takes a single string argument, which
+is the selected candidate.
+
+Window context when calling an action
+.....................................
+
+     Currently, the action is executed in the minibuffer window context.
+     This means e.g.  that if you call ‘insert’ the text will be
+     inserted into the minibuffer.
+
+     If you want to execute the action in the initial window from which
+     the completion started, use the ‘with-ivy-window’ wrapper macro.
+
+          (defun ivy-insert-action (x)
+            (with-ivy-window
+              (insert x)))
+
+
+File: ivy.info,  Node: How can different actions be called?,  Next: How to 
modify the actions list?,  Prev: What are actions?,  Up: Actions
+
+6.3.2 How can different actions be called?
+------------------------------------------
+
+   • ‘C-m’ (‘ivy-done’) calls the current action.
+   • ‘M-o’ (‘ivy-dispatching-done’) presents available actions for
+     selection, calls it after selection, and then exits.
+   • ‘C-M-o’ (‘ivy-dispatching-call’) presents available actions for
+     selection, calls it after selection, and then does not exit.
+
+
+File: ivy.info,  Node: How to modify the actions list?,  Next: Example - add 
two actions to each command,  Prev: How can different actions be called?,  Up: 
Actions
+
+6.3.3 How to modify the actions list?
+-------------------------------------
+
+Currently, you can append any amount of your own actions to the default
+list of actions.  This can be done either for a specific command, or for
+all commands at once.
+
+   Usually, the command has only one default action.  The convention is
+to use single letters when selecting a command, and the letter ‘o’ is
+designated for the default command.  This way, ‘M-o o’ should be always
+equivalent to ‘C-m’.
+
+
+File: ivy.info,  Node: Example - add two actions to each command,  Next: 
Example - define a new command with several actions,  Prev: How to modify the 
actions list?,  Up: Actions
+
+6.3.4 Example - add two actions to each command
+-----------------------------------------------
+
+The first action inserts the current candidate into the Ivy window - the
+window from which ‘ivy-read’ was called.
+
+   The second action copies the current candidate to the kill ring.
+
+     (defun ivy-yank-action (x)
+       (kill-new x))
+
+     (defun ivy-copy-to-buffer-action (x)
+       (with-ivy-window
+         (insert x)))
+
+     (ivy-set-actions
+      t
+      '(("i" ivy-copy-to-buffer-action "insert")
+        ("y" ivy-yank-action "yank")))
+
+   Then in any completion session, ‘M-o y’ invokes ‘ivy-yank-action’,
+and ‘M-o i’ invokes ‘ivy-copy-to-buffer-action’.
+
+* Menu:
+
+* How to undo adding the two actions::
+* How to add actions to a specific command::
+
+
+File: ivy.info,  Node: How to undo adding the two actions,  Next: How to add 
actions to a specific command,  Up: Example - add two actions to each command
+
+6.3.4.1 How to undo adding the two actions
+..........................................
+
+Since ‘ivy-set-actions’ modifies the internal dictionary with new data,
+set the extra actions list to ‘nil’ by assigning ‘nil’ value to the ‘t’
+key as follows:
+
+     (ivy-set-actions t nil)
+
+
+File: ivy.info,  Node: How to add actions to a specific command,  Prev: How to 
undo adding the two actions,  Up: Example - add two actions to each command
+
+6.3.4.2 How to add actions to a specific command
+................................................
+
+Use the command name as the key:
+
+     (ivy-set-actions
+      'swiper
+      '(("i" ivy-copy-to-buffer-action "insert")
+        ("y" ivy-yank-action "yank")))
+
+
+File: ivy.info,  Node: Example - define a new command with several actions,  
Prev: Example - add two actions to each command,  Up: Actions
+
+6.3.5 Example - define a new command with several actions
+---------------------------------------------------------
+
+     (defun my-action-1 (x)
+       (message "action-1: %s" x))
+
+     (defun my-action-2 (x)
+       (message "action-2: %s" x))
+
+     (defun my-action-3 (x)
+       (message "action-3: %s" x))
+
+     (defun my-command-with-3-actions ()
+       (interactive)
+       (ivy-read "test: " '("foo" "bar" "baz")
+           :action '(1
+                     ("o" my-action-1 "action 1")
+                     ("j" my-action-2 "action 2")
+                     ("k" my-action-3 "action 3"))))
+
+   The number 1 above is the index of the default action.  Each action
+has its own string description for easy selection.
+
+* Menu:
+
+* Test the above function with ivy-occur::
+
+
+File: ivy.info,  Node: Test the above function with ivy-occur,  Up: Example - 
define a new command with several actions
+
+6.3.5.1 Test the above function with ‘ivy-occur’
+................................................
+
+To examine each action with each candidate in a key-efficient way, try:
+
+   • Call ‘my-command-with-3-actions’
+   • Press ‘C-c C-o’ to close the completion window and move to an
+     ivy-occur buffer
+   • Press ‘kkk’ to move to the first candidate, since the point is most
+     likely at the end of the buffer
+   • Press ‘oo’ to call the first action
+   • Press ‘oj’ and ‘ok’ to call the second and the third actions
+   • Press ‘j’ to move to the next candidate
+   • Press ‘oo’, ‘oj’, ‘ok’
+   • Press ‘j’ to move to the next candidate
+   • and so on...
+
+
+File: ivy.info,  Node: Packages,  Prev: Actions,  Up: Customization
+
+6.4 Packages
+============
+
+‘org-mode’
+..........
+
+     ‘org-mode’ versions 8.3.3 or later obey ‘completing-read-function’
+     (which ‘ivy-mode’ sets).  Try refiling headings with similar names
+     to appreciate ‘ivy-mode’.
+
+‘magit’
+.......
+
+     Uses ivy by default if Ivy is installed.
+
+‘find-file-in-project’
+......................
+
+     Uses ivy by default if Ivy is installed.
+
+‘projectile’
+............
+
+     Projectile requires this setting for ivy completion:
+
+          (setq projectile-completion-system 'ivy)
+
+‘helm-make’
+...........
+
+     Helm-make requires this setting for ivy completion.
+
+          (setq helm-make-completion-method 'ivy)
+
+automatically integrated packages
+.................................
+
+     Ivy re-uses the following packages if they are installed: ‘avy’,
+     ‘amx’ or ‘smex’, ‘flx’, and ‘wgrep’.
+
+
+File: ivy.info,  Node: Commands,  Next: API,  Prev: Customization,  Up: Top
+
+7 Commands
+**********
+
+* Menu:
+
+* File Name Completion::
+* Buffer Name Completion::
+* Counsel commands::
+
+
+File: ivy.info,  Node: File Name Completion,  Next: Buffer Name Completion,  
Up: Commands
+
+7.1 File Name Completion
+========================
+
+Since file name completion is ubiquitous, Ivy provides extra bindings
+that work here:
+
+‘C-j’ (‘ivy-alt-done’)
+......................
+
+     On a directory, restarts completion from that directory.
+
+     On a file or ‘./’, exit completion with the selected candidate.
+
+‘DEL’ (‘ivy-backward-delete-char’)
+..................................
+
+     Restart the completion in the parent directory if current input is
+     empty.
+
+‘//’ (‘self-insert-command’)
+............................
+
+     Switch to the root directory.
+
+‘~’ (‘self-insert-command’)
+...........................
+
+     Switch to the home directory.
+
+‘/’ (‘self-insert-command’)
+...........................
+
+     If the current input matches an existing directory name exactly,
+     switch the completion to that directory.
+
+‘M-r’ (‘ivy-toggle-regexp-quote’)
+.................................
+
+     Toggle between input as regexp or not.
+
+     Switch to matching literally since file names include ‘.’, which is
+     for matching any char in regexp mode.
+ -- User Option: ivy-extra-directories
+     Decide if you want to see ‘../’ and ‘./’ during file name
+     completion.
+
+     Reason to remove: ‘../’ is the same as ‘DEL’.
+
+     Reason not to remove: navigate anywhere with only ‘C-n’, ‘C-p’ and
+     ‘C-j’.
+
+     Likewise, ‘./’ can be removed.
+
+History
+.......
+
+     File history works the same with ‘M-p’, ‘M-n’, and ‘C-r’, but uses
+     a custom code for file name completion that cycles through files
+     previously opened.  It also works with TRAMP files.
+
+* Menu:
+
+* Using TRAMP::
+
+
+File: ivy.info,  Node: Using TRAMP,  Up: File Name Completion
+
+7.1.1 Using TRAMP
+-----------------
+
+‘~’ (tilde)
+...........
+
+     Move to the home directory.  Either the local or the remote one,
+     depending on the current directory.  The boolean option
+     ‘ivy-magic-tilde’ decides whether the binding to do this is ‘~’ or
+     ‘~/’.
+
+‘//’ (double slash)
+...................
+
+     Move to the root directory.  Either the local or the remote one,
+     depending on the current directory.  Here, you can also select a
+     TRAMP connection method, such as ‘ssh’ or ‘scpx’.
+
+‘/ C-j’
+.......
+
+     Move the the local root directory.
+
+   From any directory, with the empty input, inputting ‘/ssh:’ and
+pressing ‘C-j’ (or ‘RET’, which is the same thing) completes for host
+and user names.
+
+   For ‘/ssh:user@’ input, completes the domain name.
+
+   ‘C-i’ works in a similar way to the default completion.
+
+   You can also get sudo access for the current directory by inputting
+‘/sudo::’ ‘RET’.  Using ‘/sudo:’ (i.e.  single colon instead of double)
+will result in a completion session for the desired user.
+
+   Multi-hopping is possible, although a bit complex.
+
+Example : connect to a remote host ‘cloud’ and open a file with ‘sudo’ there
+............................................................................
+
+        • ‘C-x C-f’ ‘/ssh:cloud|sudo:root:/’.
+
+
+File: ivy.info,  Node: Buffer Name Completion,  Next: Counsel commands,  Prev: 
File Name Completion,  Up: Commands
+
+7.2 Buffer Name Completion
+==========================
+
+ -- User Option: ivy-use-virtual-buffers
+     When non-nil, add ‘recentf-mode’ and bookmarks to
+     ‘ivy-switch-buffer’ completion candidates.
+
+     Adding this to Emacs init file:
+
+          (setq ivy-use-virtual-buffers t)
+     will add additional virtual buffers to the buffers list for recent
+     files.  Selecting such virtual buffers, which are highlighted with
+     ‘ivy-virtual’ face, will open the corresponding file.
+
+
+File: ivy.info,  Node: Counsel commands,  Prev: Buffer Name Completion,  Up: 
Commands
+
+7.3 Counsel commands
+====================
+
+The main advantages of ‘counsel-’ functions over their basic equivalents
+in ‘ivy-mode’ are:
+
+  1. Multi-actions and non-exiting actions work.
+  2. ‘ivy-resume’ can resume the last completion session.
+  3. Customize ‘ivy-set-actions’, ‘ivy-re-builders-alist’.
+  4. Customize individual keymaps, such as ‘counsel-describe-map’,
+     ‘counsel-git-grep-map’, or ‘counsel-find-file-map’, instead of
+     customizing ‘ivy-minibuffer-map’ that applies to all completion
+     sessions.
+
+
+File: ivy.info,  Node: API,  Next: Variable Index,  Prev: Commands,  Up: Top
+
+8 API
+*****
+
+The main (and only) entry point is the ‘ivy-read’ function.  It takes
+two required arguments and many optional arguments that can be passed by
+a key.  The optional ‘:action’ argument is highly recommended for
+features such as multi-actions, non-exiting actions, ‘ivy-occur’ and
+‘ivy-resume’.
+
+* Menu:
+
+* Required arguments for ivy-read::
+* Optional arguments for ivy-read::
+* Example - counsel-describe-function::
+* Example - counsel-locate::
+* Example - ivy-read-with-extra-properties::
+
+
+File: ivy.info,  Node: Required arguments for ivy-read,  Next: Optional 
arguments for ivy-read,  Up: API
+
+8.1 Required arguments for ‘ivy-read’
+=====================================
+
+‘prompt’
+........
+
+     A prompt string normally ending in a colon and a space.
+     ‘ivy-count-format’ is prepended to it during completion.
+
+‘collection’
+............
+
+     Either a list of strings, a function, an alist or a hash table.
+
+     If a function, then it has to be compatible with ‘all-completions’.
+
+
+File: ivy.info,  Node: Optional arguments for ivy-read,  Next: Example - 
counsel-describe-function,  Prev: Required arguments for ivy-read,  Up: API
+
+8.2 Optional arguments for ‘ivy-read’
+=====================================
+
+‘predicate’
+...........
+
+     Is a function to filter the initial collection.  It has to be
+     compatible with ‘all-completions’.  Tip: most of the time, it’s
+     simpler to just apply this filter to the ‘collection’ argument
+     itself, e.g.  ‘(cl-remove-if-not predicate collection)’.
+
+‘require-match’
+...............
+
+     When set to a non-nil value, input must match one of the
+     candidates.  Custom input is not accepted.
+
+‘initial-input’
+...............
+
+     This string argument is included for compatibility with
+     ‘completing-read’, which inserts it into the minibuffer.
+
+     It’s recommended to use the ‘preselect’ argument instead of this.
+
+‘history’
+.........
+
+     Name of the symbol to store history.  See ‘completing-read’.
+
+‘preselect’
+...........
+
+     Determines which one of the candidates to initially select.
+
+     When set to an integer value, select the candidate with that index
+     value.
+
+     When set to any other non-nil value, select the first candidate
+     matching this value.  Comparison is first done with ‘equal’.  If
+     this fails, and when applicable, match ‘preselect’ as a regular
+     expression.
+
+     Every time the input becomes empty, the item corresponding to
+     ‘preselect’ is selected.
+
+‘keymap’
+........
+
+     A keymap to be composed with ‘ivy-minibuffer-map’.  This keymap has
+     priority over ‘ivy-minibuffer-map’ and can be modified at any later
+     stage.
+
+‘update-fn’
+...........
+
+     Is the function called each time the current candidate changes.
+     This function takes no arguments and is called in the minibuffer’s
+     ‘post-command-hook’.  See ‘swiper’ for an example usage.
+
+‘sort’
+......
+
+     When non-nil, use ‘ivy-sort-functions-alist’ to sort the collection
+     as long as the collection is not larger than ‘ivy-sort-max-size’.
+
+‘action’
+........
+
+     Is the function to call after selection.  It takes a string
+     argument.
+
+‘unwind’
+........
+
+     Is the function to call before exiting completion.  It takes no
+     arguments.  This function is called even if the completion is
+     interrupted with ‘C-g’.  See ‘swiper’ for an example usage.
+
+‘re-builder’
+............
+
+     Is a function that takes a string and returns a valid regex.  See
+     ‘Completion Styles’ for details.
+
+‘matcher’
+.........
+
+     Is a function that takes a regex string and a list of strings and
+     returns a list of strings matching the regex.  Any ordinary Emacs
+     matching function will suffice, yet finely tuned matching functions
+     can be used.  See ‘counsel-find-file’ for an example usage.
+
+‘dynamic-collection’
+....................
+
+     When non-nil, ‘collection’ will be used to dynamically generate the
+     candidates each time the input changes, instead of being used once
+     statically with ‘all-completions’ to generate a list of strings.
+     See ‘counsel-locate’ for an example usage.
+
+‘caller’
+........
+
+     Is a symbol that uniquely identifies the function that called
+     ‘ivy-read’, which may be useful for further customizations.
+
+
+File: ivy.info,  Node: Example - counsel-describe-function,  Next: Example - 
counsel-locate,  Prev: Optional arguments for ivy-read,  Up: API
+
+8.3 Example - ‘counsel-describe-function’
+=========================================
+
+This is a typical example of a function with a non-async collection,
+which is a collection where all the strings in the collection are known
+prior to any input from the user.
+
+   Only the first two arguments (along with ‘action’) are essential -
+the rest of the arguments are for fine-tuning, and could be omitted.
+
+   The ‘action’ argument could also be omitted - but then ‘ivy-read’
+would do nothing except returning the string result, which you could
+later use yourself.  However, it’s recommended that you use the ‘action’
+argument.
+
+     (defun counsel-describe-function ()
+       "Forward to `describe-function'."
+       (interactive)
+       (ivy-read "Describe function: "
+           (let (cands)
+             (mapatoms
+              (lambda (x)
+                (when (fboundp x)
+                  (push (symbol-name x) cands))))
+             cands)
+           :keymap counsel-describe-map
+           :preselect (ivy-thing-at-point)
+           :history 'counsel-describe-symbol-history
+           :require-match t
+           :sort t
+           :action (lambda (x)
+                     (describe-function
+                      (intern x)))
+           :caller 'counsel-describe-function))
+
+   Here are the interesting features of the above function, in the order
+that they appear:
+
+   • The ‘prompt’ argument is a simple string ending in ": ".
+   • The ‘collection’ argument evaluates to a (large) list of strings.
+   • The ‘keymap’ argument is for a custom keymap to supplement
+     ‘ivy-minibuffer-map’.
+   • The ‘preselect’ is provided by ‘ivy-thing-at-point’, which returns
+     a symbol near the point.  Ivy then selects the first candidate from
+     the collection that matches this symbol.  To select this
+     pre-selected candidate, a ‘RET’ will suffice.  No further user
+     input is necessary.
+   • The ‘history’ argument is for keeping the history of this command
+     separate from the common history in ‘ivy-history’.
+   • The ‘require-match’ is set to ‘t’ since it doesn’t make sense to
+     call ‘describe-function’ on an un-interned symbol.
+   • The ‘sort’ argument is set to ‘t’ so choosing between similar
+     candidates becomes easier.  Sometimes, the collection size will
+     exceed ‘ivy-sort-max-size’, which is 30000 by default.  In that
+     case the sorting will not happen to avoid delays.
+
+     Adjust this variable to choose between sorting time and completion
+     start-up time.
+   • The ‘action’ argument calls ‘describe-function’ on the interned
+     selected candidate.
+   • The ‘caller’ argument identifies this completion session.  This is
+     important, since with the collection being a list of strings and
+     not a function name, the only other way for ‘ivy-read’ to identify
+     "who’s calling" and to apply the appropriate customizations is to
+     examine ‘this-command’.  But ‘this-command’ would be modified if
+     another command called ‘counsel-describe-function’.
+
+
+File: ivy.info,  Node: Example - counsel-locate,  Next: Example - 
ivy-read-with-extra-properties,  Prev: Example - counsel-describe-function,  
Up: API
+
+8.4 Example - ‘counsel-locate’
+==============================
+
+This is a typical example of a function with an async collection.  Since
+the collection function cannot pre-compute all the locatable files in
+memory within reasonable limits (time or memory), it relies on user
+input to filter the universe of possible candidates to a manageable size
+while also continuing to search asynchronously for possible candidates.
+Both the filtering and searching continues with each character change of
+the input with rapid updates to the collection presented without idle
+waiting times.  This live update will continue as long as there are
+likely candidates.  Eventually updates to the minibuffer will stop after
+user input, filtering, and searching have exhausted looking for possible
+candidates.
+
+   Async collections suit long-running shell commands, such as ‘locate’.
+With each new input, a new process starts while the old process is
+killed.  The collection is refreshed anew with each new process.
+Meanwhile the user can provide more input characters (for further
+narrowing) or select a candidate from the visible collection.
+
+     (defun counsel-locate-function (str)
+       (or
+        (ivy-more-chars)
+        (progn
+          (counsel--async-command
+           (format "locate %s '%s'"
+             (mapconcat #'identity counsel-locate-options " ")
+             (counsel--elisp-to-pcre
+              (ivy--regex str))))
+          '("" "working..."))))
+
+     ;;;###autoload
+     (defun counsel-locate (&optional initial-input)
+       "Call the \"locate\" shell command.
+     INITIAL-INPUT can be given as the initial minibuffer input."
+       (interactive)
+       (ivy-read "Locate: " #'counsel-locate-function
+           :initial-input initial-input
+           :dynamic-collection t
+           :history 'counsel-locate-history
+           :action (lambda (file)
+                     (with-ivy-window
+                       (when file
+                         (find-file file))))
+           :unwind #'counsel-delete-process
+           :caller 'counsel-locate))
+
+   Here are the interesting features of the above functions, in the
+order that they appear:
+
+   • ‘counsel-locate-function’ takes a string argument and returns a
+     list of strings.  Note that it’s not compatible with
+     ‘all-completions’, but since we’re not using that here, might as
+     well use one argument instead of three.
+   • ‘ivy-more-chars’ is a simple function that returns e.g.  ‘'("2
+     chars more")’ asking the user for more input.
+   • ‘counsel--async-command’ is a very easy API simplification that
+     takes a single string argument suitable for
+     ‘shell-command-to-string’.  So you could prototype your function as
+     non-async using ‘shell-command-to-string’ and ‘split-string’ to
+     produce a collection, then decide that you want async and simply
+     swap in ‘counsel--async-command’.
+   • ‘counsel-locate’ is an interactive function with an optional
+     ‘initial-input’.
+   • ‘#'counsel-locate-function’ is passed as the ‘collection’ argument.
+   • ‘dynamic-collection’ is set to t, since this is an async
+     collection.
+   • ‘action’ argument uses ‘with-ivy-window’ wrapper, since we want to
+     open the selected file in the same window from which
+     ‘counsel-locate’ was called.
+   • ‘unwind’ argument is set to ‘#'counsel-delete-process’: when we
+     press ‘C-g’ we want to kill the running process created by
+     ‘counsel--async-command’.
+   • ‘caller’ argument identifies this command for easier customization.
+
+
+File: ivy.info,  Node: Example - ivy-read-with-extra-properties,  Prev: 
Example - counsel-locate,  Up: API
+
+8.5 Example - ‘ivy-read-with-extra-properties’
+==============================================
+
+This is another example to show how to associate additional values to
+each displayed strings.
+
+     (defun find-candidates-function (str pred _)
+       (let ((props '(1 2))
+       (strs '("foo" "foo2")))
+         (cl-mapcar (lambda (s p) (propertize s 'property p))
+              strs
+              props)))
+
+     (defun find-candidates ()
+       (interactive)
+       (ivy-read "Find symbols: "
+           #'find-candidates-function
+           :action (lambda (x)
+                     (message "Value: %s" (get-text-property 0 'property x)
+                      ))))
+
+   Here are the interesting features of the above function:
+
+   • ‘find-candidates-function’ builds up a list of strings and
+     associates "foo" with the value 1 and "foo2" with 2.
+   • ‘find-candidates’ is an interactive function.
+   • ‘#'find-candidates’ is passed as the ‘collection’ argument.
+   • ‘action’ gets passed the selected string with the associated value.
+     It then retrieves that value and displays it.
+
+
+File: ivy.info,  Node: Variable Index,  Next: Keystroke Index,  Prev: API,  
Up: Top
+
+Variable Index
+**************
+
+[index]
+* Menu:
+
+* ivy-alt-done:                          Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 30)
+* ivy-alt-done <1>:                      File Name Completion. (line 12)
+* ivy-avy:                               Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 64)
+* ivy-backward-delete-char:              File Name Completion. (line 19)
+* ivy-call:                              Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 16)
+* ivy-confirm-face:                      Faces.                (line 34)
+* ivy-count-format:                      Defcustoms.           (line  6)
+* ivy-current-match:                     Faces.                (line  9)
+* ivy-dispatching-call:                  Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 26)
+* ivy-dispatching-done:                  Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 24)
+* ivy-display-style:                     Defcustoms.           (line 24)
+* ivy-done:                              Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 19)
+* ivy-extra-directories:                 File Name Completion. (line 45)
+* ivy-height:                            Key bindings for navigation.
+                                                               (line 21)
+* ivy-immediate-done:                    Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 53)
+* ivy-insert-current:                    Key bindings that alter the 
minibuffer input.
+                                                               (line 23)
+* ivy-kill-ring-save:                    Other key bindings.   (line  9)
+* ivy-match-required-face:               Faces.                (line 53)
+* ivy-minibuffer-grow:                   Hydra in the minibuffer.
+                                                               (line 45)
+* ivy-minibuffer-map:                    Minibuffer key bindings.
+                                                               (line  6)
+* ivy-minibuffer-match-face-1:           Faces.                (line 14)
+* ivy-minibuffer-match-face-2:           Faces.                (line 19)
+* ivy-minibuffer-match-face-3:           Faces.                (line 24)
+* ivy-minibuffer-match-face-4:           Faces.                (line 29)
+* ivy-minibuffer-shrink:                 Hydra in the minibuffer.
+                                                               (line 50)
+* ivy-modified-buffer:                   Faces.                (line 88)
+* ivy-modified-outside-buffer:           Faces.                (line 93)
+* ivy-next-action:                       Hydra in the minibuffer.
+                                                               (line 60)
+* ivy-next-history-element:              Key bindings that alter the 
minibuffer input.
+                                                               (line  9)
+* ivy-next-line-and-call:                Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 36)
+* ivy-occur:                             Saving the current completion session 
to a buffer.
+                                                               (line  9)
+* ivy-occur-click:                       Saving the current completion session 
to a buffer.
+                                                               (line 21)
+* ivy-occur-dispatch:                    Saving the current completion session 
to a buffer.
+                                                               (line 41)
+* ivy-occur-press:                       Saving the current completion session 
to a buffer.
+                                                               (line 16)
+* ivy-occur-read-action:                 Saving the current completion session 
to a buffer.
+                                                               (line 36)
+* ivy-on-del-error-function:             Defcustoms.           (line 31)
+* ivy-partial-or-done:                   Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 37)
+* ivy-prev-action:                       Hydra in the minibuffer.
+                                                               (line 55)
+* ivy-previous-history-element:          Key bindings that alter the 
minibuffer input.
+                                                               (line 18)
+* ivy-previous-line-and-call:            Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 47)
+* ivy-read-action:                       Hydra in the minibuffer.
+                                                               (line 65)
+* ivy-remote:                            Faces.                (line 71)
+* ivy-restrict-to-matches:               Key bindings that alter the 
minibuffer input.
+                                                               (line 40)
+* ivy-resume:                            Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 55)
+* ivy-reverse-i-search:                  Key bindings that alter the 
minibuffer input.
+                                                               (line 48)
+* ivy-rotate-preferred-builders:         Hydra in the minibuffer.
+                                                               (line 40)
+* ivy-subdir:                            Faces.                (line 66)
+* ivy-toggle-calling:                    Hydra in the minibuffer.
+                                                               (line 34)
+* ivy-toggle-case-fold:                  Hydra in the minibuffer.
+                                                               (line 70)
+* ivy-toggle-regexp-quote:               File Name Completion. (line 41)
+* ivy-use-virtual-buffers:               Buffer Name Completion.
+                                                               (line  6)
+* ivy-virtual:                           Faces.                (line 76)
+* ivy-wrap:                              Key bindings for navigation.
+                                                               (line 14)
+* ivy-yank-word:                         Key bindings that alter the 
minibuffer input.
+                                                               (line 32)
+
+
+File: ivy.info,  Node: Keystroke Index,  Prev: Variable Index,  Up: Top
+
+Keystroke Index
+***************
+
+[index]
+* Menu:
+
+* /:                                     File Name Completion. (line 35)
+* / C-j:                                 Using TRAMP.          (line 24)
+* //:                                    File Name Completion. (line 25)
+* // <1>:                                Using TRAMP.          (line 17)
+* <:                                     Hydra in the minibuffer.
+                                                               (line 50)
+* >:                                     Hydra in the minibuffer.
+                                                               (line 45)
+* ~:                                     File Name Completion. (line 30)
+* ~ <1>:                                 Using TRAMP.          (line  9)
+* a:                                     Hydra in the minibuffer.
+                                                               (line 65)
+* a <1>:                                 Saving the current completion session 
to a buffer.
+                                                               (line 36)
+* c:                                     Hydra in the minibuffer.
+                                                               (line 34)
+* C:                                     Hydra in the minibuffer.
+                                                               (line 70)
+* C-':                                   Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 64)
+* C-c C-o:                               Saving the current completion session 
to a buffer.
+                                                               (line  9)
+* C-j:                                   Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 30)
+* C-j <1>:                               File Name Completion. (line 12)
+* C-m:                                   Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 19)
+* C-M-j:                                 Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 53)
+* C-M-m:                                 Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 16)
+* C-M-n:                                 Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 36)
+* C-M-o:                                 Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 26)
+* C-M-p:                                 Key bindings for multiple selections 
and actions keep minibuffer open.
+                                                               (line 47)
+* C-o:                                   Hydra in the minibuffer.
+                                                               (line  9)
+* C-r:                                   Key bindings that alter the 
minibuffer input.
+                                                               (line 48)
+* DEL:                                   File Name Completion. (line 19)
+* f:                                     Saving the current completion session 
to a buffer.
+                                                               (line 16)
+* j:                                     Saving the current completion session 
to a buffer.
+                                                               (line 26)
+* k:                                     Saving the current completion session 
to a buffer.
+                                                               (line 31)
+* m:                                     Hydra in the minibuffer.
+                                                               (line 40)
+* M-i:                                   Key bindings that alter the 
minibuffer input.
+                                                               (line 23)
+* M-j:                                   Key bindings that alter the 
minibuffer input.
+                                                               (line 32)
+* M-n:                                   Key bindings that alter the 
minibuffer input.
+                                                               (line  9)
+* M-o:                                   Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 24)
+* M-p:                                   Key bindings that alter the 
minibuffer input.
+                                                               (line 18)
+* M-r:                                   File Name Completion. (line 41)
+* M-w:                                   Other key bindings.   (line  9)
+* mouse-1:                               Saving the current completion session 
to a buffer.
+                                                               (line 21)
+* o:                                     Saving the current completion session 
to a buffer.
+                                                               (line 41)
+* q:                                     Saving the current completion session 
to a buffer.
+                                                               (line 46)
+* RET:                                   Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 19)
+* RET <1>:                               Saving the current completion session 
to a buffer.
+                                                               (line 16)
+* s:                                     Hydra in the minibuffer.
+                                                               (line 60)
+* S-SPC:                                 Key bindings that alter the 
minibuffer input.
+                                                               (line 40)
+* TAB:                                   Key bindings for single selection 
action then exit minibuffer.
+                                                               (line 37)
+* w:                                     Hydra in the minibuffer.
+                                                               (line 55)
+
+
+
+Tag Table:
+Node: Top1361
+Node: Introduction3272
+Node: Installation5795
+Node: Installing from Emacs Package Manager6245
+Node: Installing from the Git repository7359
+Node: Getting started8179
+Node: Basic customization8486
+Node: Key bindings9081
+Node: Global key bindings9273
+Node: Minibuffer key bindings10713
+Node: Key bindings for navigation11945
+Node: Key bindings for single selection action then exit minibuffer13152
+Node: Key bindings for multiple selections and actions keep minibuffer 
open15799
+Node: Key bindings that alter the minibuffer input18191
+Node: Other key bindings20136
+Node: Hydra in the minibuffer20514
+Node: Saving the current completion session to a buffer22617
+Node: Completion Styles24029
+Node: ivy--regex-plus25780
+Node: ivy--regex-ignore-order27266
+Node: ivy--regex-fuzzy27634
+Node: Customization28131
+Node: Faces28317
+Node: Defcustoms30746
+Node: Actions32040
+Node: What are actions?32366
+Node: How can different actions be called?33184
+Node: How to modify the actions list?33755
+Node: Example - add two actions to each command34415
+Node: How to undo adding the two actions35374
+Node: How to add actions to a specific command35826
+Node: Example - define a new command with several actions36242
+Node: Test the above function with ivy-occur37130
+Node: Packages37972
+Node: Commands38937
+Node: File Name Completion39122
+Node: Using TRAMP40918
+Node: Buffer Name Completion42365
+Node: Counsel commands42980
+Node: API43627
+Node: Required arguments for ivy-read44225
+Node: Optional arguments for ivy-read44744
+Node: Example - counsel-describe-function48170
+Node: Example - counsel-locate51413
+Node: Example - ivy-read-with-extra-properties55163
+Node: Variable Index56371
+Node: Keystroke Index63418
+
+End Tag Table
+
+
+Local Variables:
+coding: utf-8
+End:
diff --git a/packages/ivy/swiper.el b/packages/ivy/swiper.el
index 0fe6779..500ac18 100644
--- a/packages/ivy/swiper.el
+++ b/packages/ivy/swiper.el
@@ -4,8 +4,8 @@
 
 ;; Author: Oleh Krehel <address@hidden>
 ;; URL: https://github.com/abo-abo/swiper
-;; Version: 0.11.0
-;; Package-Requires: ((emacs "24.1") (ivy "0.11.0"))
+;; Version: 0.12.0
+;; Package-Requires: ((emacs "24.1") (ivy "0.12.0"))
 ;; Keywords: matching
 
 ;; This file is part of GNU Emacs.
@@ -43,23 +43,48 @@
 
 (defface swiper-match-face-1
   '((t (:inherit lazy-highlight)))
-  "The background face for `swiper' matches.")
+  "The background face for `swiper' matches."
+  :group 'ivy-faces)
 
 (defface swiper-match-face-2
   '((t (:inherit isearch)))
-  "Face for `swiper' matches modulo 1.")
+  "Face for `swiper' matches modulo 1."
+  :group 'ivy-faces)
 
 (defface swiper-match-face-3
   '((t (:inherit match)))
-  "Face for `swiper' matches modulo 2.")
+  "Face for `swiper' matches modulo 2."
+  :group 'ivy-faces)
 
 (defface swiper-match-face-4
   '((t (:inherit isearch-fail)))
-  "Face for `swiper' matches modulo 3.")
+  "Face for `swiper' matches modulo 3."
+  :group 'ivy-faces)
+
+(defface swiper-background-match-face-1
+  '((t (:inherit swiper-match-face-1)))
+  "The background face for non-current `swiper' matches."
+  :group 'ivy-faces)
+
+(defface swiper-background-match-face-2
+  '((t (:inherit swiper-match-face-2)))
+  "Face for non-current `swiper' matches modulo 1."
+  :group 'ivy-faces)
+
+(defface swiper-background-match-face-3
+  '((t (:inherit swiper-match-face-3)))
+  "Face for non-current `swiper' matches modulo 2."
+  :group 'ivy-faces)
+
+(defface swiper-background-match-face-4
+  '((t (:inherit swiper-match-face-4)))
+  "Face for non-current `swiper' matches modulo 3."
+  :group 'ivy-faces)
 
 (defface swiper-line-face
   '((t (:inherit highlight)))
-  "Face for current `swiper' line.")
+  "Face for current `swiper' line."
+  :group 'ivy-faces)
 
 (defcustom swiper-faces '(swiper-match-face-1
                           swiper-match-face-2
@@ -69,6 +94,31 @@
   :group 'ivy-faces
   :type '(repeat face))
 
+(defvar swiper-background-faces
+  '(swiper-background-match-face-1
+    swiper-background-match-face-2
+    swiper-background-match-face-3
+    swiper-background-match-face-4)
+  "Like `swiper-faces', but used for all matches except the current one.")
+
+(defun swiper--recompute-background-faces ()
+  (let ((faces '(swiper-background-match-face-1
+                 swiper-background-match-face-2
+                 swiper-background-match-face-3
+                 swiper-background-match-face-4))
+        (colir-compose-method #'colir-compose-soft-light))
+    (cl-mapc (lambda (f1 f2)
+               (let ((bg (face-background f1)))
+                 (when bg
+                   (set-face-background
+                    f2
+                    (colir-blend
+                     (colir-color-parse bg)
+                     (colir-color-parse "#ffffff"))))))
+             swiper-faces
+             faces)))
+(swiper--recompute-background-faces)
+
 (defcustom swiper-min-highlight 2
   "Only highlight matches for regexps at least this long."
   :type 'integer)
@@ -79,7 +129,8 @@
   :group 'swiper)
 
 (defcustom swiper-goto-start-of-match nil
-  "When non-nil, go to the start of the match, not its end."
+  "When non-nil, go to the start of the match, not its end.
+Treated as non-nil when searching backwards."
   :type 'boolean
   :group 'swiper)
 
@@ -93,28 +144,79 @@
     map)
   "Keymap for swiper.")
 
+(defvar swiper--query-replace-overlays nil)
+
+(defun swiper--query-replace-updatefn ()
+  (let ((lisp (ignore-errors (nth 2 (query-replace-compile-replacement 
ivy-text t)))))
+    (dolist (ov swiper--query-replace-overlays)
+      (when lisp
+        (dolist (x (overlay-get ov 'matches))
+          (setq lisp (cl-subst (cadr x) (car x) lisp :test #'equal)))
+        (setq lisp (ignore-errors (eval lisp))))
+      (overlay-put
+       ov 'after-string
+       (propertize
+        (if (stringp lisp)
+            lisp
+          ivy-text)
+        'face 'error)))))
+
+(defun swiper--query-replace-cleanup ()
+  (while swiper--query-replace-overlays
+    (delete-overlay (pop swiper--query-replace-overlays))))
+
+(defun swiper--query-replace-setup ()
+  (with-ivy-window
+    (let ((end (window-end (selected-window) t))
+          (re (ivy--regex ivy-text)))
+      (save-excursion
+        (goto-char (window-start))
+        (while (re-search-forward re end t)
+          (let ((ov (make-overlay (1- (match-end 0)) (match-end 0)))
+                (md (match-data)))
+            (overlay-put
+             ov 'matches
+             (mapcar
+              (lambda (x)
+                (list `(match-string ,x) (match-string x)))
+              (number-sequence 0 (1- (/ (length md) 2)))))
+            (push ov swiper--query-replace-overlays)))))))
+
 (defun swiper-query-replace ()
   "Start `query-replace' with string to replace from last search string."
   (interactive)
-  (if (null (window-minibuffer-p))
-      (user-error "Should only be called in the minibuffer through 
`swiper-map'")
-    (let* ((enable-recursive-minibuffers t)
-           (from (ivy--regex ivy-text))
-           (to (minibuffer-with-setup-hook
-                   (lambda ()
-                     (setq minibuffer-default
-                           (if (string-match "\\`\\\\_<\\(.*\\)\\\\_>\\'" 
ivy-text)
-                               (match-string 1 ivy-text)
-                             ivy-text)))
-                 (read-from-minibuffer (format "Query replace %s with: " 
from)))))
-      (swiper--cleanup)
-      (ivy-exit-with-action
-       (lambda (_)
-         (with-ivy-window
-           (move-beginning-of-line 1)
-           (let ((inhibit-read-only t))
-             (perform-replace from to
-                              t t nil))))))))
+  (cond ((null (window-minibuffer-p))
+         (user-error "Should only be called in the minibuffer through 
`swiper-map'"))
+        ((string= "" ivy-text)
+         (user-error "Empty input"))
+        (t
+         (swiper--query-replace-setup)
+         (unwind-protect
+              (let* ((enable-recursive-minibuffers t)
+                     (from (ivy--regex ivy-text))
+                     (default
+                      (format "\\,(concat %s)"
+                              (if (<= ivy--subexps 1)
+                                  "\\&"
+                                (mapconcat (lambda (i) (format "\\%d" i))
+                                           (number-sequence 1 ivy--subexps)
+                                           " \" \" "))))
+                     (to
+                      (query-replace-compile-replacement
+                       (ivy-read
+                        (format "Query replace %s with: " from) nil
+                        :def default
+                        :update-fn #'swiper--query-replace-updatefn)
+                       t)))
+                (swiper--cleanup)
+                (ivy-exit-with-action
+                 (lambda (_)
+                   (with-ivy-window
+                     (move-beginning-of-line 1)
+                     (let ((inhibit-read-only t))
+                       (perform-replace from to
+                                        t t nil))))))
+           (swiper--query-replace-cleanup)))))
 
 (defvar inhibit-message)
 
@@ -140,12 +242,9 @@
                     (perform-replace from to t t nil)))
              (set-window-configuration wnd-conf))))))))
 
-(defvar avy-background)
 (defvar avy-all-windows)
 (defvar avy-style)
 (defvar avy-keys)
-(declare-function avy--regex-candidates "ext:avy")
-(declare-function avy--process "ext:avy")
 (declare-function avy--overlay-post "ext:avy")
 (declare-function avy-action-goto "ext:avy")
 (declare-function avy-candidate-beg "ext:avy")
@@ -158,8 +257,8 @@
 (declare-function avy-push-mark "ext:avy")
 (declare-function avy--remove-leading-chars "ext:avy")
 
-(defun swiper--avy-candidate ()
-  (let* ((avy-all-windows nil)
+(defun swiper--avy-candidates ()
+  (let* (
          ;; We'll have overlapping overlays, so we sort all the
          ;; overlays in the visible region by their start, and then
          ;; throw out non-Swiper overlays or overlapping Swiper
@@ -169,32 +268,37 @@
                                                    (window-end)))
                                     #'< :key #'overlay-start))
          (min-overlay-start 0)
-         (overlays-for-avy (cl-remove-if-not
-                            (lambda (ov)
-                              (when (and (>= (overlay-start ov)
-                                             min-overlay-start)
-                                         (memq (overlay-get ov 'face)
-                                               swiper-faces))
-                                (setq min-overlay-start (overlay-start ov))))
-                            visible-overlays))
-         (offset (if (eq (ivy-state-caller ivy-last) 'swiper) 1 0))
-         (candidates (nconc
-                      (mapcar (lambda (ov)
-                                (cons (overlay-start ov)
-                                      (overlay-get ov 'window)))
-                              overlays-for-avy)
-                      (save-excursion
-                        (save-restriction
-                          (narrow-to-region (window-start) (window-end))
-                          (goto-char (point-min))
-                          (forward-line)
-                          (let ((win (selected-window))
-                                cands)
-                            (while (not (eobp))
-                              (push (cons (+ (point) offset) win)
-                                    cands)
-                              (forward-line))
-                            cands))))))
+         (overlays-for-avy
+          (cl-remove-if-not
+           (lambda (ov)
+             (when (and (>= (overlay-start ov)
+                            min-overlay-start)
+                        (memq (overlay-get ov 'face)
+                              (append swiper-faces swiper-background-faces)))
+               (setq min-overlay-start (overlay-start ov))))
+           visible-overlays))
+         (offset (if (eq (ivy-state-caller ivy-last) 'swiper) 1 0)))
+    (nconc
+     (mapcar (lambda (ov)
+               (cons (overlay-start ov)
+                     (overlay-get ov 'window)))
+             overlays-for-avy)
+     (save-excursion
+       (save-restriction
+         (narrow-to-region (window-start) (window-end))
+         (goto-char (point-min))
+         (forward-line)
+         (let ((win (selected-window))
+               cands)
+           (while (not (eobp))
+             (push (cons (+ (point) offset) win)
+                   cands)
+             (forward-line))
+           cands))))))
+
+(defun swiper--avy-candidate ()
+  (let ((candidates (swiper--avy-candidates))
+        (avy-all-windows nil))
     (unwind-protect
          (prog2
              (avy--make-backgrounds
@@ -208,46 +312,60 @@
            (avy-push-mark))
       (avy--done))))
 
+(defun swiper--avy-goto (candidate)
+  (cond ((let ((win (cdr-safe candidate)))
+           (and win (window-minibuffer-p win)))
+         (let ((nlines (count-lines (point-min) (point-max))))
+           (ivy-set-index
+            (+ (car (ivy--minibuffer-index-bounds
+                     ivy--index ivy--length ivy-height))
+               (line-number-at-pos (car candidate))
+               (if (or (= nlines (1+ ivy-height))
+                       (< ivy--length ivy-height))
+                   0
+                 (- ivy-height nlines))
+               -2)))
+         (ivy--exhibit)
+         (ivy-done)
+         (ivy-call))
+        ((or (consp candidate)
+             (number-or-marker-p candidate))
+         (ivy-quit-and-run
+           (avy-action-goto (avy-candidate-beg candidate))))))
+
 ;;;###autoload
 (defun swiper-avy ()
   "Jump to one of the current swiper candidates."
   (interactive)
   (unless (require 'avy nil 'noerror)
     (error "Package avy isn't installed"))
-  (unless (string= ivy-text "")
-    (let ((candidate (swiper--avy-candidate)))
-      (if (window-minibuffer-p (cdr candidate))
-          (let ((cand-text (save-excursion
-                             (goto-char (car candidate))
-                             (buffer-substring-no-properties
-                              (line-beginning-position)
-                              (line-end-position)))))
-            (ivy-set-index (cl-position-if
-                            (lambda (x) (cl-search x cand-text))
-                            ivy--old-cands))
-            (ivy--exhibit)
-            (ivy-done)
-            (ivy-call))
-        (ivy-quit-and-run
-          (avy-action-goto (avy-candidate-beg candidate)))))))
+  (cl-case (length ivy-text)
+    (0
+     (user-error "Need at least one char of input"))
+    (1
+     (let ((swiper-min-highlight 1))
+       (swiper--update-input-ivy))))
+  (swiper--avy-goto (swiper--avy-candidate)))
 
 (declare-function mc/create-fake-cursor-at-point "ext:multiple-cursors-core")
 (declare-function multiple-cursors-mode "ext:multiple-cursors-core")
 
 (defun swiper-mc ()
-  "Create a fake cursor for each `swiper' candidate."
+  "Create a fake cursor for each `swiper' candidate.
+Make sure `swiper-mc' is on `mc/cmds-to-run-once' list."
   (interactive)
   (unless (require 'multiple-cursors nil t)
     (error "Multiple-cursors isn't installed"))
   (unless (window-minibuffer-p)
     (error "Call me only from `swiper'"))
-  (let ((cands (nreverse ivy--old-cands)))
+  (let ((cands (nreverse ivy--old-cands))
+        (action (ivy--get-action ivy-last)))
     (unless (string= ivy-text "")
       (ivy-exit-with-action
        (lambda (_)
          (let (cand)
            (while (setq cand (pop cands))
-             (swiper--action cand)
+             (funcall action cand)
              (when cands
                (mc/create-fake-cursor-at-point))))
          (multiple-cursors-mode 1))))))
@@ -306,14 +424,16 @@
     twittering-mode
     vc-dir-mode
     w3m-mode
-    woman-mode)
+    woman-mode
+    xref--xref-buffer-mode)
   "List of major-modes that are incompatible with `font-lock-ensure'.")
 
 (defun swiper-font-lock-ensure-p ()
   "Return non-nil if we should `font-lock-ensure'."
   (or (derived-mode-p 'magit-mode)
       (bound-and-true-p magit-blame-mode)
-      (memq major-mode swiper-font-lock-exclude)))
+      (memq major-mode swiper-font-lock-exclude)
+      (not (derived-mode-p 'prog-mode))))
 
 (defun swiper-font-lock-ensure ()
   "Ensure the entired buffer is highlighted."
@@ -358,6 +478,15 @@
 
 (declare-function outline-show-all "outline")
 
+(defvar swiper-use-visual-line-p
+  (lambda (n-lines)
+    (and visual-line-mode
+         ;; super-slow otherwise
+         (< (buffer-size) 20000)
+         (< n-lines 400)))
+  "A predicate that decides whether `line-move' or `forward-line' is used.
+Note that `line-move' can be very slow.")
+
 (defun swiper--candidates (&optional numbers-width)
   "Return a list of this buffer lines.
 
@@ -365,10 +494,7 @@ NUMBERS-WIDTH, when specified, is used for width spec of 
line
 numbers; replaces calculating the width from buffer line count."
   (let* ((inhibit-field-text-motion t)
          (n-lines (count-lines (point-min) (point-max))))
-    (if (and visual-line-mode
-             ;; super-slow otherwise
-             (< (buffer-size) 20000)
-             (< n-lines 400))
+    (if (funcall swiper-use-visual-line-p n-lines)
         (progn
           (when (eq major-mode 'org-mode)
             (require 'outline)
@@ -383,7 +509,7 @@ numbers; replaces calculating the width from buffer line 
count."
                               (1+ (floor (log n-lines 10)))))
       (setq swiper--format-spec
             (format "%%-%dd " swiper--width))
-      (let ((line-number 0)
+      (let ((line-number 1)
             (advancer (if swiper-use-visual-line
                           (lambda (arg) (line-move arg t))
                         #'forward-line))
@@ -392,18 +518,20 @@ numbers; replaces calculating the width from buffer line 
count."
           (goto-char (point-min))
           (swiper-font-lock-ensure)
           (while (< (point) (point-max))
-            (let ((str (swiper--line)))
-              (setq str (ivy-cleanup-string str))
-              (let ((line-number-str
-                     (format swiper--format-spec (cl-incf line-number))))
-                (if swiper-include-line-number-in-search
-                    (setq str (concat line-number-str str))
+            (when (swiper-match-usable-p)
+              (let ((str (swiper--line)))
+                (setq str (ivy-cleanup-string str))
+                (let ((line-number-str
+                       (format swiper--format-spec line-number)))
+                  (if swiper-include-line-number-in-search
+                      (setq str (concat line-number-str str))
+                    (put-text-property
+                     0 1 'display line-number-str str))
                   (put-text-property
-                   0 1 'display line-number-str str))
-                (put-text-property
-                 0 1 'swiper-line-number line-number-str str))
-              (push str candidates))
-            (funcall advancer 1))
+                   0 1 'swiper-line-number line-number-str str))
+                (push str candidates)))
+            (funcall advancer 1)
+            (cl-incf line-number))
           (nreverse candidates))))))
 
 (defvar swiper--opoint 1
@@ -411,12 +539,42 @@ numbers; replaces calculating the width from buffer line 
count."
 
 ;;;###autoload
 (defun swiper (&optional initial-input)
-  "`isearch' with an overview.
+  "`isearch-forward' with an overview.
 When non-nil, INITIAL-INPUT is the initial search pattern."
   (interactive)
   (swiper--ivy (swiper--candidates) initial-input))
 
-(defvar swiper--current-window-start nil)
+;;;###autoload
+(defun swiper-backward (&optional initial-input)
+  "`isearch-backward' with an overview.
+When non-nil, INITIAL-INPUT is the initial search pattern."
+  (interactive)
+  (let ((ivy-index-functions-alist
+         '((swiper . ivy-recompute-index-swiper-backward))))
+    (swiper initial-input)))
+
+;;;###autoload
+(defun swiper-thing-at-point ()
+  "`swiper' with `ivy-thing-at-point'."
+  (interactive)
+  (let ((thing (ivy-thing-at-point)))
+    (when (use-region-p)
+      (deactivate-mark))
+    (swiper thing)))
+
+;;;###autoload
+(defun swiper-all-thing-at-point ()
+  "`swiper-all' with `ivy-thing-at-point'."
+  (interactive)
+  (let ((thing (ivy-thing-at-point)))
+    (when (use-region-p)
+      (deactivate-mark))
+    (swiper-all thing)))
+
+(defvar swiper--current-window-start nil
+  "Store `window-start' to restore it later.
+This prevents a \"jumping\" behavior which occurs when variables
+such as `scroll-conservatively' are set to a high value.")
 
 (defun swiper--extract-matches (regex cands)
   "Extract captured REGEX groups from CANDS."
@@ -432,6 +590,45 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
               res)))
     (nreverse res)))
 
+(defun swiper--occur-cands (fname cands)
+  (when cands
+    (with-current-buffer (ivy-state-buffer ivy-last)
+      (when (eq (ivy-state-caller ivy-last) 'swiper-isearch)
+        (setq cands (mapcar #'swiper--line-at-point cands)))
+      (let* ((pt-min (point-min))
+             (line-delta
+              (save-restriction
+                (widen)
+                (1- (line-number-at-pos pt-min))))
+             (lines
+              (if (eq (ivy-state-caller ivy-last) 'swiper-isearch)
+                  (swiper--isearch-occur-cands cands)
+                (mapcar (lambda (s)
+                          (let ((l (get-text-property 0 'swiper-line-number 
s)))
+                            (setq s (substring s 1))
+                            (put-text-property 0 1 'swiper-line-number l s)
+                            (cons (read l) s)))
+                        cands)))
+             (offset (+ (length fname) 2)))
+        (mapcar (lambda (x)
+                  (let ((nn (number-to-string
+                             (+ (car x) line-delta))))
+                    (put-text-property 0 (length nn) 'face 
'ivy-grep-line-number nn)
+                    (put-text-property 0 1 'offset (+ offset (length nn)) 
fname)
+                    (format "%s:%s:%s" fname nn (cdr x))))
+                lines)))))
+
+(defun swiper--isearch-occur-cands (cands)
+  (let* ((last-pt (get-text-property 0 'point (car cands)))
+         (line (1+ (line-number-at-pos last-pt)))
+         res pt)
+    (dolist (cand cands)
+      (setq pt (get-text-property 0 'point cand))
+      (cl-incf line (1- (count-lines last-pt pt)))
+      (push (cons line cand) res)
+      (setq last-pt pt))
+    (nreverse res)))
+
 (defun swiper-occur (&optional revert)
   "Generate a custom occur buffer for `swiper'.
 When REVERT is non-nil, regenerate the current *ivy-occur* buffer.
@@ -445,23 +642,21 @@ When capture groups are present in the input, print them 
instead of lines."
                      (buffer-name buffer)))
                  'face
                  'ivy-grep-info))
-         (re (progn (string-match "\"\\(.*\\)\"" (buffer-name))
-                    (match-string 1 (buffer-name))))
-         (re (mapconcat #'identity (ivy--split re) ".*?"))
+         (ivy-text (progn (string-match "\"\\(.*\\)\"" (buffer-name))
+                          (match-string 1 (buffer-name))))
+         (re (mapconcat #'identity (ivy--split ivy-text) ".*?"))
          (cands
-          (mapcar
-           (lambda (s)
-             (let* ((n (get-text-property 0 'swiper-line-number s))
-                    (i (string-match-p "[ \t\n\r]+\\'" n)))
-               (when i (setq n (substring n 0 i)))
-               (put-text-property 0 (length n) 'face 'ivy-grep-line-number n)
-               (format "%s:%s:%s" fname n (substring s 1))))
+          (swiper--occur-cands
+           fname
            (if (not revert)
                ivy--old-cands
              (setq ivy--old-re nil)
-             (let ((ivy--regex-function 'swiper--re-builder))
-               (ivy--filter re (with-current-buffer buffer
-                                 (swiper--candidates))))))))
+             (save-window-excursion
+               (switch-to-buffer buffer)
+               (if (eq (ivy-state-caller ivy-last) 'swiper)
+                   (let ((ivy--regex-function 'swiper--re-builder))
+                     (ivy--filter re (swiper--candidates)))
+                 (swiper-isearch-function ivy-text)))))))
     (if (string-match-p "\\\\(" re)
         (insert
          (mapconcat #'identity
@@ -504,6 +699,8 @@ When capture groups are present in the input, print them 
instead of lines."
   (when (setq swiper--reveal-mode
               (bound-and-true-p reveal-mode))
     (reveal-mode -1))
+  (lazy-highlight-cleanup t)
+  (setq isearch-opened-overlays nil)
   (when (bound-and-true-p evil-mode)
     (evil-set-jump)))
 
@@ -533,7 +730,12 @@ line numbers.  For the buffer, use `ivy--regex' instead."
                         (setq ivy--subexps 1))
                     (format "^ %s" re))))
                ((eq (bound-and-true-p search-default-mode) 
'char-fold-to-regexp)
-                (mapconcat #'char-fold-to-regexp (ivy--split str) ".*"))
+                (let ((subs (ivy--split str)))
+                  (setq ivy--subexps (length subs))
+                  (mapconcat
+                   (lambda (s) (format "\\(%s\\)" (char-fold-to-regexp s)))
+                   subs
+                   ".*?")))
                (t
                 (funcall re-builder str)))))
     re))
@@ -555,7 +757,7 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
   (setq swiper-invocation-face
         (plist-get (text-properties-at (point)) 'face))
   (let ((preselect
-         (if swiper-use-visual-line
+         (if (or swiper-use-visual-line (null search-invisible))
              (count-screen-lines
               (point-min)
               (save-excursion (beginning-of-visual-line) (point)))
@@ -625,24 +827,71 @@ Matched candidates should have `swiper-invocation-face'."
 (defvar swiper--overlays nil
   "Store overlays.")
 
+(defvar swiper--isearch-highlight-timer nil
+  "This timer used by `swiper--delayed-add-overlays'.")
+
 (defun swiper--cleanup ()
   "Clean up the overlays."
   (while swiper--overlays
     (delete-overlay (pop swiper--overlays)))
-  (save-excursion
-    (goto-char (point-min))
-    (isearch-clean-overlays)))
+  ;; force cleanup unless it's :unwind
+  (lazy-highlight-cleanup
+   (if (eq ivy-exit 'done) lazy-highlight-cleanup t))
+  (when (timerp swiper--isearch-highlight-timer)
+    (cancel-timer swiper--isearch-highlight-timer)
+    (setq swiper--isearch-highlight-timer nil)))
+
+(defun swiper--add-cursor-overlay (wnd)
+  (let* ((special (or (eolp) (looking-at "\t")))
+         (ov (make-overlay (point) (if special (point) (1+ (point))))))
+    (if special
+        (overlay-put ov 'after-string (propertize " " 'face 'ivy-cursor))
+      (overlay-put ov 'face 'ivy-cursor))
+    (overlay-put ov 'window wnd)
+    (overlay-put ov 'priority 2)
+    (push ov swiper--overlays)))
+
+(defun swiper--add-line-overlay (wnd)
+  (let ((beg (if visual-line-mode
+                 (save-excursion
+                   (beginning-of-visual-line)
+                   (point))
+               (line-beginning-position)))
+        (end (if visual-line-mode
+                 (save-excursion
+                   (end-of-visual-line)
+                   (point))
+               (1+ (line-end-position)))))
+    (push (swiper--make-overlay beg end 'swiper-line-face wnd 0)
+          swiper--overlays)))
+
+(defun swiper--make-overlay (beg end face wnd priority)
+  "Create an overlay bound by BEG and END.
+FACE, WND and PRIORITY are properties corresponding to
+the face, window and priority of the overlay."
+  (let ((overlay (make-overlay beg end)))
+    (overlay-put overlay 'face face)
+    (overlay-put overlay 'window wnd)
+    (overlay-put overlay 'priority priority)
+    overlay))
+
+(defun swiper--recenter-p ()
+  (or (display-graphic-p)
+      (not recenter-redisplay)))
+
+(defun swiper--positive-regexps (str)
+  (let ((regexp-or-regexps
+         (funcall ivy--regex-function str)))
+    (if (listp regexp-or-regexps)
+        (mapcar #'car (cl-remove-if-not #'cdr regexp-or-regexps))
+      (list regexp-or-regexps))))
 
 (defun swiper--update-input-ivy ()
   "Called when `ivy' input is updated."
   (with-ivy-window
     (swiper--cleanup)
     (when (> (length (ivy-state-current ivy-last)) 0)
-      (let* ((regexp-or-regexps (funcall ivy--regex-function ivy-text))
-             (regexps
-              (if (listp regexp-or-regexps)
-                  (mapcar #'car (cl-remove-if-not #'cdr regexp-or-regexps))
-                (list regexp-or-regexps))))
+      (let ((regexps (swiper--positive-regexps ivy-text)))
         (dolist (re regexps)
           (let* ((re (replace-regexp-in-string
                       "    " "\t"
@@ -675,54 +924,58 @@ Matched candidates should have `swiper-invocation-face'."
                     (setq swiper--current-match-start (match-beginning 0))))
                 (isearch-range-invisible (line-beginning-position)
                                          (line-end-position))
-                (unless (and (>= (point) (window-start))
-                             (<= (point) (window-end (ivy-state-window 
ivy-last) t)))
+                (when (and (swiper--recenter-p)
+                           (or
+                            (< (point) (window-start))
+                            (> (point) (window-end (ivy-state-window ivy-last) 
t))))
                   (recenter))
                 (setq swiper--current-window-start (window-start))))
             (swiper--add-overlays
              re
-             (max (window-start) swiper--point-min)
-             (min (window-end (selected-window) t) swiper--point-max))))))))
+             (max
+              (if (swiper--recenter-p)
+                  (window-start)
+                (line-beginning-position (- (window-height))))
+              swiper--point-min)
+             (min
+              (if (swiper--recenter-p)
+                  (window-end (selected-window) t)
+                (line-end-position (window-height)))
+              swiper--point-max))))))))
 
 (defun swiper--add-overlays (re &optional beg end wnd)
   "Add overlays for RE regexp in visible part of the current buffer.
 BEG and END, when specified, are the point bounds.
 WND, when specified is the window."
   (setq wnd (or wnd (ivy-state-window ivy-last)))
-  (let ((ov (if visual-line-mode
-                (make-overlay
-                 (save-excursion
-                   (beginning-of-visual-line)
-                   (point))
-                 (save-excursion
-                   (end-of-visual-line)
-                   (point)))
-              (make-overlay
-               (line-beginning-position)
-               (1+ (line-end-position))))))
-    (overlay-put ov 'face 'swiper-line-face)
-    (overlay-put ov 'window wnd)
-    (push ov swiper--overlays)
-    (let* ((wh (window-height))
-           (beg (or beg (save-excursion
-                          (forward-line (- wh))
-                          (point))))
-           (end (or end (save-excursion
-                          (forward-line wh)
-                          (point))))
-           (case-fold-search (ivy--case-fold-p re)))
-      (when (>= (length re) swiper-min-highlight)
-        (save-excursion
-          (goto-char beg)
-          ;; RE can become an invalid regexp
-          (while (and (ignore-errors (re-search-forward re end t))
-                      (> (- (match-end 0) (match-beginning 0)) 0))
-            ;; Don't highlight a match if it spans multiple
-            ;; lines. `count-lines' returns 1 if the match is within a
-            ;; single line, even if it includes the newline, and 2 or
-            ;; greater otherwise. We hope that the inclusion of the
-            ;; newline will not ever be a problem in practice.
-            (when (< (count-lines (match-beginning 0) (match-end 0)) 2)
+  (swiper--add-line-overlay wnd)
+  (let* ((pt (point))
+         (wh (window-height))
+         (beg (or beg (save-excursion
+                        (forward-line (- wh))
+                        (point))))
+         (end (or end (save-excursion
+                        (forward-line wh)
+                        (point))))
+         (case-fold-search (ivy--case-fold-p re)))
+    (when (>= (length re) swiper-min-highlight)
+      (save-excursion
+        (goto-char beg)
+        ;; RE can become an invalid regexp
+        (while (and (ignore-errors (re-search-forward re end t))
+                    (> (- (match-end 0) (match-beginning 0)) 0))
+          ;; Don't highlight a match if it spans multiple
+          ;; lines. `count-lines' returns 1 if the match is within a
+          ;; single line, even if it includes the newline, and 2 or
+          ;; greater otherwise. We hope that the inclusion of the
+          ;; newline will not ever be a problem in practice.
+          (when (< (count-lines (match-beginning 0) (match-end 0)) 2)
+            (let* ((faces (if (= (match-end 0) pt)
+                              swiper-faces
+                            swiper-background-faces))
+                   (adder-fn (lambda (beg end face priority)
+                               (push (swiper--make-overlay beg end face wnd 
priority)
+                                     isearch-lazy-highlight-overlays))))
               (unless (and (consp ivy--old-re)
                            (null
                             (save-match-data
@@ -731,41 +984,35 @@ WND, when specified is the window."
                                                (buffer-substring-no-properties
                                                 (line-beginning-position)
                                                 (line-end-position)))))))
-                (let ((mb (match-beginning 0))
-                      (me (match-end 0)))
-                  (unless (> (- me mb) 2017)
-                    (swiper--add-overlay mb me
-                                         (if (zerop ivy--subexps)
-                                             (cadr swiper-faces)
-                                           (car swiper-faces))
-                                         wnd 0))))
-              (let ((i 1)
-                    (j 0))
-                (while (<= (cl-incf j) ivy--subexps)
-                  (let ((bm (match-beginning j))
-                        (em (match-end j)))
-                    (when (and (integerp em)
-                               (integerp bm))
-                      (while (and (< j ivy--subexps)
-                                  (integerp (match-beginning (+ j 1)))
-                                  (= em (match-beginning (+ j 1))))
-                        (setq em (match-end (cl-incf j))))
-                      (swiper--add-overlay
-                       bm em
-                       (nth (1+ (mod (+ i 2) (1- (length swiper-faces))))
-                            swiper-faces)
-                       wnd i)
-                      (cl-incf i))))))))))))
-
-(defun swiper--add-overlay (beg end face wnd priority)
-  "Add overlay bound by BEG and END to `swiper--overlays'.
-FACE, WND and PRIORITY are properties corresponding to
-the face, window and priority of the overlay."
-  (let ((overlay (make-overlay beg end)))
-    (push overlay swiper--overlays)
-    (overlay-put overlay 'face face)
-    (overlay-put overlay 'window wnd)
-    (overlay-put overlay 'priority priority)))
+                (swiper--add-properties faces adder-fn)))))))))
+
+(defun swiper--add-properties (faces adder-fn)
+  (let ((mb (match-beginning 0))
+        (me (match-end 0)))
+    (unless (> (- me mb) 2017)
+      (funcall adder-fn
+               mb me
+               (if (zerop ivy--subexps)
+                   (cadr faces)
+                 (car faces))
+               0)))
+  (let ((i 1)
+        (j 0))
+    (while (<= (cl-incf j) ivy--subexps)
+      (let ((bm (match-beginning j))
+            (em (match-end j)))
+        (when (and (integerp em)
+                   (integerp bm))
+          (while (and (< j ivy--subexps)
+                      (integerp (match-beginning (+ j 1)))
+                      (= em (match-beginning (+ j 1))))
+            (setq em (match-end (cl-incf j))))
+          (funcall adder-fn
+                   bm em
+                   (nth (1+ (mod (+ i 2) (1- (length faces))))
+                        faces)
+                   i)
+          (cl-incf i))))))
 
 (defcustom swiper-action-recenter nil
   "When non-nil, recenter after exiting `swiper'."
@@ -779,9 +1026,7 @@ the face, window and priority of the overlay."
 
 (defun swiper--action (x)
   "Goto line X."
-  (let ((ln (1- (read (or (get-text-property 0 'swiper-line-number x)
-                          (and (string-match ":\\([0-9]+\\):.*\\'" x)
-                               (match-string-no-properties 1 x))))))
+  (let ((ln (1- (read (get-text-property 0 'swiper-line-number x))))
         (re (ivy--regex ivy-text)))
     (if (null x)
         (user-error "No candidates")
@@ -789,7 +1034,10 @@ the face, window and priority of the overlay."
         (unless (equal (current-buffer)
                        (ivy-state-buffer ivy-last))
           (switch-to-buffer (ivy-state-buffer ivy-last)))
-        (goto-char swiper--point-min)
+        (goto-char
+         (if (buffer-narrowed-p)
+             swiper--point-min
+           (point-min)))
         (funcall (if swiper-use-visual-line
                      #'line-move
                    #'forward-line)
@@ -799,7 +1047,8 @@ the face, window and priority of the overlay."
         (swiper--ensure-visible)
         (cond (swiper-action-recenter
                (recenter))
-              (swiper--current-window-start
+              ((and swiper--current-window-start
+                    (swiper--recenter-p))
                (set-window-start (selected-window) 
swiper--current-window-start)))
         (when (/= (point) swiper--opoint)
           (unless (and transient-mark-mode mark-active)
@@ -841,6 +1090,8 @@ the face, window and priority of the overlay."
   (format "Buffers (%s): "
           (mapconcat #'identity swiper-multi-buffers ", ")))
 
+(defvar swiper-window-width 80)
+
 (defun swiper-multi ()
   "Select one or more buffers.
 Run `swiper' for those buffers."
@@ -850,10 +1101,11 @@ Run `swiper' for those buffers."
     (ivy-read (swiper-multi-prompt)
               #'internal-complete-buffer
               :action #'swiper-multi-action-1))
-  (ivy-read "Swiper: " swiper-multi-candidates
-            :action #'swiper-multi-action-2
-            :unwind #'swiper--cleanup
-            :caller 'swiper-multi))
+  (let ((swiper-window-width (- (- (frame-width) (if (display-graphic-p) 0 1)) 
4)))
+    (ivy-read "Swiper: " swiper-multi-candidates
+              :action #'swiper-multi-action-2
+              :unwind #'swiper--cleanup
+              :caller 'swiper-multi)))
 
 (defun swiper-multi-action-1 (x)
   "Add X to list of selected buffers `swiper-multi-buffers'.
@@ -951,11 +1203,9 @@ otherwise continue prompting for buffers."
          (list "")
        (setq ivy--old-cands (nreverse cands))))))
 
-(defvar swiper-window-width 80)
-
 (defun swiper--all-format-function (cands)
   "Format CANDS for `swiper-all'.
-See `ivy-format-function' for further information."
+See `ivy-format-functions-alist' for further information."
   (let* ((ww swiper-window-width)
          (col2 1)
          (cands-with-buffer
@@ -995,18 +1245,18 @@ See `ivy-format-function' for further information."
 (defun swiper-all (&optional initial-input)
   "Run `swiper' for all open buffers."
   (interactive)
-  (let* ((swiper-window-width (- (frame-width) (if (display-graphic-p) 0 1)))
-         (ivy-format-function #'swiper--all-format-function))
+  (let ((swiper-window-width (- (frame-width) (if (display-graphic-p) 0 1))))
     (ivy-read "swiper-all: " 'swiper-all-function
               :action #'swiper-all-action
               :unwind #'swiper--cleanup
-              :update-fn (lambda ()
-                           (swiper-all-action (ivy-state-current ivy-last)))
+              :update-fn 'auto
               :dynamic-collection t
               :keymap swiper-all-map
               :initial-input initial-input
               :caller 'swiper-multi)))
 
+(add-to-list 'ivy-format-functions-alist '(swiper-multi . 
swiper--all-format-function))
+
 (defun swiper-all-action (x)
   "Move to candidate X from `swiper-all'."
   (when (> (length x) 0)
@@ -1023,38 +1273,312 @@ See `ivy-format-function' for further information."
 
 (defun swiper--multi-candidates (buffers)
   "Extract candidates from BUFFERS."
-  (let* ((ww (window-width))
-         (res nil)
-         (column-2 (apply #'max
-                          (mapcar
-                           (lambda (b)
-                             (length (buffer-name b)))
-                           buffers)))
-         (column-1 (- ww 4 column-2 1)))
+  (let ((res nil))
     (dolist (buf buffers)
       (with-current-buffer buf
         (setq res
-              (append
+              (nconc
                (mapcar
-                (lambda (s)
-                  (setq s (concat (ivy--truncate-string s column-1) " "))
-                  (let ((len (length s)))
-                    (put-text-property
-                     (1- len) len 'display
-                     (concat
-                      (make-string
-                       (max 0
-                            (- ww (string-width s) (length (buffer-name)) 3))
-                       ?\ )
-                      (buffer-name))
-                     s)
-                    (put-text-property 0 len 'buffer buf s)
-                    s))
+                (lambda (s) (put-text-property 0 1 'buffer (buffer-name) s) s)
                 (swiper--candidates 4))
-               res))
-        nil))
+               res))))
     res))
 
+;;* `swiper-isearch'
+(defvar swiper--isearch-point-history nil
+  "Store the current input and point history for a single search.
+Each element is a cons cell of an input and a point position that
+corresponds to it.
+
+This ensures that if the user enters \"ab\", the point will
+come back to the same place as when \"a\" was initially entered.")
+
+(defun swiper-isearch-function (str)
+  "Collect STR matches in the current buffer for `swiper-isearch'."
+  (with-ivy-window
+    (swiper--isearch-function str)))
+
+(defun swiper-match-usable-p ()
+  (or search-invisible
+      (not (cl-find-if
+            (lambda (ov)
+              (invisible-p (overlay-get ov 'invisible)))
+            (overlays-at (point))))))
+
+(defvar swiper--isearch-backward nil)
+
+(defun swiper--isearch-function (str)
+  (let* ((case-fold-search (ivy--case-fold-p str))
+         (re-full (funcall ivy--regex-function str))
+         (re (ivy-re-to-str re-full)))
+    (unless (string= re "")
+      (let ((re (if (string-match "\\`\\(.*\\)[\\]|\\'" re)
+                    (match-string 1 re)
+                  re))
+            (pt-hist (cdr (assoc str swiper--isearch-point-history)))
+            cands
+            idx-found
+            (idx 0))
+        (save-excursion
+          (goto-char (if swiper--isearch-backward (point-max) (point-min)))
+          (while (funcall (if swiper--isearch-backward #'re-search-backward 
#'re-search-forward) re nil t)
+            (when (swiper-match-usable-p)
+              (unless idx-found
+                (when (or
+                       (eq (match-beginning 0) pt-hist)
+                       (if swiper--isearch-backward
+                           (<= (match-beginning 0) (cdar 
swiper--isearch-point-history))
+                         (>= (match-beginning 0) (cdar 
swiper--isearch-point-history))))
+                  (push (cons str (match-beginning 0)) 
swiper--isearch-point-history)
+                  (setq idx-found idx)))
+              (cl-incf idx)
+              (let ((pos (if (or swiper--isearch-backward 
swiper-goto-start-of-match)
+                             (match-beginning 0)
+                           (point))))
+                (push pos cands)))))
+        (setq ivy--old-re re)
+        (when idx-found
+          (ivy-set-index (if swiper--isearch-backward
+                             (- (length cands) idx-found 1)
+                           idx-found)))
+        (setq ivy--old-cands (if swiper--isearch-backward
+                                 cands
+                               (nreverse cands)))))))
+
+(defcustom swiper-isearch-highlight-delay '(2 0.2)
+  "When `ivy-text' is too short, delay showing the overlay.
+
+The default value will delay showing the overlay by 0.2 seconds
+if `ivy-text' is shorter than 2 characters.
+
+The aim is to reduce the visual clutter, since it's very rare
+that we search only for one character."
+  :type '(list
+          (integer :tag "Text length")
+          (float :tag "Delay in seconds")))
+
+(defun swiper--delayed-add-overlays ()
+  (if (and swiper-isearch-highlight-delay
+           (< (length ivy-text) (car swiper-isearch-highlight-delay)))
+      (setq swiper--isearch-highlight-timer
+            (run-with-idle-timer
+             (cadr swiper-isearch-highlight-delay) nil
+             (lambda ()
+               (with-ivy-window
+                 (swiper--add-overlays (ivy--regex ivy-text))))))
+    (dolist (re (swiper--positive-regexps ivy-text))
+      (swiper--add-overlays re))))
+
+(defun swiper-isearch-action (x)
+  "Move to X for `swiper-isearch'."
+  (if (or (numberp x)
+          (and (> (length x) 0)
+               (setq x (get-text-property 0 'point x))))
+      (with-ivy-window
+        (goto-char x)
+        (isearch-range-invisible (point) (1+ (point)))
+        (when swiper-action-recenter
+          (recenter))
+        (unless (eq ivy-exit 'done)
+          (swiper--cleanup)
+          (swiper--delayed-add-overlays)
+          (swiper--add-cursor-overlay
+           (ivy-state-window ivy-last))))
+    (swiper--cleanup)))
+
+(defun swiper-isearch-thing-at-point ()
+  "Insert `symbol-at-point' into the minibuffer of `swiper-isearch'.
+When not running `swiper-isearch' already, start it."
+  (interactive)
+  (if (window-minibuffer-p)
+      (let (bnd str regionp)
+        (with-ivy-window
+          (setq bnd
+                (if (setq regionp (region-active-p))
+                    (prog1 (cons (region-beginning) (region-end))
+                      (deactivate-mark))
+                  (bounds-of-thing-at-point 'symbol)))
+          (setq str (buffer-substring-no-properties (car bnd) (cdr bnd))))
+        (setq swiper--isearch-point-history
+              (list (cons "" (car bnd))))
+        (insert str)
+        (unless regionp
+          (ivy--insert-symbol-boundaries)))
+    (let (thing)
+      (if (use-region-p)
+          (progn
+            (setq thing (buffer-substring-no-properties
+                         (region-beginning) (region-end)))
+            (goto-char (region-beginning))
+            (deactivate-mark))
+        (let ((bnd (bounds-of-thing-at-point 'symbol)))
+          (when bnd
+            (goto-char (car bnd)))
+          (setq thing (ivy-thing-at-point))))
+      (swiper-isearch thing))))
+
+(defvar swiper-isearch-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map swiper-map)
+    (define-key map (kbd "M-n") 'swiper-isearch-thing-at-point)
+    map)
+  "Keymap for `swiper-isearch'.")
+
+(defun swiper--isearch-same-line-p (s1 s2)
+  "Check if S1 and S2 are equal and on the same line."
+  (and (equal s1 s2)
+       (<= (count-lines
+            (get-text-property 0 'point s2)
+            (get-text-property 0 'point s1))
+           1)))
+
+(defun swiper-isearch-format-function (cands)
+  (if (numberp (car-safe cands))
+      (swiper--isearch-format
+       ivy--index ivy--length ivy--old-cands
+       ivy--old-re
+       (ivy-state-current ivy-last)
+       (ivy-state-buffer ivy-last))
+    (ivy-format-function-default cands)))
+
+(defun swiper--line-at-point (pt)
+  (save-excursion
+    (goto-char pt)
+    (let ((s (buffer-substring
+              (line-beginning-position)
+              (line-end-position))))
+      (put-text-property 0 1 'point pt s)
+      (ivy-cleanup-string s))))
+
+(defun swiper--isearch-highlight (str &optional current)
+  (let ((start 0)
+        (i 0))
+    (while (string-match ivy--old-re str start)
+      (setq start (match-end 0))
+      (swiper--add-properties
+       (if (eq current i)
+           swiper-faces
+         swiper-background-faces)
+       (lambda (beg end face _priority)
+         (ivy-add-face-text-property
+          beg end face str)))
+      (cl-incf i))
+    str))
+
+(defun swiper--isearch-format (index length cands regex current buffer)
+  (let* ((half-height (/ ivy-height 2))
+         (i (1- index))
+         (j 0)
+         (len 0)
+         res s)
+    (with-current-buffer buffer
+      (while (and (>= i 0)
+                  (swiper--isearch-same-line-p
+                   (swiper--line-at-point (nth i cands))
+                   (swiper--line-at-point current)))
+        (cl-decf i)
+        (cl-incf j))
+      (while (and (>= i 0)
+                  (< len half-height))
+        (setq s (swiper--line-at-point (nth i cands)))
+        (unless (swiper--isearch-same-line-p s (car res))
+          (push (swiper--isearch-highlight s) res)
+          (cl-incf len))
+        (cl-decf i))
+      (setq res (nreverse res))
+      (let ((current-str
+             (swiper--line-at-point current))
+            (start 0))
+        (dotimes (_ (1+ j))
+          (string-match regex current-str start)
+          (setq start (match-end 0)))
+        (swiper--isearch-highlight current-str j)
+        (font-lock-append-text-property
+         0 (length current-str)
+         'face 'swiper-line-face current-str)
+        (push current-str res))
+      (cl-incf len)
+      (setq i (1+ index))
+      (while (and (< i length)
+                  (swiper--isearch-same-line-p
+                   (swiper--line-at-point (nth i cands))
+                   (swiper--line-at-point current)))
+        (cl-incf i))
+      (while (and (< i length)
+                  (< len ivy-height))
+        (setq s (swiper--line-at-point (nth i cands)))
+        (unless (swiper--isearch-same-line-p s (car res))
+          (push (swiper--isearch-highlight s) res)
+          (cl-incf len))
+        (cl-incf i))
+      (mapconcat #'identity (nreverse res) "\n"))))
+
+;;;###autoload
+(defun swiper-isearch (&optional initial-input)
+  "A `swiper' that's not line-based."
+  (interactive)
+  (swiper--init)
+  (swiper-font-lock-ensure)
+  (setq swiper--isearch-point-history
+        (list
+         (cons "" (- (point) (if swiper--isearch-backward 1 0)))))
+  (let ((ivy-fixed-height-minibuffer t)
+        (cursor-in-non-selected-windows nil)
+        (swiper-min-highlight 1)
+        res)
+    (unwind-protect
+         (and
+          (setq res
+                (ivy-read
+                 "Swiper: "
+                 #'swiper-isearch-function
+                 :initial-input initial-input
+                 :keymap swiper-isearch-map
+                 :dynamic-collection t
+                 :require-match t
+                 :action #'swiper-isearch-action
+                 :update-fn 'auto
+                 :unwind #'swiper--cleanup
+                 :re-builder #'swiper--re-builder
+                 :history 'swiper-history
+                 :caller 'swiper-isearch))
+          (point))
+      (unless (or res swiper-stay-on-quit)
+        (goto-char swiper--opoint))
+      (isearch-clean-overlays)
+      (unless (or res (string= ivy-text ""))
+        (cl-pushnew ivy-text swiper-history)))))
+
+;;;###autoload
+(defun swiper-isearch-backward (&optional initial-input)
+  "Like `swiper-isearch' but the first result is before the point."
+  (interactive)
+  (let ((swiper--isearch-backward t))
+    (swiper-isearch initial-input)))
+
+(add-to-list 'ivy-format-functions-alist '(swiper-isearch . 
swiper-isearch-format-function))
+(ivy-set-occur 'swiper-isearch 'swiper-occur)
+
+(defun swiper-isearch-toggle ()
+  "Two-way toggle between `swiper-isearch' and isearch.
+Intended to be bound in `isearch-mode-map' and `swiper-map'."
+  (interactive)
+  (if isearch-mode
+      (let ((query (if isearch-regexp
+                       isearch-string
+                     (regexp-quote isearch-string))))
+        (isearch-exit)
+        (goto-char (or (and isearch-forward isearch-other-end)
+                       (point)))
+        (swiper-isearch query))
+    (ivy-exit-with-action
+     (lambda (_)
+       (when (looking-back ivy--old-re (line-beginning-position))
+         (goto-char (match-beginning 0)))
+       (isearch-mode t)
+       (unless (string= ivy-text "")
+         (isearch-yank-string ivy-text))))))
+
 (provide 'swiper)
 
 ;;; swiper.el ends here



reply via email to

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