[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 2bec99d 146/167: Ease production of functions like ivy-for
From: |
Oleh Krehel |
Subject: |
[elpa] master 2bec99d 146/167: Ease production of functions like ivy-format-function-default |
Date: |
Tue, 08 Dec 2015 10:50:37 +0000 |
branch: master
commit 2bec99d49ffdf89b5f2e3521cde5306d4ae72c64
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Ease production of functions like ivy-format-function-default
* ivy.el (ivy--format-function-generic): New defun.
(ivy-format-function-default):
(ivy-format-function-arrow):
(ivy-format-function-line): Use `ivy--format-function-generic'.
* counsel.el (counsel--M-x-transformer): Add an extra space to simplify
the logic.
Re #307
---
counsel.el | 4 +-
ivy.el | 64 ++++++++++++++++++++++++++++++-----------------------------
2 files changed, 35 insertions(+), 33 deletions(-)
diff --git a/counsel.el b/counsel.el
index 5491495..0ced4b9 100644
--- a/counsel.el
+++ b/counsel.el
@@ -833,8 +833,8 @@ CAND-PAIR is (command-name . extra-info)."
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)))))))
+ (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)
diff --git a/ivy.el b/ivy.el
index 5578acd..f3c760d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1909,48 +1909,50 @@ This string will be inserted into the minibuffer."
(- (length str) 3))) "...")
str))
-(defun ivy-format-function-default (cand-pairs)
- "Transform CAND-PAIRS into a string for minibuffer."
+(defun ivy--format-function-generic (selected-fn other-fn cand-pairs separator)
+ "Transform CAND-PAIRS into a string for minibuffer.
+SELECTED-FN and OTHER-FN each take two string arguments.
+SEPARATOR is used to join the candidates."
(let ((i -1))
(mapconcat
(lambda (pair)
- (let ((stub (car pair))
+ (let ((str (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")))
+ (if curr
+ (funcall selected-fn str extra)
+ (funcall other-fn str extra))))
+ cand-pairs
+ separator)))
+
+(defun ivy-format-function-default (cand-pairs)
+ "Transform CAND-PAIRS into a string for minibuffer."
+ (ivy--format-function-generic
+ (lambda (str extra)
+ (concat (ivy--add-face str 'ivy-current-match) extra))
+ #'concat
+ cand-pairs
+ "\n"))
(defun ivy-format-function-arrow (cand-pairs)
"Transform CAND-PAIRS into a string for minibuffer."
- (let ((i -1))
- (mapconcat
- (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))
- (concat (if curr "> " " ")
- (if extra (format "%s %s" stub extra) stub))))
- cand-pairs "\n")))
+ (ivy--format-function-generic
+ (lambda (str extra)
+ (concat "> " (ivy--add-face str 'ivy-current-match) extra))
+ (lambda (str extra)
+ (concat " " str extra))
+ cand-pairs
+ "\n"))
(defun ivy-format-function-line (cand-pairs)
"Transform CAND-PAIRS into a string for minibuffer."
- (let ((i -1))
- (mapconcat
- (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))
- cand-pairs "")))
+ (ivy--format-function-generic
+ (lambda (str extra)
+ (ivy--add-face (concat str extra "\n") 'ivy-current-match))
+ (lambda (str extra)
+ (concat str extra "\n"))
+ cand-pairs
+ ""))
(defface ivy-minibuffer-match-face-1
'((((class color) (background light))
- [elpa] master 85bd44b 125/167: swiper.el: Modify the behavior with org-mode and visual-line-mode, (continued)
- [elpa] master 85bd44b 125/167: swiper.el: Modify the behavior with org-mode and visual-line-mode, Oleh Krehel, 2015/12/08
- [elpa] master 8fdf210 127/167: Switch to using ivy-exit-with-action, Oleh Krehel, 2015/12/08
- [elpa] master ce6ab7a 135/167: Perform string-match in the original buffer, Oleh Krehel, 2015/12/08
- [elpa] master bc00eaf 137/167: Fix `counsel-ag` on Windows, Oleh Krehel, 2015/12/08
- [elpa] master ed2367b 134/167: swiper.el (swiper--candidates): Require outline, Oleh Krehel, 2015/12/08
- [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 <=
- [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, 2015/12/08
- [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