branch: master
commit 56aa6056a93e91bab754b802f5fa93bc94ec78ac
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
ivy.el (ivy-add-prompt-count): Refactor from ivy--reset-state
* counsel.el (counsel-prompt-function-default): Update.
(counsel-prompt-function-dir): Update.
---
counsel.el | 22 ++++++++++++----------
ivy.el | 48 +++++++++++++++++++++++++-----------------------
2 files changed, 37 insertions(+), 33 deletions(-)
diff --git a/counsel.el b/counsel.el
index 211f8b9..5c1673c 100644
--- a/counsel.el
+++ b/counsel.el
@@ -210,7 +210,8 @@ Update the minibuffer with the amount of lines collected
every
(defun counsel-prompt-function-default ()
"Return prompt appended with a semicolon."
- (format "%s: " (ivy-state-prompt ivy-last)))
+ (ivy-add-prompt-count
+ (format "%s: " (ivy-state-prompt ivy-last))))
(defun counsel-delete-process ()
(let ((process (get-process " *counsel*")))
@@ -889,15 +890,16 @@ Describe the selected candidate."
(defun counsel-prompt-function-dir ()
"Return prompt appended with the parent directory."
- (let ((directory counsel--git-grep-dir))
- (format "%s [%s]: "
- (ivy-state-prompt ivy-last)
- (let ((dir-list (eshell-split-path directory)))
- (if (> (length dir-list) 3)
- (apply #'concat
- (append '("...")
- (cl-subseq dir-list (- (length dir-list) 3))))
- directory)))))
+ (ivy-add-prompt-count
+ (let ((directory counsel--git-grep-dir))
+ (format "%s [%s]: "
+ (ivy-state-prompt ivy-last)
+ (let ((dir-list (eshell-split-path directory)))
+ (if (> (length dir-list) 3)
+ (apply #'concat
+ (append '("...")
+ (cl-subseq dir-list (- (length dir-list)
3))))
+ directory))))))
(defun counsel-git-grep-function (string &optional _pred &rest _unused)
"Grep in the current git repository for STRING."
diff --git a/ivy.el b/ivy.el
index 49b4db5..df1e0cf 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1588,31 +1588,33 @@ This is useful for recursive `ivy-read'."
(region-beginning)
(region-end))
(ivy-thing-at-point)))
- (setq ivy--prompt
- (cond ((string-match "%.*d" prompt)
- prompt)
- ((null ivy-count-format)
- (error
- "`ivy-count-format' can't be nil. Set it to an empty string
instead"))
- ((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
- prompt)
- (t
- prompt)))
+ (setq ivy--prompt (ivy-add-prompt-count prompt))
(setf (ivy-state-initial-input ivy-last) initial-input)))
+(defun ivy-add-prompt-count (prompt)
+ (cond ((string-match "%.*d" prompt)
+ prompt)
+ ((null ivy-count-format)
+ (error
+ "`ivy-count-format' can't be nil. Set it to an empty string
instead"))
+ ((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
+ prompt)
+ (t
+ prompt)))
+
;;;###autoload
(defun ivy-completing-read (prompt collection
&optional predicate require-match initial-input