]> code.delx.au - gnu-emacs-elpa/blobdiff - ivy.el
ivy.el (ivy-use-virtual-buffers): Update docstring
[gnu-emacs-elpa] / ivy.el
diff --git a/ivy.el b/ivy.el
index 6c3c7892b663ab55fca7f83ef972ac13dfcc78bb..04dd2dc0b85244027533d6d8c042ae30473a7d03 100644 (file)
--- a/ivy.el
+++ b/ivy.el
 Set this to nil if you don't want the count.  You can also set it
 to e.g. \"(%d/%d) \" if you want to see both the candidate index
 and the candidate count."
-  :type '(choice (const :tag "Count disabled" nil) string))
+  :type '(choice
+          (const :tag "Count disabled" nil)
+          (const :tag "Count matches" "%-4d ")
+          (const :tag "Count matches and show current match" "(%d/%d) ")
+          string))
 
 (defcustom ivy-wrap nil
   "Whether to wrap around after the first and last candidate."
   :type 'boolean)
 
-(defcustom ivy-display-style nil
+(defcustom ivy-display-style (unless (version< emacs-version "24.5") 'fancy)
   "The style for formatting the minibuffer.
 
 By default, the matched strings will be copied as they are.
 
 With the fancy method, the matching parts of the regexp will be
-additionally highlighted, just like `swiper' does it."
+additionally highlighted, just like `swiper' does it.
+
+This setting depends on `add-face-text-property' - a C function
+available as of 24.5. It will behave poorly in earlier Emacs
+versions."
   :type '(choice
           (const :tag "Plain" nil)
           (const :tag "Fancy" fancy)))
@@ -103,7 +111,7 @@ Only \"./\" and \"../\" apply here. They appear in reverse order."
   :type 'list)
 
 (defcustom ivy-use-virtual-buffers nil
-  "When non-nil, add `recentf-mode' and bookmarks to the list of buffers."
+  "When non-nil, add `recentf-mode' and bookmarks to `ivy-switch-buffer'."
   :type 'boolean)
 
 (defvar ivy--actions-list nil
@@ -608,7 +616,8 @@ If the input is empty, select the previous history element instead."
         (prog1 (funcall action x)
           (unless (or (eq ivy-exit 'done)
                       (equal (selected-window)
-                             (active-minibuffer-window)))
+                             (active-minibuffer-window))
+                      (null (active-minibuffer-window)))
             (select-window (active-minibuffer-window))))))))
 
 (defun ivy-next-line-and-call (&optional arg)
@@ -1013,7 +1022,9 @@ This is useful for recursive `ivy-read'."
                              (string= preselect-directory
                                       default-directory))
                    (setq ivy--directory preselect-directory))
-                 (setq preselect (file-name-nondirectory preselect))))
+                 (setf
+                  (ivy-state-preselect state)
+                  (setq preselect (file-name-nondirectory preselect)))))
              (setq coll (ivy--sorted-files ivy--directory))
              (when initial-input
                (unless (or require-match
@@ -1026,10 +1037,9 @@ This is useful for recursive `ivy-read'."
             ((or (functionp collection)
                  (byte-code-function-p collection)
                  (vectorp collection)
-                 (listp (car collection)))
+                 (and (consp collection) (listp (car collection)))
+                 (hash-table-p collection))
              (setq coll (all-completions "" collection predicate)))
-            ((hash-table-p collection)
-             (error "Hash table as a collection unsupported"))
             (t
              (setq coll collection)))
       (when sort
@@ -1160,10 +1170,12 @@ When MATCHER is non-nil it's used instead of `cl-remove-if-not'."
     (when matcher
       (setq candidates (funcall matcher "" candidates))))
   (or (cl-position preselect candidates :test #'equal)
-      (cl-position-if
-       (lambda (x)
-         (string-match (regexp-quote preselect) x))
-       candidates)))
+      (and (stringp preselect)
+           (let ((re (regexp-quote preselect)))
+             (cl-position-if
+              (lambda (x)
+                (string-match re x))
+              candidates)))))
 
 ;;* Implementation
 ;;** Regex
@@ -1343,17 +1355,21 @@ Insert .* between each char."
                                   ivy--full-length)
                              ivy--length)))
                ivy--prompt-extra
-               tail)
-              (if ivy--directory
-                  (abbreviate-file-name ivy--directory)
-                ""))))
+               tail)))
+            (d-str (if ivy--directory
+                       (abbreviate-file-name ivy--directory)
+                     "")))
         (save-excursion
           (goto-char (point-min))
           (delete-region (point-min) (minibuffer-prompt-end))
-          (when (> (length n-str) (- (window-width) 35))
-            (setq n-str (concat (substring n-str 0
-                                           (max (- (window-width) 35)
-                                                10)) "... ")))
+          (if (> (+ (mod (+ (length n-str) (length d-str)) (window-width))
+                    (length ivy-text))
+                 (window-width))
+              (setq n-str (concat n-str "\n" d-str))
+            (setq n-str (concat n-str d-str)))
+          (let ((regex (format "\\([^\n]\\{%d\\}\\)[^\n]" (window-width))))
+            (while (string-match regex n-str)
+              (setq n-str (replace-match (concat (match-string 1 n-str) "\n") nil t n-str 1))))
           (set-text-properties 0 (length n-str)
                                `(face minibuffer-prompt ,@std-props)
                                n-str)
@@ -1544,33 +1560,38 @@ CANDIDATES are assumed to be static."
                                     (if (cdr re)
                                         #'cl-remove-if-not
                                       #'cl-remove-if)
-                                    (let ((re (car re)))
-                                      (lambda (x) (string-match re x)))
+                                    (let ((re-str (car re)))
+                                      (lambda (x) (string-match re-str x)))
                                     res))))
                          res))))
              (tail (nthcdr ivy--index ivy--old-cands))
              idx)
-        (when (and tail ivy--old-cands (not (equal "^" ivy--old-re)))
-          (unless (and (not (equal re-str ivy--old-re))
-                       (or (setq ivy--index
-                                 (or
-                                  (cl-position (if (and (> (length re-str) 0)
-                                                        (eq ?^ (aref re-str 0)))
-                                                   (substring re-str 1)
-                                                 re-str) cands
-                                                 :test #'equal)
-                                  (and ivy--directory
-                                       (cl-position
-                                        (concat re-str "/") cands
-                                        :test #'equal))))))
-            (while (and tail (null idx))
-              ;; Compare with eq to handle equal duplicates in cands
-              (setq idx (cl-position (pop tail) cands)))
-            (setq ivy--index (or idx 0))))
+        (if (eq (ivy-state-unwind ivy-last) 'swiper--cleanup)
+            (when (and tail ivy--old-cands (not (equal "^" ivy--old-re)))
+              (unless (and (not (equal re-str ivy--old-re))
+                           (or (setq ivy--index
+                                     (or
+                                      (cl-position (if (and (> (length re-str) 0)
+                                                            (eq ?^ (aref re-str 0)))
+                                                       (substring re-str 1)
+                                                     re-str) cands
+                                                     :test #'equal)
+                                      (and ivy--directory
+                                           (cl-position
+                                            (concat re-str "/") cands
+                                            :test #'equal))))))
+                (while (and tail (null idx))
+                  ;; Compare with eq to handle equal duplicates in cands
+                  (setq idx (cl-position (pop tail) cands)))
+                (setq ivy--index (or idx 0))))
+          (setq ivy--index 0))
         (when (and (string= name "") (not (equal ivy--old-re "")))
           (setq ivy--index
-                (or (cl-position (ivy-state-preselect ivy-last)
-                                 cands :test #'equal)
+                (or (ivy--preselect-index
+                     cands
+                     nil
+                     (ivy-state-preselect ivy-last)
+                     nil)
                     ivy--index)))
         (setq ivy--old-re (if cands re-str ""))
         (when (and (require 'flx nil 'noerror)