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

@ -157,6 +157,7 @@ When PRED is non-nil, it's a filter for matching point positions."
(defun avy--overlay (str pt wnd)
"Create an overlay with STR at PT in WND."
(when (<= (1+ pt) (with-selected-window wnd (point-max)))
(let* ((pt (+ pt avy--overlay-offset))
(ol (make-overlay pt (1+ pt) (window-buffer wnd)))
(old-str (with-selected-window wnd
@ -166,7 +167,7 @@ When PRED is non-nil, it's a filter for matching point positions."
old-str 'face 'avy-background-face)))
(overlay-put ol 'window wnd)
(overlay-put ol 'display (concat str old-str))
(push ol avy--overlays-lead)))
(push ol avy--overlays-lead))))
(defun avy--overlay-pre (path leaf)
"Create an overlay with STR at LEAF.
@ -204,7 +205,9 @@ LEAF is ((BEG . END) . WND)."
(setq old-str (propertize
old-str 'face 'avy-background-face)))
(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))))
(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)."
(interactive "P")
(avy--generic-jump
(regexp-quote (string (read-char "char: ")))
(let ((c (read-char "char: ")))
(if (= 13 c)
"\n"
(regexp-quote (string c))))
arg
avy-goto-char-style))