mirror of
https://github.com/abo-abo/avy.git
synced 2025-10-13 21:33:05 +00:00
Move from "avi-" to "avy-", leave old stuff obsolete
* avy-jump.el (avi-keys): (avi-background): (avi-word-punc-regexp): (avi-lead-face): (avi--goto): (avi--process): (avi-all-windows): (avi-goto-char): (avi-goto-char-2): (avi-isearch): (avi-goto-word-0): (avi-goto-subword-0): (avi-goto-word-1): (avi-goto-line): (avi-copy-line): (avi-move-line): (avi-copy-region): Make obsolete.
This commit is contained in:
parent
5d2979b911
commit
6c1f2f6423
@ -20,8 +20,7 @@
|
||||
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
(add-to-list 'load-path default-directory)
|
||||
(mapc #'byte-compile-file '("avy.el" "avy-jump.el" "ace-window.el"))
|
||||
(require 'ace-window)
|
||||
(mapc #'byte-compile-file '("avy.el" "avy-jump.el"))
|
||||
(require 'avy-jump)
|
||||
(global-set-key (kbd "C-c j") 'avi-goto-char)
|
||||
(global-set-key (kbd "C-'") 'avi-goto-char-2)
|
||||
(global-set-key (kbd "C-c j") 'avy-goto-char)
|
||||
(global-set-key (kbd "C-'") 'avy-goto-char-2)
|
||||
|
185
avy-jump.el
185
avy-jump.el
@ -3,6 +3,9 @@
|
||||
;; Copyright (C) 2015 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Oleh Krehel
|
||||
;; URL: https://github.com/abo-abo/avy-jump
|
||||
;; Version: 0.1.0
|
||||
;; Keywords: point, location
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
@ -32,31 +35,35 @@
|
||||
(defgroup avy-jump nil
|
||||
"Jump to things tree-style."
|
||||
:group 'convenience
|
||||
:prefix "avi-")
|
||||
:prefix "avy-")
|
||||
|
||||
(defcustom avi-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
|
||||
(defcustom avy-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
|
||||
"Keys for jumping.")
|
||||
(define-obsolete-variable-alias 'avi-keys 'avy-keys "0.1.0")
|
||||
|
||||
(defcustom avi-background nil
|
||||
(defcustom avy-background nil
|
||||
"When non-nil, a gray background will be added during the selection."
|
||||
:type 'boolean)
|
||||
(define-obsolete-variable-alias 'avi-background 'avy-background "0.1.0")
|
||||
|
||||
(defcustom avi-word-punc-regexp "[!-/:-@[-`{-~]"
|
||||
(defcustom avy-word-punc-regexp "[!-/:-@[-`{-~]"
|
||||
"Regexp of punctuation characters that should be matched when calling
|
||||
`avi-goto-word-1' command. When nil, punctuation chars will not be matched.
|
||||
`avy-goto-word-1' command. When nil, punctuation chars will not be matched.
|
||||
|
||||
\"[!-/:-@[-`{-~]\" will match all printable punctuation chars.")
|
||||
(define-obsolete-variable-alias 'avi-word-punc-regexp 'avy-word-punc-regexp "0.1.0")
|
||||
|
||||
(defface avi-lead-face
|
||||
'((t (:foreground "white" :background "#e52b50")))
|
||||
(defface avy-lead-face
|
||||
'((t (:foreground "white" :background "#e52b50")))
|
||||
"Face used for the leading chars.")
|
||||
(define-obsolete-face-alias 'avi-lead-face 'avy-lead-face "0.1.0")
|
||||
|
||||
(defface avy-background-face
|
||||
'((t (:foreground "gray40")))
|
||||
"Face for whole window background during selection.")
|
||||
|
||||
;;* Internals
|
||||
(defun avi--goto (x)
|
||||
(defun avy--goto (x)
|
||||
"Goto X.
|
||||
X is (POS . WND)
|
||||
POS is either a position or (BEG . END)."
|
||||
@ -68,8 +75,9 @@ POS is either a position or (BEG . END)."
|
||||
(setq pt (car pt)))
|
||||
(unless (= pt (point)) (push-mark))
|
||||
(goto-char pt))))
|
||||
(define-obsolete-function-alias 'avi--goto 'avy--goto "0.1.0")
|
||||
|
||||
(defun avi--process (candidates overlay-fn)
|
||||
(defun avy--process (candidates overlay-fn)
|
||||
"Select one of CANDIDATES using `avy-read'."
|
||||
(unwind-protect
|
||||
(cl-case (length candidates)
|
||||
@ -79,17 +87,18 @@ POS is either a position or (BEG . END)."
|
||||
(car candidates))
|
||||
(t
|
||||
(avy--make-backgrounds (list (selected-window)))
|
||||
(avy-read (avy-tree candidates avi-keys)
|
||||
(avy-read (avy-tree candidates avy-keys)
|
||||
overlay-fn
|
||||
#'avy--remove-leading-chars)))
|
||||
(avy--done)))
|
||||
(define-obsolete-function-alias 'avi--process 'avy--process "0.1.0")
|
||||
|
||||
(defvar avy--overlays-back nil
|
||||
"Hold overlays for when `avi-background' is t.")
|
||||
"Hold overlays for when `avy-background' is t.")
|
||||
|
||||
(defun avy--make-backgrounds (wnd-list)
|
||||
"Create a dim background overlay for each window on WND-LIST."
|
||||
(when avi-background
|
||||
(when avy-background
|
||||
(setq avy--overlays-back
|
||||
(mapcar (lambda (w)
|
||||
(let ((ol (make-overlay
|
||||
@ -106,16 +115,17 @@ POS is either a position or (BEG . END)."
|
||||
(setq avy--overlays-back nil)
|
||||
(avy--remove-leading-chars))
|
||||
|
||||
(defcustom avi-all-windows t
|
||||
(defcustom avy-all-windows t
|
||||
"When non-nil, loop though all windows for candidates."
|
||||
:type 'boolean)
|
||||
(define-obsolete-variable-alias 'avi-all-windows 'avy-all-windows "0.1.0")
|
||||
|
||||
(defun avi--regex-candidates (regex &optional wnd beg end pred)
|
||||
(defun avy--regex-candidates (regex &optional wnd beg end pred)
|
||||
"Return all elements that match REGEX in WND.
|
||||
Each element of the list is ((BEG . END) . WND)
|
||||
When PRED is non-nil, it's a filter for matching point positions."
|
||||
(let (candidates)
|
||||
(dolist (wnd (if avi-all-windows
|
||||
(dolist (wnd (if avy-all-windows
|
||||
(window-list)
|
||||
(list (selected-window))))
|
||||
(with-selected-window wnd
|
||||
@ -131,8 +141,8 @@ When PRED is non-nil, it's a filter for matching point positions."
|
||||
wnd) candidates))))))))
|
||||
(nreverse candidates)))
|
||||
|
||||
(defvar avi--overlay-offset 0
|
||||
"The offset to apply in `avi--overlay'.")
|
||||
(defvar avy--overlay-offset 0
|
||||
"The offset to apply in `avy--overlay'.")
|
||||
|
||||
(defvar avy--overlays-lead nil
|
||||
"Hold overlays for leading chars.")
|
||||
@ -142,26 +152,26 @@ When PRED is non-nil, it's a filter for matching point positions."
|
||||
(mapc #'delete-overlay avy--overlays-lead)
|
||||
(setq avy--overlays-lead nil))
|
||||
|
||||
(defun avi--overlay (str pt wnd)
|
||||
(defun avy--overlay (str pt wnd)
|
||||
"Create an overlay with STR at PT in WND."
|
||||
(let* ((pt (+ pt avi--overlay-offset))
|
||||
(let* ((pt (+ pt avy--overlay-offset))
|
||||
(ol (make-overlay pt (1+ pt) (window-buffer wnd)))
|
||||
(old-str (with-selected-window wnd
|
||||
(buffer-substring pt (1+ pt)))))
|
||||
(when avi-background
|
||||
(when avy-background
|
||||
(setq old-str (propertize
|
||||
old-str 'face 'avy-background-face)))
|
||||
(overlay-put ol 'window wnd)
|
||||
(overlay-put ol 'display (concat str old-str))
|
||||
(push ol avy--overlays-lead)))
|
||||
|
||||
(defun avi--overlay-pre (path leaf)
|
||||
(defun avy--overlay-pre (path leaf)
|
||||
"Create an overlay with STR at LEAF.
|
||||
PATH is a list of keys from tree root to LEAF.
|
||||
LEAF is ((BEG . END) . WND)."
|
||||
(avi--overlay
|
||||
(avy--overlay
|
||||
(propertize (apply #'string (reverse path))
|
||||
'face 'avi-lead-face)
|
||||
'face 'avy-lead-face)
|
||||
(cond ((numberp leaf)
|
||||
leaf)
|
||||
((consp (car leaf))
|
||||
@ -171,14 +181,15 @@ LEAF is ((BEG . END) . WND)."
|
||||
(if (consp leaf)
|
||||
(cdr leaf)
|
||||
(selected-window))))
|
||||
(define-obsolete-function-alias 'avi--overlay-pre 'avy--overlay-pre "0.1.0")
|
||||
|
||||
(defun avi--overlay-at (path leaf)
|
||||
(defun avy--overlay-at (path leaf)
|
||||
"Create an overlay with STR at LEAF.
|
||||
PATH is a list of keys from tree root to LEAF.
|
||||
LEAF is ((BEG . END) . WND)."
|
||||
(let ((str (propertize
|
||||
(string (car (last path)))
|
||||
'face 'avi-lead-face))
|
||||
'face 'avy-lead-face))
|
||||
(pt (if (consp (car leaf))
|
||||
(caar leaf)
|
||||
(car leaf)))
|
||||
@ -187,20 +198,21 @@ LEAF is ((BEG . END) . WND)."
|
||||
(window-buffer wnd)))
|
||||
(old-str (with-selected-window wnd
|
||||
(buffer-substring pt (1+ pt)))))
|
||||
(when avi-background
|
||||
(when avy-background
|
||||
(setq old-str (propertize
|
||||
old-str 'face 'avy-background-face)))
|
||||
(overlay-put ol 'window wnd)
|
||||
(overlay-put ol 'display str)
|
||||
(push ol avy--overlays-lead))))
|
||||
(define-obsolete-function-alias 'avi--overlay-at 'avy--overlay-at "0.1.0")
|
||||
|
||||
(defun avi--overlay-post (path leaf)
|
||||
(defun avy--overlay-post (path leaf)
|
||||
"Create an overlay with STR at LEAF.
|
||||
PATH is a list of keys from tree root to LEAF.
|
||||
LEAF is ((BEG . END) . WND)."
|
||||
(avi--overlay
|
||||
(avy--overlay
|
||||
(propertize (apply #'string (reverse path))
|
||||
'face 'avi-lead-face)
|
||||
'face 'avy-lead-face)
|
||||
(cond ((numberp leaf)
|
||||
leaf)
|
||||
((consp (car leaf))
|
||||
@ -210,102 +222,109 @@ LEAF is ((BEG . END) . WND)."
|
||||
(if (consp leaf)
|
||||
(cdr leaf)
|
||||
(selected-window))))
|
||||
(define-obsolete-function-alias 'avi--overlay-post 'avy--overlay-post "0.1.0")
|
||||
|
||||
(defun avi--generic-jump (regex flip)
|
||||
(defun avy--generic-jump (regex flip)
|
||||
"Jump to REGEX.
|
||||
When FLIP is non-nil, flip `avi-all-windows'."
|
||||
(let ((avi-all-windows
|
||||
When FLIP is non-nil, flip `avy-all-windows'."
|
||||
(let ((avy-all-windows
|
||||
(if flip
|
||||
(not avi-all-windows)
|
||||
avi-all-windows)))
|
||||
(avi--goto
|
||||
(avi--process
|
||||
(avi--regex-candidates
|
||||
(not avy-all-windows)
|
||||
avy-all-windows)))
|
||||
(avy--goto
|
||||
(avy--process
|
||||
(avy--regex-candidates
|
||||
regex)
|
||||
#'avi--overlay-post))))
|
||||
#'avy--overlay-post))))
|
||||
|
||||
;;* Commands
|
||||
;;;###autoload
|
||||
(defun avi-goto-char (&optional arg)
|
||||
(defun avy-goto-char (&optional arg)
|
||||
"Read one char and jump to it.
|
||||
The window scope is determined by `avi-all-windows'.
|
||||
The window scope is determined by `avy-all-windows'.
|
||||
When ARG is non-nil, flip the window scope."
|
||||
(interactive "P")
|
||||
(avi--generic-jump
|
||||
(avy--generic-jump
|
||||
(string (read-char "char: ")) arg))
|
||||
(define-obsolete-function-alias 'avi-goto-char 'avy-goto-char "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-goto-char-2 (&optional arg)
|
||||
(defun avy-goto-char-2 (&optional arg)
|
||||
"Read two chars and jump to them in current window.
|
||||
When ARG is non-nil, flip the window scope."
|
||||
(interactive "P")
|
||||
(avi--generic-jump
|
||||
(avy--generic-jump
|
||||
(string
|
||||
(read-char "char 1: ")
|
||||
(read-char "char 2: "))
|
||||
arg))
|
||||
(define-obsolete-function-alias 'avi-goto-char-2 'avy-goto-char-2 "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-isearch ()
|
||||
(defun avy-isearch ()
|
||||
"Jump to one of the current isearch candidates."
|
||||
(interactive)
|
||||
(let* ((candidates
|
||||
(avi--regex-candidates isearch-string))
|
||||
(avi-background nil)
|
||||
(avy--regex-candidates isearch-string))
|
||||
(avy-background nil)
|
||||
(candidate
|
||||
(avi--process candidates #'avi--overlay-post)))
|
||||
(avy--process candidates #'avy--overlay-post)))
|
||||
(isearch-done)
|
||||
(avi--goto candidate)))
|
||||
(avy--goto candidate)))
|
||||
(define-obsolete-function-alias 'avi-isearch 'avy-isearch "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-goto-word-0 (arg)
|
||||
(defun avy-goto-word-0 (arg)
|
||||
"Jump to a word start."
|
||||
(interactive "P")
|
||||
(let ((avi-keys (number-sequence ?a ?z)))
|
||||
(avi--generic-jump "\\b\\sw" arg)))
|
||||
(let ((avy-keys (number-sequence ?a ?z)))
|
||||
(avy--generic-jump "\\b\\sw" arg)))
|
||||
(define-obsolete-function-alias 'avi-goto-word-0 'avy-goto-word-0 "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-goto-subword-0 (&optional arg)
|
||||
(defun avy-goto-subword-0 (&optional arg)
|
||||
"Jump to a word or subword start."
|
||||
(interactive "P")
|
||||
(let* ((avi-all-windows
|
||||
(let* ((avy-all-windows
|
||||
(if arg
|
||||
(not avi-all-windows)
|
||||
avi-all-windows))
|
||||
(avi-keys (number-sequence ?a ?z))
|
||||
(candidates (avi--regex-candidates
|
||||
(not avy-all-windows)
|
||||
avy-all-windows))
|
||||
(avy-keys (number-sequence ?a ?z))
|
||||
(candidates (avy--regex-candidates
|
||||
"\\(\\b\\sw\\)\\|\\(?:[^A-Z]\\([A-Z]\\)\\)")))
|
||||
(dolist (x candidates)
|
||||
(when (> (- (cdar x) (caar x)) 1)
|
||||
(cl-incf (caar x))))
|
||||
(avi--goto
|
||||
(avi--process candidates #'avi--overlay-pre))))
|
||||
(avy--goto
|
||||
(avy--process candidates #'avy--overlay-pre))))
|
||||
(define-obsolete-function-alias 'avi-goto-subword-0 'avy-goto-subword-0 "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-goto-word-1 ()
|
||||
(defun avy-goto-word-1 ()
|
||||
"Jump to a word start in current window.
|
||||
Read one char with which the word should start."
|
||||
(interactive)
|
||||
(let* ((str (string (read-char "char: ")))
|
||||
(candidates (avi--regex-candidates
|
||||
(if (and avi-word-punc-regexp
|
||||
(string-match avi-word-punc-regexp str))
|
||||
(candidates (avy--regex-candidates
|
||||
(if (and avy-word-punc-regexp
|
||||
(string-match avy-word-punc-regexp str))
|
||||
str
|
||||
(concat
|
||||
"\\b"
|
||||
str)))))
|
||||
(avi--goto
|
||||
(avi--process candidates #'avi--overlay-pre))))
|
||||
(avy--goto
|
||||
(avy--process candidates #'avy--overlay-pre))))
|
||||
(define-obsolete-function-alias 'avi-goto-word-1 'avy-goto-word-1 "0.1.0")
|
||||
|
||||
(defun avi--line (&optional arg)
|
||||
(defun avy--line (&optional arg)
|
||||
"Select line in current window."
|
||||
(let ((avi-background nil)
|
||||
(avi-all-windows
|
||||
(let ((avy-background nil)
|
||||
(avy-all-windows
|
||||
(if arg
|
||||
(not avi-all-windows)
|
||||
avi-all-windows))
|
||||
(not avy-all-windows)
|
||||
avy-all-windows))
|
||||
candidates)
|
||||
(dolist (wnd (if avi-all-windows
|
||||
(dolist (wnd (if avy-all-windows
|
||||
(window-list)
|
||||
(list (selected-window))))
|
||||
(with-selected-window wnd
|
||||
@ -320,20 +339,21 @@ Read one char with which the word should start."
|
||||
(push (cons (point) (selected-window))
|
||||
candidates))
|
||||
(forward-line 1)))))))
|
||||
(avi--process (nreverse candidates) #'avi--overlay-pre)))
|
||||
(avy--process (nreverse candidates) #'avy--overlay-pre)))
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-goto-line (&optional arg)
|
||||
(defun avy-goto-line (&optional arg)
|
||||
"Jump to a line start in current buffer."
|
||||
(interactive "P")
|
||||
(avi--goto (avi--line arg)))
|
||||
(avy--goto (avy--line arg)))
|
||||
(define-obsolete-function-alias 'avi-goto-line 'avy-goto-line "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-copy-line (arg)
|
||||
(defun avy-copy-line (arg)
|
||||
"Copy a selected line above the current line.
|
||||
ARG lines can be used."
|
||||
(interactive "p")
|
||||
(let ((start (car (avi--line))))
|
||||
(let ((start (car (avy--line))))
|
||||
(move-beginning-of-line nil)
|
||||
(save-excursion
|
||||
(insert
|
||||
@ -344,13 +364,14 @@ ARG lines can be used."
|
||||
(move-end-of-line arg)
|
||||
(point)))
|
||||
"\n"))))
|
||||
(define-obsolete-function-alias 'avi-copy-line 'avy-copy-line "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-move-line (arg)
|
||||
(defun avy-move-line (arg)
|
||||
"Move a selected line above the current line.
|
||||
ARG lines can be used."
|
||||
(interactive "p")
|
||||
(let ((start (car (avi--line))))
|
||||
(let ((start (car (avy--line))))
|
||||
(move-beginning-of-line nil)
|
||||
(save-excursion
|
||||
(save-excursion
|
||||
@ -360,13 +381,14 @@ ARG lines can be used."
|
||||
(insert
|
||||
(current-kill 0)
|
||||
"\n"))))
|
||||
(define-obsolete-function-alias 'avi-move-line 'avy-move-line "0.1.0")
|
||||
|
||||
;;;###autoload
|
||||
(defun avi-copy-region ()
|
||||
(defun avy-copy-region ()
|
||||
"Select two lines and copy the text between them here."
|
||||
(interactive)
|
||||
(let ((beg (car (avi--line)))
|
||||
(end (car (avi--line)))
|
||||
(let ((beg (car (avy--line)))
|
||||
(end (car (avy--line)))
|
||||
(pad (if (bolp) "" "\n")))
|
||||
(move-beginning-of-line nil)
|
||||
(save-excursion
|
||||
@ -377,6 +399,7 @@ ARG lines can be used."
|
||||
(goto-char end)
|
||||
(line-end-position)))
|
||||
pad))))
|
||||
(define-obsolete-function-alias 'avi-copy-region 'avy-copy-region "0.1.0")
|
||||
|
||||
(provide 'avy-jump)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user