Better fontification of file names and line numbers in ivy results #399
This is more a feature request. I'd like the formatting in an ivy buffer to be more consistent and more like
I think it would be nice if filenames were in
In writing my own counsel-zgrep using
Just an idea.
The text was updated successfully, but these errors were encountered:
Commands can customize their display by let-binding
This will be way too slow. Using
They don't have one because they don't need one:
Thanks. I figured formatting all of the " counsel" buffer would be more work than necessary.
I roughly have your suggestion working. I'm let binding
And now I'm going to try rewriting it. I'm finding this portion of the code hard to wrap my head around. It would really help if CAND-PAIRS was documented somewhere.
Like what's the difference between the STRING and EXTRA part? It's probably because I'm coming from
Finally I'm not sure whether the CAND-PAIRS list that's passed around to the formating commands is for all the candidates or just the subset of candidates that are being displayed in the minibuffer? It was a surprise at first when I found my
It feels like the abstraction levels are a little confused in this area but I suspect I feel that way just because I'm having a hard time figuring out how all these pieces fit together.
The STRING part is the actual candidate. The EXTRA part is any extra information that you might want to attach. That part is almost always empty. But something like
This is standard. There is a full re-display in the post-command hook. But only the first 10 candidates are processed.
Yes, it's best to not think too much about it. Once there's enough things to abstract, the abstraction layers fall into place.
As I understand it,
The only existing functions that make use of extra is
I'm writing a
If my way of formatting is let binding an
This all works for
So my attempt at fixing this was as follows. At the bottom of
(defvar ivy-transform-cand-pairs 'identity) (let* ((ivy--index index) (pairs1 (mapcar (lambda (cand) (cons cand nil)) cands)) (pairs2 (mapcar ivy-transform-cand-pairs pairs1)) (cand-pairs (mapcar (lambda (pair) (cons (ivy--format-minibuffer-line (car pair)) (cdr pair))) pairs2)) (res (concat "\n" (funcall ivy-format-function cand-pairs)))) (put-text-property 0 (length res) 'read-only nil res) res))))
This is helpful, but the existing
I'm still thinking through what a better api for this would be, but I thought I'd get this out there. I definitely think the user option of how to format the selected line needs to be completely separate from the rest of the formatting. I also think the conversion between strings and cand-pairs needs to be more accessible to the api.
* ivy.el (ivy--display-transformers-list): New defvar. (ivy-set-display-transformer): New defun. Keys are :caller, values are str->str lambda. (ivy-state): New field display-transformer-fn. (ivy-read): Set :display-transformer-fn. (ivy--format): Apply :display-transformer-fn to each displayed candidate, in the context of ivy-window. * counsel.el (ivy-set-display-transformer): Set for `counsel-M-x'. (counsel-M-x-transformer): Promote from `counsel--M-x-transformer'. Now takes a string instead of a cons cell. (counsel-M-x): No more messing with `ivy-format-function'. Re #399
* ivy.el (ivy--format-function-generic): Third arg is no longer a list of cons cells, but a list of strings instead. (ivy-format-function-default): (ivy-format-function-arrow): (ivy-format-function-line): Take a string instead of a cons cell. (ivy--format): Feed strings instead of cons cells to `ivy-format-function'. * ivy-test.el (ivy--format): Update test. * counsel.el (counsel--yank-pop-format-function): Take a string instead of a cons cell. Re #399
Thanks for looking at this. This commit seems to have broken things. On an Emacs -Q, if I enable ivy-mode, then counsel-find-file (and most other things) fail with wrong number of arguments. I'm trying to track it down but figured I'd report it even without details.
Thanks for all the consideration of my ramblings, I really appreciate it. I think what you've done definitely improves things. Some suggestions:
The doc strings in the
I still have the problem of my entire zgrep lines getting fancy displayed (including the file names), I'll keep thinking on that.
Is the only thing that
Could it get another argument, say a regexp or function, to specify the region of the STR argument to be highlighted?