(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)
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))
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)
(- (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))
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))))