Customize how `avy-lead-face-0' is applied

* avy.el (avy-highlight-first): New defcustom. When non-nil, use
  `avy-lead-face-0' even on terminal chars.
(avy--overlay-pre): Update.
(avy--overlay-at-full): Update.
(avy--overlay-post): Update.

Fixes #42
This commit is contained in:
Oleh Krehel 2015-05-16 19:31:26 +02:00
parent 1127467669
commit ea6f5c5953

11
avy.el
View File

@ -374,13 +374,18 @@ When GROUP is non-nil, (BEG . END) should delimit that regex group."
(overlay-put ol 'display (concat str old-str)) (overlay-put ol 'display (concat str old-str))
(push ol avy--overlays-lead)))) (push ol avy--overlays-lead))))
(defcustom avy-highlight-first nil
"When non-nil highlight the first decision char with `avy-lead-face-0'.
Do this even when the char is terminating."
:type 'boolean)
(defun avy--overlay-pre (path leaf) (defun avy--overlay-pre (path leaf)
"Create an overlay with PATH at LEAF. "Create an overlay with PATH at LEAF.
PATH is a list of keys from tree root to LEAF. PATH is a list of keys from tree root to LEAF.
LEAF is normally ((BEG . END) . WND)." LEAF is normally ((BEG . END) . WND)."
(let ((str (propertize (apply #'string (reverse path)) (let ((str (propertize (apply #'string (reverse path))
'face 'avy-lead-face))) 'face 'avy-lead-face)))
(when (> (length str) 1) (when (or avy-highlight-first (> (length str) 1))
(set-text-properties 0 1 '(face avy-lead-face-0) str)) (set-text-properties 0 1 '(face avy-lead-face-0) str))
(setq str (concat (setq str (concat
(propertize avy-current-path (propertize avy-current-path
@ -435,7 +440,7 @@ LEAF is normally ((BEG . END) . WND)."
(caar leaf) (caar leaf)
(car leaf))) (car leaf)))
(wnd (cdr leaf))) (wnd (cdr leaf)))
(when (> (length str) 1) (when (or avy-highlight-first (> (length str) 1))
(set-text-properties 0 1 '(face avy-lead-face-0) str)) (set-text-properties 0 1 '(face avy-lead-face-0) str))
(with-selected-window wnd (with-selected-window wnd
(save-excursion (save-excursion
@ -469,7 +474,7 @@ PATH is a list of keys from tree root to LEAF.
LEAF is normally ((BEG . END) . WND)." LEAF is normally ((BEG . END) . WND)."
(let ((str (propertize (apply #'string (reverse path)) (let ((str (propertize (apply #'string (reverse path))
'face 'avy-lead-face))) 'face 'avy-lead-face)))
(when (> (length str) 1) (when (or avy-highlight-first (> (length str) 1))
(set-text-properties 0 1 '(face avy-lead-face-0) str)) (set-text-properties 0 1 '(face avy-lead-face-0) str))
(setq str (concat (setq str (concat
(propertize avy-current-path (propertize avy-current-path