branch: master
commit a5701a97217f269c7f6c05e8f3cfa7fe976bdad2
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
ivy.el (ivy-configure): Add :format-fn
---
counsel.el | 30 +++++++++++++++++-------------
ivy.el | 3 +++
swiper.el | 14 ++++++--------
3 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/counsel.el b/counsel.el
index f413d97..0a4b7b9 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1195,8 +1195,7 @@ back to the face of the character after point, and
finally the
(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."
+ "Format NAMES according to `counsel--faces-format'."
(let ((formatter
(lambda (name)
(format counsel--faces-format name
@@ -1225,9 +1224,8 @@ selected face."
:caller 'counsel-faces)))
(ivy-configure 'counsel-faces
- :sort-fn #'ivy-string<)
-
-(add-to-list 'ivy-format-functions-alist '(counsel-faces .
counsel--faces-format-function))
+ :sort-fn #'ivy-string<
+ :format-fn #'counsel--faces-format-function)
(ivy-set-actions
'counsel-faces
@@ -1756,9 +1754,9 @@ currently checked out."
:caller 'counsel-git-log))
(ivy-configure 'counsel-git-log
- :unwind-fn #'counsel-delete-process)
+ :unwind-fn #'counsel-delete-process
+ :format-fn #'counsel--git-log-format-function)
-(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]*$"))
@@ -4179,7 +4177,9 @@ 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))
+
+(ivy-configure 'counsel-yank-pop
+ :format-fn #'counsel--yank-pop-format-function)
(add-to-list 'ivy-height-alist '(counsel-yank-pop . 5))
(ivy-set-actions
@@ -4254,7 +4254,8 @@ matching the register's value description against a
regexp in
: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))
+(ivy-configure 'counsel-evil-registers
+ :format-fn #'counsel--yank-pop-format-function)
(add-to-list 'ivy-height-alist '(counsel-evil-registers . 5))
(defun counsel-evil-registers-action (s)
@@ -4997,7 +4998,8 @@ selected color."
: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-configure 'counsel-colors-emacs
+ :format-fn #'counsel--colors-emacs-format-function)
(ivy-set-actions
'counsel-colors-emacs
@@ -5045,9 +5047,9 @@ selected color."
:caller 'counsel-colors-web)))
(ivy-configure 'counsel-colors-web
- :sort-fn #'ivy-string<)
+ :sort-fn #'ivy-string<
+ :format-fn #'counsel--colors-web-format-function)
-(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")
@@ -5893,7 +5895,9 @@ specified by the `blddir' property."
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))
+
+(ivy-configure 'counsel-compile-env
+ :format-fn #'counsel-compile-env--format-hint)
;;** `counsel-minor'
(defvar counsel-minor-history nil
diff --git a/ivy.el b/ivy.el
index 1527e85..cb5569d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1913,6 +1913,7 @@ May supersede `ivy-initial-inputs-alist'."
unwind-fn
index-fn
sort-fn
+ format-fn
display-transformer-fn
more-chars
grep-p)
@@ -1930,6 +1931,8 @@ May supersede `ivy-initial-inputs-alist'."
(ivy--alist-set 'ivy-index-functions-alist caller index-fn))
(when sort-fn
(ivy--alist-set 'ivy-sort-functions-alist caller sort-fn))
+ (when format-fn
+ (ivy--alist-set 'ivy-format-functions-alist caller format-fn))
(when display-transformer-fn
(ivy-set-display-transformer caller display-transformer-fn))
(when more-chars
diff --git a/swiper.el b/swiper.el
index e41b96d..2777123 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1137,7 +1137,8 @@ Run `swiper' for those buffers."
(ivy-configure 'swiper-multi
:unwind-fn #'swiper--cleanup
- :index-fn #'ivy-recompute-index-swiper)
+ :index-fn #'ivy-recompute-index-swiper
+ :format-fn #'swiper--all-format-function)
(defun swiper-multi-action-1 (x)
"Add X to list of selected buffers `swiper-multi-buffers'.
@@ -1287,10 +1288,8 @@ See `ivy-format-functions-alist' for further
information."
(ivy-configure 'swiper-all
:update-fn 'auto
- :unwind-fn #'swiper--cleanup)
-
-(add-to-list 'ivy-format-functions-alist '(swiper-multi .
swiper--all-format-function))
-(add-to-list 'ivy-format-functions-alist '(swiper-all .
swiper--all-format-function))
+ :unwind-fn #'swiper--cleanup
+ :format-fn #'swiper--all-format-function)
(defun swiper-all-action (x)
"Move to candidate X from `swiper-all'."
@@ -1625,7 +1624,8 @@ When not running `swiper-isearch' already, start it."
(ivy-configure 'swiper-isearch
:occur #'swiper-occur
:update-fn 'auto
- :unwind-fn #'swiper--cleanup)
+ :unwind-fn #'swiper--cleanup
+ :format-fn #'swiper-isearch-format-function)
;;;###autoload
(defun swiper-isearch-backward (&optional initial-input)
@@ -1634,8 +1634,6 @@ When not running `swiper-isearch' already, start it."
(let ((swiper--isearch-backward t))
(swiper-isearch initial-input)))
-(add-to-list 'ivy-format-functions-alist '(swiper-isearch .
swiper-isearch-format-function))
-
(defun swiper-isearch-toggle ()
"Two-way toggle between `swiper-isearch' and isearch.
Intended to be bound in `isearch-mode-map' and `swiper-map'."