branch: master
commit a5e49ff5f72bc1687a02c2078ee737433af77487
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Make counsel-M-x respect ivy-format-function
* counsel.el (counsel--format-function-M-x): Remove defun.
(counsel--M-x-transformer): New defun.
(counsel-M-x): Temporarily bind `ivy-format-function' to apply
`counsel--M-x-transformer' beforehand.
* ivy.el (ivy-format-function-arrow): Update style.
Fixes #150
---
counsel.el | 36 +++++++++++++++++++-----------------
ivy.el | 4 ++--
2 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/counsel.el b/counsel.el
index af2acb7..3c9fa1f 100644
--- a/counsel.el
+++ b/counsel.el
@@ -487,19 +487,15 @@ When NO-ASYNC is non-nil, do it synchronously."
(ivy--insert-minibuffer
(ivy--format ivy--all-candidates)))))))))
-(defun counsel--format-function-M-x (cands)
- "Join CANDS, a list of command names, with newlines.
-If a command is bound, add it's binding after it."
- (with-selected-window (ivy-state-window ivy-last)
- (mapconcat (lambda (x)
- (let ((binding (substitute-command-keys (format "\\[%s]" x))))
- (setq binding (replace-regexp-in-string "C-x 6" "<f2>"
binding))
- (if (string-match "^M-x" binding)
- x
- (format "%s (%s)" x
- (propertize binding 'face
'font-lock-keyword-face)))))
- cands
- "\n")))
+(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))))
+ (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)))))
;;;###autoload
(defun counsel-M-x (&optional initial-input)
@@ -509,10 +505,16 @@ Optional INITIAL-INPUT is the initial input in the
minibuffer."
(unless initial-input
(setq initial-input (cdr (assoc this-command
ivy-initial-inputs-alist))))
- (let ((ivy-format-function #'counsel--format-function-M-x)
- (cands obarray)
- (pred 'commandp)
- (sort t))
+ (let* ((store ivy-format-function)
+ (ivy-format-function
+ (lambda (cands)
+ (funcall
+ store
+ (with-selected-window (ivy-state-window ivy-last)
+ (mapcar #'counsel--M-x-transformer cands)))))
+ (cands obarray)
+ (pred 'commandp)
+ (sort t))
(when (or (featurep 'smex)
(package-installed-p 'smex))
(require 'smex)
diff --git a/ivy.el b/ivy.el
index bf399c1..b105690 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1275,8 +1275,8 @@ This string will be inserted into the minibuffer.")
(mapconcat
(lambda (s)
(concat (if (eq (cl-incf i) ivy--index)
- "==> "
- " ")
+ "> "
+ " ")
s))
cands "\n")))