Special-case char RET to allow for jumping to end-of-lines.

With this change you can use `avy-goto-char' also to jump to the end of
some currently visible line.  E.g., C-c j <return> (assuming C-c j is
bound to `avy-goto-char') makes all line endings jump targets.

`avy--overlay-at' had to be adapted so that the overlay at \n doesn't
make the line-break disappear.

`avy--overlay' had to be adapted in order not to put an overlay on the
char after (point-max) in case `avy--overlay-post' is used.  (Honestly,
this feature is a bit awkward with 'post overlays where the jump
location is visualized as first char in the next line.)
This commit is contained in:
Tassilo Horn 2015-05-07 14:37:31 +02:00
parent 487d5ea201
commit 903e172517

View File

@ -92,16 +92,16 @@ POS is either a position or (BEG . END)."
(defun avy--process (candidates overlay-fn) (defun avy--process (candidates overlay-fn)
"Select one of CANDIDATES using `avy-read'." "Select one of CANDIDATES using `avy-read'."
(unwind-protect (unwind-protect
(cl-case (length candidates) (cl-case (length candidates)
(0 (0
nil) nil)
(1 (1
(car candidates)) (car candidates))
(t (t
(avy--make-backgrounds (list (selected-window))) (avy--make-backgrounds (list (selected-window)))
(avy-read (avy-tree candidates avy-keys) (avy-read (avy-tree candidates avy-keys)
overlay-fn overlay-fn
#'avy--remove-leading-chars))) #'avy--remove-leading-chars)))
(avy--done))) (avy--done)))
(defvar avy--overlays-back nil (defvar avy--overlays-back nil
@ -157,16 +157,17 @@ When PRED is non-nil, it's a filter for matching point positions."
(defun avy--overlay (str pt wnd) (defun avy--overlay (str pt wnd)
"Create an overlay with STR at PT in WND." "Create an overlay with STR at PT in WND."
(let* ((pt (+ pt avy--overlay-offset)) (when (<= (1+ pt) (with-selected-window wnd (point-max)))
(ol (make-overlay pt (1+ pt) (window-buffer wnd))) (let* ((pt (+ pt avy--overlay-offset))
(old-str (with-selected-window wnd (ol (make-overlay pt (1+ pt) (window-buffer wnd)))
(buffer-substring pt (1+ pt))))) (old-str (with-selected-window wnd
(when avy-background (buffer-substring pt (1+ pt)))))
(setq old-str (propertize (when avy-background
old-str 'face 'avy-background-face))) (setq old-str (propertize
(overlay-put ol 'window wnd) old-str 'face 'avy-background-face)))
(overlay-put ol 'display (concat str old-str)) (overlay-put ol 'window wnd)
(push ol avy--overlays-lead))) (overlay-put ol 'display (concat str old-str))
(push ol avy--overlays-lead))))
(defun avy--overlay-pre (path leaf) (defun avy--overlay-pre (path leaf)
"Create an overlay with STR at LEAF. "Create an overlay with STR at LEAF.
@ -204,7 +205,9 @@ LEAF is ((BEG . END) . WND)."
(setq old-str (propertize (setq old-str (propertize
old-str 'face 'avy-background-face))) old-str 'face 'avy-background-face)))
(overlay-put ol 'window wnd) (overlay-put ol 'window wnd)
(overlay-put ol 'display str) (overlay-put ol 'display (if (string= old-str "\n")
(concat str "\n")
str))
(push ol avy--overlays-lead)))) (push ol avy--overlays-lead))))
(defun avy--overlay-post (path leaf) (defun avy--overlay-post (path leaf)
@ -267,7 +270,10 @@ STYLE determines the leading char overlay style."
The window scope is determined by `avy-all-windows' (ARG negates it)." The window scope is determined by `avy-all-windows' (ARG negates it)."
(interactive "P") (interactive "P")
(avy--generic-jump (avy--generic-jump
(regexp-quote (string (read-char "char: "))) (let ((c (read-char "char: ")))
(if (= 13 c)
"\n"
(regexp-quote (string c))))
arg arg
avy-goto-char-style)) avy-goto-char-style))