[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3b67044 145/167: Convert ivy formatting functions to dotte
From: |
Oleh Krehel |
Subject: |
[elpa] master 3b67044 145/167: Convert ivy formatting functions to dotted pairs. |
Date: |
Tue, 08 Dec 2015 10:50:36 +0000 |
branch: master
commit 3b67044d00573b8207d0df9fa03777237e196bdf
Author: Stephen Whipple <address@hidden>
Commit: Stephen Whipple <address@hidden>
Convert ivy formatting functions to dotted pairs.
`ivy-format-function' now expects to operate on dotted pairs
representing (stub . extra), where `stub' is the original
candidate and `extra' is any extra information that has been
added by counsel or other libraries.
The format function can differentiate between the original stub
and extra information and choose how to display the result to
the user.
---
counsel.el | 22 ++++++++++++--------
ivy-test.el | 2 +-
ivy.el | 63 ++++++++++++++++++++++++++++++++++------------------------
3 files changed, 51 insertions(+), 36 deletions(-)
diff --git a/counsel.el b/counsel.el
index 5354d39..5491495 100644
--- a/counsel.el
+++ b/counsel.el
@@ -822,15 +822,19 @@ When NO-ASYNC is non-nil, do it synchronously."
(when (= 0 (cl-incf counsel-gg-state))
(ivy--exhibit)))))))))
-(defun counsel--M-x-transformer (cmd)
- "Add a binding to CMD if it's bound in the current window.
-CMD is a command name."
- (let ((binding (substitute-command-keys (format "\\[%s]" cmd))))
+(defun counsel--M-x-transformer (cand-pair)
+ "Add a binding to CAND-PAIR cdr if the car is bound in the current window.
+CAND-PAIR is (command-name . extra-info)."
+ (let* ((command-name (car cand-pair))
+ (extra-info (cdr cand-pair))
+ (binding (substitute-command-keys (format "\\[%s]" command-name))))
(setq binding (replace-regexp-in-string "C-x 6" "<f2>" binding))
(if (string-match "^M-x" binding)
- cmd
- (format "%s (%s)" cmd
- (propertize binding 'face 'font-lock-keyword-face)))))
+ cand-pair
+ (cons command-name
+ (if extra-info
+ (format "%s (%s)" extra-info (propertize binding 'face
'font-lock-keyword-face))
+ (format "(%s)" (propertize binding 'face
'font-lock-keyword-face)))))))
(defvar smex-initialized-p)
(defvar smex-ido-cache)
@@ -863,11 +867,11 @@ Optional INITIAL-INPUT is the initial input in the
minibuffer."
ivy-initial-inputs-alist))))
(let* ((store ivy-format-function)
(ivy-format-function
- (lambda (cands)
+ (lambda (cand-pairs)
(funcall
store
(with-ivy-window
- (mapcar #'counsel--M-x-transformer cands)))))
+ (mapcar #'counsel--M-x-transformer cand-pairs)))))
(cands obarray)
(pred 'commandp)
(sort t))
diff --git a/ivy-test.el b/ivy-test.el
index ddfef34..ec5857d 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -115,7 +115,7 @@
(ert-deftest ivy--format ()
(should (string= (let ((ivy--index 10)
- (ivy-format-function (lambda (x) (mapconcat
#'identity x "\n")))
+ (ivy-format-function (lambda (x) (mapconcat (lambda
(y) (car y)) x "\n")))
(cands '("NAME"
"SYNOPSIS"
"DESCRIPTION"
diff --git a/ivy.el b/ivy.el
index c365d47..5578acd 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1895,7 +1895,7 @@ Prefix matches to NAME are put ahead of the list."
cands)))
(defcustom ivy-format-function 'ivy-format-function-default
- "Function to transform the list of candidates into a string.
+ "Function to transform the list of candidate pairs into a string.
This string will be inserted into the minibuffer."
:type '(choice
(const :tag "Default" ivy-format-function-default)
@@ -1909,37 +1909,48 @@ This string will be inserted into the minibuffer."
(- (length str) 3))) "...")
str))
-(defun ivy-format-function-default (cands)
- "Transform CANDS into a string for minibuffer."
+(defun ivy-format-function-default (cand-pairs)
+ "Transform CAND-PAIRS into a string for minibuffer."
(let ((i -1))
(mapconcat
- (lambda (s)
- (when (eq (cl-incf i) ivy--index)
- (ivy--add-face s 'ivy-current-match))
- s)
- cands "\n")))
-
-(defun ivy-format-function-arrow (cands)
- "Transform CANDS into a string for minibuffer."
+ (lambda (pair)
+ (let ((stub (car pair))
+ (extra (cdr pair))
+ (curr (eq (cl-incf i) ivy--index)))
+ (when curr
+ (ivy--add-face stub 'ivy-current-match))
+ (if extra (format "%s %s" stub extra) stub)))
+ cand-pairs "\n")))
+
+(defun ivy-format-function-arrow (cand-pairs)
+ "Transform CAND-PAIRS into a string for minibuffer."
(let ((i -1))
(mapconcat
- (lambda (s)
- (let ((curr (eq (cl-incf i) ivy--index)))
+ (lambda (pair)
+ (let ((stub (car pair))
+ (extra (cdr pair))
+ (curr (eq (cl-incf i) ivy--index)))
(when curr
- (ivy--add-face s 'ivy-current-match))
- (concat (if curr "> " " ") s)))
- cands "\n")))
+ (ivy--add-face stub 'ivy-current-match))
+ (concat (if curr "> " " ")
+ (if extra (format "%s %s" stub extra) stub))))
+ cand-pairs "\n")))
-(defun ivy-format-function-line (cands)
- "Transform CANDS into a string for minibuffer."
+(defun ivy-format-function-line (cand-pairs)
+ "Transform CAND-PAIRS into a string for minibuffer."
(let ((i -1))
(mapconcat
- (lambda (s)
- (let ((line (concat s "\n")))
- (when (eq (cl-incf i) ivy--index)
+ (lambda (pair)
+ (let* ((stub (car pair))
+ (extra (cdr pair))
+ (curr (eq (cl-incf i) ivy--index))
+ (line (if extra
+ (format "%s %s\n" stub extra)
+ (concat stub "\n"))))
+ (when curr
(ivy--add-face line 'ivy-current-match))
line))
- cands "")))
+ cand-pairs "")))
(defface ivy-minibuffer-match-face-1
'((((class color) (background light))
@@ -2041,11 +2052,11 @@ CANDS is a list of strings."
x)))
cands))))
(setq ivy--current (copy-sequence (nth index cands)))
- (setq cands (mapcar
- #'ivy--format-minibuffer-line
- cands))
(let* ((ivy--index index)
- (res (concat "\n" (funcall ivy-format-function cands))))
+ (cand-pairs (mapcar
+ (lambda (cand)
+ (cons (ivy--format-minibuffer-line cand) nil))
cands))
+ (res (concat "\n" (funcall ivy-format-function cand-pairs))))
(put-text-property 0 (length res) 'read-only nil res)
res))))
- [elpa] master 80d4dde 141/167: Fix broken candidate index in ivy-resume, (continued)
- [elpa] master 80d4dde 141/167: Fix broken candidate index in ivy-resume, Oleh Krehel, 2015/12/08
- [elpa] master d9ecd2e 133/167: Fix the preselect for (swiper "one"), Oleh Krehel, 2015/12/08
- [elpa] master 073b071 115/167: Allow to sort files by last modification time., Oleh Krehel, 2015/12/08
- [elpa] master 0c62f7e 132/167: ivy.el (ivy-alt-done): Split into smaller defuns, Oleh Krehel, 2015/12/08
- [elpa] master 59df2e9 131/167: ivy.el (ivy-alt-done): Refactor, Oleh Krehel, 2015/12/08
- [elpa] master 2bec99d 146/167: Ease production of functions like ivy-format-function-default, Oleh Krehel, 2015/12/08
- [elpa] master c546ae4 150/167: Enable recursive swiper calls, Oleh Krehel, 2015/12/08
- [elpa] master 1bf4ae2 140/167: Warn the user about the behavior of ivy--regex-ignore-order, Oleh Krehel, 2015/12/08
- [elpa] master 99d214d 142/167: Ivy-resume should restore the buffer for swiper, Oleh Krehel, 2015/12/08
- [elpa] master 8abed59 143/167: Add counsel-grep, Oleh Krehel, 2015/12/08
- [elpa] master 3b67044 145/167: Convert ivy formatting functions to dotted pairs.,
Oleh Krehel <=
- [elpa] master ac09f6b 152/167: Fix the issue caused by recursive swiper calls, Oleh Krehel, 2015/12/08
- [elpa] master a34e532 155/167: swiper.el: Use show-all if outline-show-all isn't there, Oleh Krehel, 2015/12/08
- [elpa] master b57c57d 153/167: Fix the preselect for (swiper "one") again, Oleh Krehel, 2015/12/08
- [elpa] master a585fcd 156/167: Fix due to visual-line-mode weirdness, Oleh Krehel, 2015/12/08
- [elpa] master 1cf32c8 138/167: ivy.org manual edits, Oleh Krehel, 2015/12/08
- [elpa] master 7377445 147/167: Edit documentation strings in ivy.el, Oleh Krehel, 2015/12/08
- [elpa] master 1cceac1 154/167: Fix ivy-resume issue caused by the recursive calls change, Oleh Krehel, 2015/12/08
- [elpa] master ed9169d 158/167: swiper.el (swiper--update-input-ivy): Add a work-around for "M-j", Oleh Krehel, 2015/12/08
- [elpa] master 0332b3e 151/167: Remove 'field text property for twittering-mode, Oleh Krehel, 2015/12/08
- [elpa] master 5cfe6e6 148/167: Fixes on the previous docstring edits, Oleh Krehel, 2015/12/08