[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7feb14f 289/399: ivy.el (ivy-format-functions-alist): New
From: |
Oleh Krehel |
Subject: |
[elpa] master 7feb14f 289/399: ivy.el (ivy-format-functions-alist): New defcustom, obsoletes ivy-format-function |
Date: |
Sat, 20 Jul 2019 14:57:42 -0400 (EDT) |
branch: master
commit 7feb14f476e108dc10fe5380ee7c33de3b5fe3f1
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy.el (ivy-format-functions-alist): New defcustom, obsoletes
ivy-format-function
Fixes #2083
Fixes #2084
---
counsel.el | 156 ++++++++++++++++++++++++++++++-----------------------------
doc/ivy.org | 2 +-
doc/ivy.texi | 2 +-
ivy-test.el | 3 +-
ivy.el | 25 +++++++---
swiper.el | 9 ++--
6 files changed, 107 insertions(+), 90 deletions(-)
diff --git a/counsel.el b/counsel.el
index 86e5264..c13a4b1 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1144,17 +1144,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 ()
@@ -1163,10 +1166,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
@@ -1175,6 +1177,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")
@@ -1673,14 +1677,14 @@ currently checked out."
(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))
+ (counsel-yank-pop-truncate-radius 5))
(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--yank-pop-format-function))
(add-to-list 'ivy-height-alist '(counsel-git-log . 4))
;;* File
@@ -3729,11 +3733,6 @@ 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)
@@ -3883,8 +3882,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
@@ -3892,7 +3890,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
@@ -3953,11 +3951,6 @@ matching the register's value description against a
regexp in
:caller 'counsel-register))
;;** `counsel-evil-registers'
-(make-obsolete-variable
- 'counsel-evil-registers-height
- 'ivy-height-alist
- "<2018-04-14 Fri>") ;; TODO: Add version tag
-
(defcustom counsel-evil-registers-height 5
"The `ivy-height' of `counsel-evil-registers'."
:type 'integer)
@@ -3966,15 +3959,14 @@ matching the register's value description against a
regexp in
"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)
@@ -4660,12 +4652,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-emacs-format-function (colors)
+ "Format function for `counsel-colors-emacs'."
+ (require 'shr-color)
+ (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--formatter (formatter)
- "Turn FORMATTER into format function for `counsel-colors-*'.
-Return closure suitable for `ivy-format-function'."
+(defun counsel--colors-web-format-function (colors)
+ "Format function for `counsel-colors-web'."
(require 'shr-color)
- (lambda (colors)
+ (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))
@@ -4691,26 +4712,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
@@ -4748,16 +4758,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
@@ -4765,6 +4768,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")
@@ -5564,16 +5568,16 @@ specified by the `blddir' property."
(defun counsel-compile-env ()
"Update `counsel-compile-env' interactively."
(interactive)
- (let ((ivy-format-function #'counsel-compile-env--format-hint))
- (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)))
+ (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
diff --git a/doc/ivy.org b/doc/ivy.org
index 05a6c44..151592d 100644
--- a/doc/ivy.org
+++ b/doc/ivy.org
@@ -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
diff --git a/doc/ivy.texi b/doc/ivy.texi
index ae66455..8cc2711 100644
--- a/doc/ivy.texi
+++ b/doc/ivy.texi
@@ -181,7 +181,7 @@ 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
+@code{ivy-format-functions-alist}). 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
diff --git a/ivy-test.el b/ivy-test.el
index dad5616..dbde2ec 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -312,7 +312,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"
diff --git a/ivy.el b/ivy.el
index 8070eb3..02c1a4f 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1545,13 +1545,24 @@ minibuffer."
(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)))
@@ -3652,7 +3663,7 @@ CANDS is a list of strings."
(defun ivy--wnd-cands-to-str (wnd-cands)
(let ((str (concat "\n"
- (funcall ivy-format-function
+ (funcall (ivy-alist-setting ivy-format-functions-alist)
(condition-case nil
(mapcar
#'ivy--format-minibuffer-line
diff --git a/swiper.el b/swiper.el
index 2349488..aaa532b 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1141,7 +1141,7 @@ otherwise continue prompting for buffers."
(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
@@ -1181,8 +1181,7 @@ 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
@@ -1192,6 +1191,8 @@ See `ivy-format-function' for further information."
: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)
@@ -1464,7 +1465,6 @@ When not running `swiper-isearch' already, start it."
(let ((ivy-fixed-height-minibuffer t)
(cursor-in-non-selected-windows nil)
(swiper-min-highlight 1)
- (ivy-format-function #'swiper-isearch-format-function)
res)
(unwind-protect
(and
@@ -1487,6 +1487,7 @@ When not running `swiper-isearch' already, start it."
(unless (or res (string= ivy-text ""))
(cl-pushnew ivy-text swiper-history)))))
+(add-to-list 'ivy-format-functions-alist '(swiper-isearch .
swiper-isearch-format-function))
(ivy-set-occur 'swiper-isearch 'swiper-occur)
(defun swiper-isearch-toggle ()
- [elpa] master 8905b8b 278/399: counsel.el: Pacify byte-compiler, (continued)
- [elpa] master 8905b8b 278/399: counsel.el: Pacify byte-compiler, Oleh Krehel, 2019/07/20
- [elpa] master af5b594 283/399: ivy.el (ivy--occur-insert-lines): Fix typo bug, Oleh Krehel, 2019/07/20
- [elpa] master 04f56ca 282/399: ivy.el (ivy--recompute-index): Use configured flx candidate limit, Oleh Krehel, 2019/07/20
- [elpa] master e69ddc3 295/399: ivy.el (ivy-sort-function-buffer): Unify prefix and star-prefix matches, Oleh Krehel, 2019/07/20
- [elpa] master f40b08a 293/399: ivy-display-function: obsolete this varible in favor ivy-display-functions-alist, Oleh Krehel, 2019/07/20
- [elpa] master 332f990 285/399: ivy.el: Fix compiler warning, Oleh Krehel, 2019/07/20
- [elpa] master 779db1e 292/399: ivy.el (ivy--occur-insert-lines): Add copy-sequence, Oleh Krehel, 2019/07/20
- [elpa] master a73e24d 288/399: Do not insert initial input if nil, Oleh Krehel, 2019/07/20
- [elpa] master 0b26219 301/399: counsel.el (counsel--file-name-filter): Move ignore-re binding., Oleh Krehel, 2019/07/20
- [elpa] master ef6d3db 297/399: ivy-overlay.el (ivy-display-function-overlay): Bring back org-indent-mode logic, Oleh Krehel, 2019/07/20
- [elpa] master 7feb14f 289/399: ivy.el (ivy-format-functions-alist): New defcustom, obsoletes ivy-format-function,
Oleh Krehel <=
- [elpa] master b528f0f 299/399: ivy-overlay.el (ivy-display-function-overlay): Fix org-indent-mode once more, Oleh Krehel, 2019/07/20
- [elpa] master ef1e8d5 294/399: ivy.el (ivy-read): Don't use ivy-display-function, Oleh Krehel, 2019/07/20
- [elpa] master 57a57d1 302/399: swiper.el (swiper--multi-candidates): Simplify, Oleh Krehel, 2019/07/20
- [elpa] master 44b2d7d 300/399: ivy.el (ivy-insert-current-full): Add and bind to "C-M-y", Oleh Krehel, 2019/07/20
- [elpa] master d39f82b 307/399: counsel-yank-pop-height is obselete and doesn't do anything, Oleh Krehel, 2019/07/20
- [elpa] master c11797a 290/399: swiper.el (swiper--line-at-point): Fix swiper-isearch in compilation buffers, Oleh Krehel, 2019/07/20
- [elpa] master 94f107b 304/399: counsel.el (counsel-mark-ring): Add highlight by candidate, Oleh Krehel, 2019/07/20
- [elpa] master 034f3af 306/399: swiper.el (swiper-isearch): Allow char-fold-to-regexp, Oleh Krehel, 2019/07/20
- [elpa] master 5cc1e5c 298/399: swiper.el (swiper-isearch-thing-at-point): Improve, Oleh Krehel, 2019/07/20
- [elpa] master 3b6c898 303/399: counsel.el (counsel-mark-ring): Add preview by candidate, Oleh Krehel, 2019/07/20