Skip to content

Commit 1c6b3da

Browse files
committed
Add arrow prefix + full line candidate format
* ivy.el (ivy-format-function-arrow-line): New candidate formatting function. (ivy-format-functions-alist): List it as one of the options. (ivy-format-function-default, ivy-format-function-arrow) (ivy-format-function-line): Extend docstrings. Closes #2921.
1 parent 5f49149 commit 1c6b3da

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

ivy.el

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,8 @@ This string is inserted into the minibuffer."
17061706
(const :tag "Default" ivy-format-function-default)
17071707
(const :tag "Arrow prefix" ivy-format-function-arrow)
17081708
(const :tag "Full line" ivy-format-function-line)
1709+
(const :tag "Arrow prefix + full line"
1710+
ivy-format-function-arrow-line)
17091711
(function :tag "Custom function"))))
17101712

17111713
(defun ivy-sort-file-function-default (x y)
@@ -3967,7 +3969,8 @@ and SEPARATOR is used to join them."
39673969
separator)))
39683970

39693971
(defun ivy-format-function-default (cands)
3970-
"Transform CANDS into a string for minibuffer."
3972+
"Transform CANDS into a multiline string for the minibuffer.
3973+
Add the face `ivy-current-match' to the selected candidate."
39713974
(ivy--format-function-generic
39723975
(lambda (str)
39733976
(ivy--add-face str 'ivy-current-match))
@@ -3976,7 +3979,9 @@ and SEPARATOR is used to join them."
39763979
"\n"))
39773980

39783981
(defun ivy-format-function-arrow (cands)
3979-
"Transform CANDS into a string for minibuffer."
3982+
"Transform CANDS into a multiline string for the minibuffer.
3983+
Like `ivy-format-function-default', but also prefix the selected
3984+
candidate with an arrow \">\"."
39803985
(ivy--format-function-generic
39813986
(lambda (str)
39823987
(concat "> " (ivy--add-face str 'ivy-current-match)))
@@ -3986,9 +3991,13 @@ and SEPARATOR is used to join them."
39863991
"\n"))
39873992

39883993
(defun ivy-format-function-line (cands)
3989-
"Transform CANDS into a string for minibuffer.
3990-
Note that since Emacs 27, `ivy-current-match' needs to have :extend t attribute.
3991-
It has it by default, but the current theme also needs to set it."
3994+
"Transform CANDS into a multiline string for the minibuffer.
3995+
Like `ivy-format-function-default', but extend highlighting of
3996+
the selected candidate to the window edge.
3997+
3998+
Note that since Emacs 27, `ivy-current-match' needs to have a
3999+
non-nil :extend attribute. This is the case by default, but it
4000+
also needs to be preserved by the current theme."
39924001
(ivy--format-function-generic
39934002
(lambda (str)
39944003
(ivy--add-face (concat str "\n") 'ivy-current-match))
@@ -3997,6 +4006,18 @@ It has it by default, but the current theme also needs to set it."
39974006
cands
39984007
""))
39994008

4009+
(defun ivy-format-function-arrow-line (cands)
4010+
"Transform CANDS into a multiline string for the minibuffer.
4011+
This combines the \">\" prefix of `ivy-format-function-arrow'
4012+
with the extended highlighting of `ivy-format-function-line'."
4013+
(ivy--format-function-generic
4014+
(lambda (str)
4015+
(concat "> " (ivy--add-face (concat str "\n") 'ivy-current-match)))
4016+
(lambda (str)
4017+
(concat " " str "\n"))
4018+
cands
4019+
""))
4020+
40004021
(defun ivy--highlight-ignore-order (str)
40014022
"Highlight STR, using the ignore-order method."
40024023
(when (consp ivy--old-re)

0 commit comments

Comments
 (0)