Candidates with font-lock-face properties. #1293
Comments
Here's how to do this normally: (defun ivy-ls ()
(interactive)
(let ((cands (split-string (shell-command-to-string "ls -l --color=always ~/") "\n")))
(ivy-read "prompt -> " cands
:caller 'ivy-ls)))
(defun ivy-ls-display-transformer (str)
(ansi-color-apply str))
(ivy-set-display-transformer 'ivy-ls 'ivy-ls-display-transformer) The only issue is that the Here's a small hack that I've found that makes it work, don't ask me how: (defun ivy-ls-display-transformer (str)
(ivy-append-face
(ansi-color-apply str) 'ivy-modified-buffer)) And finally, here's a solution that isn't a hack, but a bit longer: (defun ivy-ls-display-transformer (str)
(ivy-map-text-property
(ansi-color-apply str)
'font-lock-face (lambda (x) (cons 'face x))))
(defun ivy-map-text-property (str prop fun)
(let ((start 0)
(end (length str))
next prev)
(while (/= start end)
(setq next (next-single-property-change start prop str end))
(setq prev (get-text-property start prop str))
(remove-text-properties start next (list prop) str)
(when prev
(let ((new (funcall fun prev)))
(put-text-property start next (car new) (cdr new) str)))
(setq start next))
str)) Everything would be easy if
Glad to hear it, and you're welcome. |
@TonCherAmi did you find a solution to this? @abo-abo I basically have the same problem, though I use |
As an example of what I'm working with: (defun nmcli-ivy ()
(interactive)
(let* ((str (shell-command-to-string "nmcli -f IN-USE,SSID,BARS,SECURITY dev wifi list"))
(lines (split-string str "\n" 'omit-nulls))
(ssid-start (string-match-p "ssid" (car lines)))
(ssid-end (string-match-p "bars" (car lines))))
(ivy-read "[Networks] "
(append
(cdr lines)
'("Rescan"))
:action
(lambda (x)
(let ((cmd
(cond
;; First do something if wifi
((string-prefix-p "*" x)
"nmcli dev wifi disconnect")
((string= x "Rescan")
"nmcli dev wifi rescan")
(t (format
"nmcli con up %s"
(substring x ssid-start ssid-end))))))
(start-process-shell-command cmd nil cmd)))
:caller 'nmcli-ivy)))
(defun nmcli-ivy-transformer (str)
(if (string-prefix-p "*" str)
(propertize
(string-trim (substring str 1))
'face
'(:foreground "#DD6F48"))
(s-trim str)))
(ivy-set-display-transformer 'nmcli-ivy 'nmcli-ivy-transformer) |
@dieggsy no, I have not unfortunately. |
Test: (progn (pop-to-buffer (get-buffer-create "*ivy--add-face*")) (erase-buffer) (let ((str #("One" 0 3 (face (:foreground "#DD6F48"))))) (insert str "\n") (insert (ivy--add-face str 'ivy-current-match)))) Re #1293
Thanks for the persistence, I can now reproduce the issue. Here's the narrowed-down reproduction scenario: (progn
(pop-to-buffer (get-buffer-create "*ivy--add-face*"))
(erase-buffer)
(let ((str #("One"
0 3 (face
(:foreground "#DD6F48")))))
(insert str "\n")
(insert (ivy--add-face str 'ivy-current-match)))) So the problem here is I've added a quick hack to @dieggsy That's a pretty cool function. Do you want to add it to counsel maybe? |
* colir.el (colir--blend-background): Extract. Re #1293
@abo-abo your workaround seems to be working for me. Regarding |
@dieggsy Great. Take your time. Thanks in advance. |
@abo-abo seems to be working for me as well, thanks a lot. |
Hey, is it currently possible to get ivy to highlight candidates with
font-lock-face
properties?For example, I'd like to use
ansi-color-apply
on the output of some shell command and then pass the result toivy-read
:Thank you very much for this project by the way, it is absolutely fantastic.
The text was updated successfully, but these errors were encountered: