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

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

[elpa] master 783f7c5 13/63: Update index formatting logic


From: Oleh Krehel
Subject: [elpa] master 783f7c5 13/63: Update index formatting logic
Date: Fri, 21 Aug 2015 12:08:32 +0000

branch: master
commit 783f7c58776d1309c84586799f31e0fe6ec64482
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Update index formatting logic
    
    * ivy.el (ivy--reset-state): Update.
    (ivy--insert-prompt): Simplify.
    
    If you want to see both the index and the length of the candidates,
    instead of just the length, it can be done like this:
    
        (setq ivy-count-format "%d/%d ")
    
    Each "%d" is replaced appropriately due to the total length of the
    candidates. For instance, this one can result in "%4d/%-4d M-x ".
    
    Re #167
---
 ivy.el    |   53 +++++++++++++++++++++++++++++++----------------------
 swiper.el |    3 +--
 2 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/ivy.el b/ivy.el
index 25720c9..27f76d1 100644
--- a/ivy.el
+++ b/ivy.el
@@ -927,6 +927,17 @@ This is useful for recursive `ivy-read'."
     (setq ivy--prompt
           (cond ((string-match "%.*d" prompt)
                  prompt)
+                ((string-match "%d.*%d" ivy-count-format)
+                 (let ((w (length (number-to-string
+                                   (length ivy--all-candidates))))
+                       (s (copy-sequence ivy-count-format)))
+                   (string-match "%d" s)
+                   (match-end 0)
+                   (string-match "%d" s (match-end 0))
+                   (setq s (replace-match (format "%%-%dd" w) nil nil s))
+                   (string-match "%d" s)
+                   (concat (replace-match (format "%%%dd" w) nil nil s)
+                           prompt)))
                 ((string-match "%.*d" ivy-count-format)
                  (concat ivy-count-format prompt))
                 (ivy--directory
@@ -1155,29 +1166,27 @@ Insert .* between each char."
       (let ((inhibit-read-only t)
             (std-props '(front-sticky t rear-nonsticky t field t read-only t))
             (n-str
+             (concat
+              (if (and (bound-and-true-p minibuffer-depth-indicate-mode)
+                       (> (minibuffer-depth) 1))
+                  (format "[%d] " (minibuffer-depth))
+                "")
               (concat
-               (if (and (bound-and-true-p minibuffer-depth-indicate-mode)
-                        (> (minibuffer-depth) 1))
-                   (format "[%d] " (minibuffer-depth))
-                 "")
-               (if (string-match "%[-0-9 ]*d.*%[-0-9 ]*d" ivy-count-format)
-                   (concat (format ivy-count-format (1+ ivy--index) 
ivy--length)
-                           " "
-                           ;; work around swiper
-                           (let ((pr (ivy-state-prompt ivy-last)))
-                             (if (string-match "%[-0-9 ]*d" pr)
-                                 (substring pr (1+ (match-end 0)))
-                               pr)))
-                 (concat (format
-                          head
-                          (or (and (ivy-state-dynamic-collection ivy-last)
-                                   ivy--full-length)
-                              ivy--length))
-                         ivy--prompt-extra
-                         tail))
-               (if ivy--directory
-                   (abbreviate-file-name ivy--directory)
-                 ""))))
+               (if (string-match "%d.*%d" ivy-count-format)
+                   (format head
+                           (1+ ivy--index)
+                           (or (and (ivy-state-dynamic-collection ivy-last)
+                                    ivy--full-length)
+                               ivy--length))
+                 (format head
+                         (or (and (ivy-state-dynamic-collection ivy-last)
+                                  ivy--full-length)
+                             ivy--length)))
+               ivy--prompt-extra
+               tail)
+              (if ivy--directory
+                  (abbreviate-file-name ivy--directory)
+                ""))))
         (save-excursion
           (goto-char (point-min))
           (delete-region (point-min) (minibuffer-prompt-end))
diff --git a/swiper.el b/swiper.el
index 1975ae2..24be153 100644
--- a/swiper.el
+++ b/swiper.el
@@ -244,8 +244,7 @@ Please remove it and update the \"swiper\" package."))
         res)
     (unwind-protect
          (setq res (ivy-read
-                    (replace-regexp-in-string
-                     "%s" "pattern: " swiper--format-spec)
+                    "Swiper: "
                     candidates
                     :initial-input initial-input
                     :keymap swiper-map



reply via email to

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