[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7dea0ff 255/348: Use ivy-format-function approach for coun
From: |
Oleh Krehel |
Subject: |
[elpa] master 7dea0ff 255/348: Use ivy-format-function approach for counsel-faces |
Date: |
Sat, 8 Apr 2017 11:04:10 -0400 (EDT) |
branch: master
commit 7dea0ff8b29db2fbc923d11e4d390d0871e77ad5
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Use ivy-format-function approach for counsel-faces
* counsel.el (counsel-faces-action-describe): Remove defun.
(counsel-faces-action-describe): Simplify.
(counsel-faces-action-customize): Simplify.
(counsel-faces-action-insert-name): Replace with 'insert.
(counsel-faces-action-kill-name): Replace with 'kill-new.
(counsel--faces-fmt): New defvar.
(counsel--faces-format-function): New defun.
(counsel-faces): Update.
With this change, the candidates are simply (face-list).
Additionally, `counsel-faces--sample-text' is no longer matched, since
it's never part of the candidate text.
Re #815
---
counsel.el | 81 ++++++++++++++++++++++++--------------------------------------
1 file changed, 31 insertions(+), 50 deletions(-)
diff --git a/counsel.el b/counsel.el
index eaaa6de..4b5f839 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2959,48 +2959,20 @@ selected candidate."
;;** `counsel-faces'
-(defun counsel-faces--update-highlight (cand)
- "Update the highlight face for the current candidate CAND.
-
-This is necessary because the default `ivy-current-match' face
-background mask most of the faces and you can not see the current
-candidate face when is selected, which is counter-intuitive and not
-user friendly. The default Emacs command `list-faces-display' have
-the same problem."
- (when (> (length cand) 0)
- (let ((face
- (intern (car (split-string (substring-no-properties cand))))))
- (face-remap-add-relative
- 'ivy-current-match
- :background (face-attribute face :background nil 'default)
- :foreground (face-attribute face :foreground nil 'default)))))
-
(defun counsel-faces-action-describe (x)
"Describe the face X."
- (let ((face (car (split-string (substring x 0 25)))))
- (describe-face (intern face))))
+ (describe-face (intern x)))
(defun counsel-faces-action-customize (x)
"Customize the face X."
- (let ((face (car (split-string (substring x 0 25)))))
- (customize-face (intern face))))
-
-(defun counsel-faces-action-insert-name (x)
- "Insert the name of face X."
- (let ((face (car (split-string (substring x 0 25)))))
- (insert face)))
-
-(defun counsel-faces-action-kill-name (x)
- "Kill the name of face X."
- (let ((face (car (split-string (substring x 0 25)))))
- (kill-new face)))
+ (customize-face (intern x)))
(ivy-set-actions
'counsel-faces
'(("d" counsel-faces-action-describe "describe face")
("c" counsel-faces-action-customize "customize face")
- ("i" counsel-faces-action-insert-name "insert face name")
- ("k" counsel-faces-action-kill-name "kill face name")))
+ ("i" insert "insert face name")
+ ("k" kill-new "kill face name")))
(defvar counsel-faces-history nil
"History for `counsel-faces'.")
@@ -3009,32 +2981,41 @@ the same problem."
"abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"
"Text string to display as the sample text for `counsel-faces'.")
+(defvar counsel--faces-fmt nil)
+
+(defun counsel--faces-format-function (cands)
+ (ivy--format-function-generic
+ (lambda (str)
+ (concat
+ (format counsel--faces-fmt
+ (ivy--add-face str 'ivy-current-match))
+ (propertize counsel-faces--sample-text 'face (intern str))))
+ (lambda (str)
+ (concat
+ (format counsel--faces-fmt
+ str)
+ (propertize counsel-faces--sample-text 'face (intern str))))
+ cands
+ "\n"))
+
(defun counsel-faces ()
"Show a list of all defined faces.
You can describe, customize, insert or kill the name or selected
candidate."
(interactive)
- (let ((minibuffer-allow-text-properties t)
- (max-length
- (apply #'max
- (mapcar
- (lambda (x)
- (length (symbol-name x)))
- (face-list)))))
- (ivy-read "%d Face: "
- (mapcar (lambda (x)
- (concat
- (propertize
- (format (format "%%-%ds " max-length) x))
- (propertize
- (format "%s" counsel-faces--sample-text)
- 'face x)))
- (face-list))
+ (let* ((minibuffer-allow-text-properties t)
+ (max-length
+ (apply #'max
+ (mapcar
+ (lambda (x)
+ (length (symbol-name x)))
+ (face-list))))
+ (counsel--faces-fmt (format "%%-%ds " max-length))
+ (ivy-format-function #'counsel--faces-format-function))
+ (ivy-read "%d Face: " (face-list)
:require-match t
:action #'counsel-faces-action-describe
- :update-fn (lambda ()
- (counsel-faces--update-highlight ivy--current))
:history 'counsel-faces-history
:caller 'counsel-faces
:sort t)))
- [elpa] master e1351c8 348/348: Merge commit 'ace01d5603ddf49b025eb811b612af72ec38dcfb' from swiper, (continued)
- [elpa] master e1351c8 348/348: Merge commit 'ace01d5603ddf49b025eb811b612af72ec38dcfb' from swiper, Oleh Krehel, 2017/04/08
- [elpa] master 3ce73ce 069/348: counsel.el (counsel-company): Enable company-mode, Oleh Krehel, 2017/04/08
- [elpa] master 61cdcd5 139/348: ivy.el (ivy-occur-press-and-switch): Use ivy-occur-last, Oleh Krehel, 2017/04/08
- [elpa] master 9346e96 194/348: Improve the overlay offset, Oleh Krehel, 2017/04/08
- [elpa] master 6644d8e 195/348: ivy-display.el: Move to wiki, Oleh Krehel, 2017/04/08
- [elpa] master e49fb6e 205/348: ivy.el (ivy-call): Set default-directory, Oleh Krehel, 2017/04/08
- [elpa] master 714cb8c 209/348: ivy.el (ivy--sort-files-by-date): Fix docstring, Oleh Krehel, 2017/04/08
- [elpa] master 0fc1507 237/348: ivy.el (ivy-occur-mode): Set view-read-only to nil locally, Oleh Krehel, 2017/04/08
- [elpa] master ea260d1 249/348: counsel.el (counsel-grep-occur): Quote the directory name, Oleh Krehel, 2017/04/08
- [elpa] master 3b15585 256/348: Fix little typo, Oleh Krehel, 2017/04/08
- [elpa] master 7dea0ff 255/348: Use ivy-format-function approach for counsel-faces,
Oleh Krehel <=
- [elpa] master 2989f25 268/348: swiper.el (swiper--update-input-ivy): Fix window-end call, Oleh Krehel, 2017/04/08
- [elpa] master c2c0e2d 270/348: ivy.el: Simplify previous commit, Oleh Krehel, 2017/04/08
- [elpa] master 75f9ceb 286/348: Allow spaces in file names when running linux apps., Oleh Krehel, 2017/04/08
- [elpa] master 2f70c56 287/348: Revert "Add missing parameter for ag", Oleh Krehel, 2017/04/08
- [elpa] master 950545b 304/348: counsel.el (counsel-linux-apps-list): Check if dir exists, Oleh Krehel, 2017/04/08
- [elpa] master 65979f6 291/348: Heed non-sort entries in ivy-sort-functions-alist, Oleh Krehel, 2017/04/08
- [elpa] master ce3c0ec 317/348: ivy.el (ivy-completing-read): Adjust :caller, Oleh Krehel, 2017/04/08
- [elpa] master d9d7592 315/348: ivy.el (ivy-completion-in-region): Remove :require-match, Oleh Krehel, 2017/04/08
- [elpa] master 4d72dc1 327/348: ivy.el: Change recursive restore order, Oleh Krehel, 2017/04/08
- [elpa] master d82dc2c 328/348: counsel.el (counsel-colors--best-contrast-color): Return same color on error, Oleh Krehel, 2017/04/08