abo-abo / swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
https://oremacs.com/swiper/
2.29k stars 338 forks source link

[Question] Ivy - Faces and display function #1098

Open joca-bt opened 7 years ago

joca-bt commented 7 years ago

I'm trying to customize my Ivy faces but I'm failing to understand the purpose of ivy-minibuffer-face-1 face? I never see it on the minibuffer. When is it used? Example image below. (I'm looking to have one and the same face for all matches.)

ivy

Is there a way to rotate the candidates lists so that the current match is always on top, instead of moving the matching line, à la ido-vertical-mode? Which functions should I look into?

I'm using Ivy 0.9.1 on Emacs 25.2.

abo-abo commented 7 years ago

I see you use the fuzzy matcher. With regular matcher, this face will highlight the intervals between match parts.

joca-bt commented 7 years ago

Oh I see, thanks.

Is there a way to force the current match to select the first candidate whenever additional text is typed? This happens with C-x C-f but not with M-x, for example. I don't know if I was clear.

For example, in the first image when I type s the first candidate is selected, instead of whatever I had selected previously, i.e. there seems to be some kind of reset. In the second image the candidate number continues to be the same.

ivy1

ivy2

JSDurand commented 6 years ago

I think the current match is reset in counsel-M-x now.

And to rotate the candidate list, you should write your own ivy-format-function. For exemple, you might want to try the following:

(defun durand-ivy-format-function-arrow (cands)
  "Transform CAND-PAIRS into a string for minibuffer using \"○ \" instead of \">\"."
  (durand-ivy-format-function-generic
   (lambda (str)
     (concat (propertize "○ "
             'face '(:foreground "gold1"))
         (ivy--add-face str 'ivy-current-match)))
   (lambda (str)
     (concat "  " str))
   cands
   "\n"))

(setq ivy-format-function 'durand-ivy-format-function-arrow)

(defun durand-ivy-format-function-generic (selected-fn other-fn cands separator)
  "Ido style!"
  (let ((i -1))
    (mapconcat
     (lambda (str)
       (let ((curr (eq (cl-incf i) 0)))
     (if curr
         (funcall selected-fn str)
       (funcall other-fn str))))
     (durand-ivy-cycle-collection (- 0 ivy--window-index) cands)
     separator)))

(defun durand-ivy-cycle-collection (arg col)
  (let* ((arg (or arg 1))
     (len (length col))
     new-li)
    (dotimes (ind len new-li)
      (push
       (nth (mod (- len ind arg 1) len) col)
       new-li))))

This might not be the best solution, but I am a newbie, so feel free to improve it. ;)