-;;; avy.el --- set-based completion -*- lexical-binding: t -*-
+;;; avy.el --- tree-based completion -*- lexical-binding: t -*-
;; Copyright (C) 2015 Free Software Foundation, Inc.
;; Author: Oleh Krehel <ohwoeowho@gmail.com>
;; URL: https://github.com/abo-abo/avy
-;; Version: 0.3.0
+;; Version: 0.4.0
;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
;; Keywords: point, location
When GROUP is non-nil, (BEG . END) should delimit that regex group."
(setq group (or group 0))
(let ((case-fold-search (or avy-case-fold-search
- (not (string= regex (upcase regex)))))
+ (string= regex (downcase regex))))
candidates)
(avy-dowindows current-prefix-arg
(dolist (pair (avy--find-visible-regions
(defun avy--overlay (str beg end wnd &optional compose-fn)
"Create an overlay with STR from BEG to END in WND.
COMPOSE-FN is a lambda that concatenates the old string at BEG with STR."
- (when (<= (1+ beg) (with-selected-window wnd (point-max)))
- (let* ((beg (+ beg avy--overlay-offset))
- (ol (make-overlay beg (or end (1+ beg)) (window-buffer wnd)))
- (old-str (avy--old-str beg wnd))
- (os-line-prefix (get-text-property 0 'line-prefix old-str))
- (os-wrap-prefix (get-text-property 0 'wrap-prefix old-str)))
- (when os-line-prefix
- (add-text-properties 0 1 `(line-prefix ,os-line-prefix) str))
- (when os-wrap-prefix
- (add-text-properties 0 1 `(wrap-prefix ,os-wrap-prefix) str))
- (overlay-put ol 'window wnd)
- (overlay-put ol 'category 'avy)
- (overlay-put ol 'display (funcall
- (or compose-fn #'concat)
- str old-str))
- (push ol avy--overlays-lead))))
+ (let ((eob (with-selected-window wnd (point-max))))
+ (when (<= beg eob)
+ (let* ((beg (+ beg avy--overlay-offset))
+ (ol (make-overlay beg (or end (1+ beg)) (window-buffer wnd)))
+ (old-str (if (eq beg eob) "" (avy--old-str beg wnd)))
+ (os-line-prefix (get-text-property 0 'line-prefix old-str))
+ (os-wrap-prefix (get-text-property 0 'wrap-prefix old-str))
+ other-ol)
+ (when os-line-prefix
+ (add-text-properties 0 1 `(line-prefix ,os-line-prefix) str))
+ (when os-wrap-prefix
+ (add-text-properties 0 1 `(wrap-prefix ,os-wrap-prefix) str))
+ (when (setq other-ol (cl-find-if
+ (lambda (o) (overlay-get o 'goto-address))
+ (overlays-at beg)))
+ (add-text-properties
+ 0 (length old-str)
+ `(face ,(overlay-get other-ol 'face)) old-str))
+ (overlay-put ol 'window wnd)
+ (overlay-put ol 'category 'avy)
+ (overlay-put ol (if (eq beg eob)
+ 'after-string
+ 'display)
+ (funcall
+ (or compose-fn #'concat)
+ str old-str))
+ (push ol avy--overlays-lead)))))
(defcustom avy-highlight-first nil
"When non-nil highlight the first decision char with `avy-lead-face-0'.
len))
lep)))
(when (and (bound-and-true-p visual-line-mode)
- (> len (- end beg)))
+ (> len (- end beg))
+ (not (eq lep beg)))
(setq len (- end beg))
(let ((old-str (apply #'string (reverse path))))
(setq str
(setq temporary-goal-column 0)
(line-move-visual 1 t))
(forward-line 1)))))))
- (setq avy-action #'identity)
- (avy--process (nreverse candidates) (avy--style-fn avy-style))))
+ (let ((avy-action #'identity))
+ (avy--process (nreverse candidates) (avy--style-fn avy-style)))))
;;;###autoload
(defun avy-goto-line (&optional arg)
Otherwise, forward to `goto-line' with ARG."
(interactive "p")
+ (setq arg (or arg 1))
(if (not (memq arg '(1 4)))
(progn
(goto-char (point-min))
"Copy a selected line above the current line.
ARG lines can be used."
(interactive "p")
- (avy-with avy-copy-line
- (let* ((start (avy--line))
- (str (buffer-substring-no-properties
- start
- (save-excursion
- (goto-char start)
- (move-end-of-line arg)
- (point)))))
- (cond ((eq avy-line-insert-style 'above)
- (beginning-of-line)
- (save-excursion
- (insert str "\n")))
- ((eq avy-line-insert-style 'below)
- (end-of-line)
- (insert "\n" str)
- (beginning-of-line))
- (t
- (user-error "Unexpected `avy-line-insert-style'"))))))
+ (let ((initial-window (selected-window)))
+ (avy-with avy-copy-line
+ (let* ((start (avy--line))
+ (str (buffer-substring-no-properties
+ start
+ (save-excursion
+ (goto-char start)
+ (move-end-of-line arg)
+ (point)))))
+ (select-window initial-window)
+ (cond ((eq avy-line-insert-style 'above)
+ (beginning-of-line)
+ (save-excursion
+ (insert str "\n")))
+ ((eq avy-line-insert-style 'below)
+ (end-of-line)
+ (insert "\n" str)
+ (beginning-of-line))
+ (t
+ (user-error "Unexpected `avy-line-insert-style'")))))))
;;;###autoload
(defun avy-move-line (arg)
"Move a selected line above the current line.
ARG lines can be used."
(interactive "p")
- (avy-with avy-move-line
- (let ((start (avy--line)))
- (save-excursion
- (goto-char start)
- (kill-whole-line arg))
- (cond ((eq avy-line-insert-style 'above)
- (beginning-of-line)
- (save-excursion
- (insert
- (current-kill 0))))
- ((eq avy-line-insert-style 'below)
- (end-of-line)
- (newline)
- (save-excursion
- (insert (substring (current-kill 0) 0 -1))))
- (t
- (user-error "Unexpected `avy-line-insert-style'"))))))
+ (let ((initial-window (selected-window)))
+ (avy-with avy-move-line
+ (let ((start (avy--line)))
+ (save-excursion
+ (goto-char start)
+ (kill-whole-line arg))
+ (select-window initial-window)
+ (cond ((eq avy-line-insert-style 'above)
+ (beginning-of-line)
+ (save-excursion
+ (insert
+ (current-kill 0))))
+ ((eq avy-line-insert-style 'below)
+ (end-of-line)
+ (newline)
+ (save-excursion
+ (insert (substring (current-kill 0) 0 -1))))
+ (t
+ (user-error "Unexpected `avy-line-insert-style'")))))))
;;;###autoload
(defun avy-copy-region (arg)
(interactive "P")
(let ((initial-window (selected-window)))
(avy-with avy-copy-region
- (let* ((beg (avy--line arg))
+ (let* ((beg (save-selected-window
+ (avy--line arg)))
(end (avy--line arg))
(str (buffer-substring-no-properties
beg
(setq str (concat str (list char)))))
;; Highlight
(when (>= (length str) 1)
- (let (found)
+ (let ((case-fold-search
+ (or avy-case-fold-search (string= str (downcase str))))
+ found)
(avy-dowindows current-prefix-arg
(dolist (pair (avy--find-visible-regions
(window-start)