Add avy-candidate-* helper functions

* avy.el (avy-candidate-beg):
(avy-candidate-end):
(avy-candidate-wnd): New defun.
(avy--overlay-pre):
(avy--overlay-at):
(avy--overlay-at-full):
(avy--overlay-post): Update.
This commit is contained in:
Oleh Krehel 2015-10-25 13:20:41 +01:00
parent cf36a599f2
commit 3257d81b4a

55
avy.el
View File

@ -649,6 +649,30 @@ Do this even when the char is terminating."
(or (cdr (assoc c avy-key-to-char-alist)) (or (cdr (assoc c avy-key-to-char-alist))
(error "Unknown key %s" c)))) (error "Unknown key %s" c))))
(defun avy-candidate-beg (leaf)
"Return the start position for LEAF."
(cond ((numberp leaf)
leaf)
((consp (car leaf))
(caar leaf))
(t
(car leaf))))
(defun avy-candidate-end (leaf)
"Return the end position for LEAF."
(cond ((numberp leaf)
leaf)
((consp (car leaf))
(cdar leaf))
(t
(car leaf))))
(defun avy-candidate-wnd (leaf)
"Return the window for LEAF."
(if (consp leaf)
(cdr leaf)
(selected-window)))
(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.
@ -664,15 +688,8 @@ LEAF is normally ((BEG . END) . WND)."
str)) str))
(avy--overlay (avy--overlay
str str
(cond ((numberp leaf) (avy-candidate-beg leaf)
leaf) (avy-candidate-wnd leaf))))
((consp (car leaf))
(caar leaf))
(t
(car leaf)))
(if (consp leaf)
(cdr leaf)
(selected-window)))))
(defun avy--overlay-at (path leaf) (defun avy--overlay-at (path leaf)
"Create an overlay with PATH at LEAF. "Create an overlay with PATH at LEAF.
@ -682,10 +699,7 @@ LEAF is normally ((BEG . END) . WND)."
(str (propertize (str (propertize
(string (car (last path))) (string (car (last path)))
'face 'avy-lead-face)) 'face 'avy-lead-face))
(pt (+ (if (consp (car leaf)) (pt (+ (avy-candidate-beg leaf) avy--overlay-offset))
(caar leaf)
(car leaf))
avy--overlay-offset))
(wnd (cdr leaf)) (wnd (cdr leaf))
(ol (make-overlay pt (1+ pt) (window-buffer wnd))) (ol (make-overlay pt (1+ pt) (window-buffer wnd)))
(old-str (avy--old-str pt wnd))) (old-str (avy--old-str pt wnd)))
@ -707,9 +721,7 @@ LEAF is normally ((BEG . END) . WND)."
(apply #'string (reverse path)) (apply #'string (reverse path))
'face 'avy-lead-face)) 'face 'avy-lead-face))
(len (length path)) (len (length path))
(beg (if (consp (car leaf)) (beg (avy-candidate-beg leaf))
(caar leaf)
(car leaf)))
(wnd (cdr leaf)) (wnd (cdr leaf))
oov) oov)
(dotimes (i len) (dotimes (i len)
@ -791,15 +803,8 @@ LEAF is normally ((BEG . END) . WND)."
str)) str))
(avy--overlay (avy--overlay
str str
(cond ((numberp leaf) (avy-candidate-end leaf)
leaf) (avy-candidate-wnd leaf))))
((consp (car leaf))
(cdar leaf))
(t
(car leaf)))
(if (consp leaf)
(cdr leaf)
(selected-window)))))
(defun avy--style-fn (style) (defun avy--style-fn (style)
"Transform STYLE symbol to a style function." "Transform STYLE symbol to a style function."