-
-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better fontification of file names and line numbers in ivy results #399
Comments
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 Rather than 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
Have a look, it's a lot simpler now. |
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. |
Ok, in |
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 think Both 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? |
This is more a feature request. I'd like the formatting in an ivy buffer to be more consistent and more like
compliation-mode
orgrep-mode
.counsel-grep
lines begin "linenumber:" andswiper
lines don't have the colon. Seems like that could be unified. Then there are other lines like fromcounsel-git-grep
or other multifile searches that are prefixed "filename:linenumber:".I think it would be nice if filenames were in
compilation-info
face and line numbers were incompilation-line-number
face (which are whatcompilation mode
uses (andgrep-mode
defaults to). It would be great if ivy could figure this out automatically so that new commands got this too. Also the match highlighting that happens of the typed in text, should be limited to after the file name or line number. Now if the search string is in the file name, it's highlighted as well.In writing my own counsel-zgrep using
counsel--async-command
I'm not quite sure where to plug this in. I think ivy does the fontification as things are added to the minibuffer, but I don't have an easy hook into that. Followingcompilation-mode
's model I think would be to turn on font-lock in the*counsel*
buffer and have it highlighted as text is added to it, then hopefully those text properties would be preserved as they're copied into the minibuffer for display.Just an idea.
The text was updated successfully, but these errors were encountered: