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:
Oleh Krehel 2015-05-05 16:53:37 +02:00
parent 5d2979b911
commit 6c1f2f6423
2 changed files with 107 additions and 85 deletions

View File

@ -20,8 +20,7 @@
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
(add-to-list 'load-path default-directory) (add-to-list 'load-path default-directory)
(mapc #'byte-compile-file '("avy.el" "avy-jump.el" "ace-window.el")) (mapc #'byte-compile-file '("avy.el" "avy-jump.el"))
(require 'ace-window)
(require 'avy-jump) (require 'avy-jump)
(global-set-key (kbd "C-c j") 'avi-goto-char) (global-set-key (kbd "C-c j") 'avy-goto-char)
(global-set-key (kbd "C-'") 'avi-goto-char-2) (global-set-key (kbd "C-'") 'avy-goto-char-2)

View File

@ -3,6 +3,9 @@
;; Copyright (C) 2015 Free Software Foundation, Inc. ;; Copyright (C) 2015 Free Software Foundation, Inc.
;; Author: Oleh Krehel ;; 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. ;; This file is part of GNU Emacs.
@ -32,31 +35,35 @@
(defgroup avy-jump nil (defgroup avy-jump nil
"Jump to things tree-style." "Jump to things tree-style."
:group 'convenience :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.") "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." "When non-nil, a gray background will be added during the selection."
:type 'boolean) :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 "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.") \"[!-/:-@[-`{-~]\" 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 (defface avy-lead-face
'((t (:foreground "white" :background "#e52b50"))) '((t (:foreground "white" :background "#e52b50")))
"Face used for the leading chars.") "Face used for the leading chars.")
(define-obsolete-face-alias 'avi-lead-face 'avy-lead-face "0.1.0")
(defface avy-background-face (defface avy-background-face
'((t (:foreground "gray40"))) '((t (:foreground "gray40")))
"Face for whole window background during selection.") "Face for whole window background during selection.")
;;* Internals ;;* Internals
(defun avi--goto (x) (defun avy--goto (x)
"Goto X. "Goto X.
X is (POS . WND) X is (POS . WND)
POS is either a position or (BEG . END)." POS is either a position or (BEG . END)."
@ -68,8 +75,9 @@ POS is either a position or (BEG . END)."
(setq pt (car pt))) (setq pt (car pt)))
(unless (= pt (point)) (push-mark)) (unless (= pt (point)) (push-mark))
(goto-char pt)))) (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'." "Select one of CANDIDATES using `avy-read'."
(unwind-protect (unwind-protect
(cl-case (length candidates) (cl-case (length candidates)
@ -79,17 +87,18 @@ POS is either a position or (BEG . END)."
(car candidates)) (car candidates))
(t (t
(avy--make-backgrounds (list (selected-window))) (avy--make-backgrounds (list (selected-window)))
(avy-read (avy-tree candidates avi-keys) (avy-read (avy-tree candidates avy-keys)
overlay-fn overlay-fn
#'avy--remove-leading-chars))) #'avy--remove-leading-chars)))
(avy--done))) (avy--done)))
(define-obsolete-function-alias 'avi--process 'avy--process "0.1.0")
(defvar avy--overlays-back nil (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) (defun avy--make-backgrounds (wnd-list)
"Create a dim background overlay for each window on WND-LIST." "Create a dim background overlay for each window on WND-LIST."
(when avi-background (when avy-background
(setq avy--overlays-back (setq avy--overlays-back
(mapcar (lambda (w) (mapcar (lambda (w)
(let ((ol (make-overlay (let ((ol (make-overlay
@ -106,16 +115,17 @@ POS is either a position or (BEG . END)."
(setq avy--overlays-back nil) (setq avy--overlays-back nil)
(avy--remove-leading-chars)) (avy--remove-leading-chars))
(defcustom avi-all-windows t (defcustom avy-all-windows t
"When non-nil, loop though all windows for candidates." "When non-nil, loop though all windows for candidates."
:type 'boolean) :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. "Return all elements that match REGEX in WND.
Each element of the list is ((BEG . END) . WND) Each element of the list is ((BEG . END) . WND)
When PRED is non-nil, it's a filter for matching point positions." When PRED is non-nil, it's a filter for matching point positions."
(let (candidates) (let (candidates)
(dolist (wnd (if avi-all-windows (dolist (wnd (if avy-all-windows
(window-list) (window-list)
(list (selected-window)))) (list (selected-window))))
(with-selected-window wnd (with-selected-window wnd
@ -131,8 +141,8 @@ When PRED is non-nil, it's a filter for matching point positions."
wnd) candidates)))))))) wnd) candidates))))))))
(nreverse candidates))) (nreverse candidates)))
(defvar avi--overlay-offset 0 (defvar avy--overlay-offset 0
"The offset to apply in `avi--overlay'.") "The offset to apply in `avy--overlay'.")
(defvar avy--overlays-lead nil (defvar avy--overlays-lead nil
"Hold overlays for leading chars.") "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) (mapc #'delete-overlay avy--overlays-lead)
(setq avy--overlays-lead nil)) (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." "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))) (ol (make-overlay pt (1+ pt) (window-buffer wnd)))
(old-str (with-selected-window wnd (old-str (with-selected-window wnd
(buffer-substring pt (1+ pt))))) (buffer-substring pt (1+ pt)))))
(when avi-background (when avy-background
(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 (concat str old-str)) (overlay-put ol 'display (concat str old-str))
(push ol avy--overlays-lead))) (push ol avy--overlays-lead)))
(defun avi--overlay-pre (path leaf) (defun avy--overlay-pre (path leaf)
"Create an overlay with STR at LEAF. "Create an overlay with STR at LEAF.
PATH is a list of keys from tree root to LEAF. PATH is a list of keys from tree root to LEAF.
LEAF is ((BEG . END) . WND)." LEAF is ((BEG . END) . WND)."
(avi--overlay (avy--overlay
(propertize (apply #'string (reverse path)) (propertize (apply #'string (reverse path))
'face 'avi-lead-face) 'face 'avy-lead-face)
(cond ((numberp leaf) (cond ((numberp leaf)
leaf) leaf)
((consp (car leaf)) ((consp (car leaf))
@ -171,14 +181,15 @@ LEAF is ((BEG . END) . WND)."
(if (consp leaf) (if (consp leaf)
(cdr leaf) (cdr leaf)
(selected-window)))) (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. "Create an overlay with STR at LEAF.
PATH is a list of keys from tree root to LEAF. PATH is a list of keys from tree root to LEAF.
LEAF is ((BEG . END) . WND)." LEAF is ((BEG . END) . WND)."
(let ((str (propertize (let ((str (propertize
(string (car (last path))) (string (car (last path)))
'face 'avi-lead-face)) 'face 'avy-lead-face))
(pt (if (consp (car leaf)) (pt (if (consp (car leaf))
(caar leaf) (caar leaf)
(car leaf))) (car leaf)))
@ -187,20 +198,21 @@ LEAF is ((BEG . END) . WND)."
(window-buffer wnd))) (window-buffer wnd)))
(old-str (with-selected-window wnd (old-str (with-selected-window wnd
(buffer-substring pt (1+ pt))))) (buffer-substring pt (1+ pt)))))
(when avi-background (when avy-background
(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 str)
(push ol avy--overlays-lead)))) (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. "Create an overlay with STR at LEAF.
PATH is a list of keys from tree root to LEAF. PATH is a list of keys from tree root to LEAF.
LEAF is ((BEG . END) . WND)." LEAF is ((BEG . END) . WND)."
(avi--overlay (avy--overlay
(propertize (apply #'string (reverse path)) (propertize (apply #'string (reverse path))
'face 'avi-lead-face) 'face 'avy-lead-face)
(cond ((numberp leaf) (cond ((numberp leaf)
leaf) leaf)
((consp (car leaf)) ((consp (car leaf))
@ -210,102 +222,109 @@ LEAF is ((BEG . END) . WND)."
(if (consp leaf) (if (consp leaf)
(cdr leaf) (cdr leaf)
(selected-window)))) (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. "Jump to REGEX.
When FLIP is non-nil, flip `avi-all-windows'." When FLIP is non-nil, flip `avy-all-windows'."
(let ((avi-all-windows (let ((avy-all-windows
(if flip (if flip
(not avi-all-windows) (not avy-all-windows)
avi-all-windows))) avy-all-windows)))
(avi--goto (avy--goto
(avi--process (avy--process
(avi--regex-candidates (avy--regex-candidates
regex) regex)
#'avi--overlay-post)))) #'avy--overlay-post))))
;;* Commands ;;* Commands
;;;###autoload ;;;###autoload
(defun avi-goto-char (&optional arg) (defun avy-goto-char (&optional arg)
"Read one char and jump to it. "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." When ARG is non-nil, flip the window scope."
(interactive "P") (interactive "P")
(avi--generic-jump (avy--generic-jump
(string (read-char "char: ")) arg)) (string (read-char "char: ")) arg))
(define-obsolete-function-alias 'avi-goto-char 'avy-goto-char "0.1.0")
;;;###autoload ;;;###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. "Read two chars and jump to them in current window.
When ARG is non-nil, flip the window scope." When ARG is non-nil, flip the window scope."
(interactive "P") (interactive "P")
(avi--generic-jump (avy--generic-jump
(string (string
(read-char "char 1: ") (read-char "char 1: ")
(read-char "char 2: ")) (read-char "char 2: "))
arg)) arg))
(define-obsolete-function-alias 'avi-goto-char-2 'avy-goto-char-2 "0.1.0")
;;;###autoload ;;;###autoload
(defun avi-isearch () (defun avy-isearch ()
"Jump to one of the current isearch candidates." "Jump to one of the current isearch candidates."
(interactive) (interactive)
(let* ((candidates (let* ((candidates
(avi--regex-candidates isearch-string)) (avy--regex-candidates isearch-string))
(avi-background nil) (avy-background nil)
(candidate (candidate
(avi--process candidates #'avi--overlay-post))) (avy--process candidates #'avy--overlay-post)))
(isearch-done) (isearch-done)
(avi--goto candidate))) (avy--goto candidate)))
(define-obsolete-function-alias 'avi-isearch 'avy-isearch "0.1.0")
;;;###autoload ;;;###autoload
(defun avi-goto-word-0 (arg) (defun avy-goto-word-0 (arg)
"Jump to a word start." "Jump to a word start."
(interactive "P") (interactive "P")
(let ((avi-keys (number-sequence ?a ?z))) (let ((avy-keys (number-sequence ?a ?z)))
(avi--generic-jump "\\b\\sw" arg))) (avy--generic-jump "\\b\\sw" arg)))
(define-obsolete-function-alias 'avi-goto-word-0 'avy-goto-word-0 "0.1.0")
;;;###autoload ;;;###autoload
(defun avi-goto-subword-0 (&optional arg) (defun avy-goto-subword-0 (&optional arg)
"Jump to a word or subword start." "Jump to a word or subword start."
(interactive "P") (interactive "P")
(let* ((avi-all-windows (let* ((avy-all-windows
(if arg (if arg
(not avi-all-windows) (not avy-all-windows)
avi-all-windows)) avy-all-windows))
(avi-keys (number-sequence ?a ?z)) (avy-keys (number-sequence ?a ?z))
(candidates (avi--regex-candidates (candidates (avy--regex-candidates
"\\(\\b\\sw\\)\\|\\(?:[^A-Z]\\([A-Z]\\)\\)"))) "\\(\\b\\sw\\)\\|\\(?:[^A-Z]\\([A-Z]\\)\\)")))
(dolist (x candidates) (dolist (x candidates)
(when (> (- (cdar x) (caar x)) 1) (when (> (- (cdar x) (caar x)) 1)
(cl-incf (caar x)))) (cl-incf (caar x))))
(avi--goto (avy--goto
(avi--process candidates #'avi--overlay-pre)))) (avy--process candidates #'avy--overlay-pre))))
(define-obsolete-function-alias 'avi-goto-subword-0 'avy-goto-subword-0 "0.1.0")
;;;###autoload ;;;###autoload
(defun avi-goto-word-1 () (defun avy-goto-word-1 ()
"Jump to a word start in current window. "Jump to a word start in current window.
Read one char with which the word should start." Read one char with which the word should start."
(interactive) (interactive)
(let* ((str (string (read-char "char: "))) (let* ((str (string (read-char "char: ")))
(candidates (avi--regex-candidates (candidates (avy--regex-candidates
(if (and avi-word-punc-regexp (if (and avy-word-punc-regexp
(string-match avi-word-punc-regexp str)) (string-match avy-word-punc-regexp str))
str str
(concat (concat
"\\b" "\\b"
str))))) str)))))
(avi--goto (avy--goto
(avi--process candidates #'avi--overlay-pre)))) (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." "Select line in current window."
(let ((avi-background nil) (let ((avy-background nil)
(avi-all-windows (avy-all-windows
(if arg (if arg
(not avi-all-windows) (not avy-all-windows)
avi-all-windows)) avy-all-windows))
candidates) candidates)
(dolist (wnd (if avi-all-windows (dolist (wnd (if avy-all-windows
(window-list) (window-list)
(list (selected-window)))) (list (selected-window))))
(with-selected-window wnd (with-selected-window wnd
@ -320,20 +339,21 @@ Read one char with which the word should start."
(push (cons (point) (selected-window)) (push (cons (point) (selected-window))
candidates)) candidates))
(forward-line 1))))))) (forward-line 1)))))))
(avi--process (nreverse candidates) #'avi--overlay-pre))) (avy--process (nreverse candidates) #'avy--overlay-pre)))
;;;###autoload ;;;###autoload
(defun avi-goto-line (&optional arg) (defun avy-goto-line (&optional arg)
"Jump to a line start in current buffer." "Jump to a line start in current buffer."
(interactive "P") (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 ;;;###autoload
(defun avi-copy-line (arg) (defun avy-copy-line (arg)
"Copy a selected line above the current line. "Copy a selected line above the current line.
ARG lines can be used." ARG lines can be used."
(interactive "p") (interactive "p")
(let ((start (car (avi--line)))) (let ((start (car (avy--line))))
(move-beginning-of-line nil) (move-beginning-of-line nil)
(save-excursion (save-excursion
(insert (insert
@ -344,13 +364,14 @@ ARG lines can be used."
(move-end-of-line arg) (move-end-of-line arg)
(point))) (point)))
"\n")))) "\n"))))
(define-obsolete-function-alias 'avi-copy-line 'avy-copy-line "0.1.0")
;;;###autoload ;;;###autoload
(defun avi-move-line (arg) (defun avy-move-line (arg)
"Move a selected line above the current line. "Move a selected line above the current line.
ARG lines can be used." ARG lines can be used."
(interactive "p") (interactive "p")
(let ((start (car (avi--line)))) (let ((start (car (avy--line))))
(move-beginning-of-line nil) (move-beginning-of-line nil)
(save-excursion (save-excursion
(save-excursion (save-excursion
@ -360,13 +381,14 @@ ARG lines can be used."
(insert (insert
(current-kill 0) (current-kill 0)
"\n")))) "\n"))))
(define-obsolete-function-alias 'avi-move-line 'avy-move-line "0.1.0")
;;;###autoload ;;;###autoload
(defun avi-copy-region () (defun avy-copy-region ()
"Select two lines and copy the text between them here." "Select two lines and copy the text between them here."
(interactive) (interactive)
(let ((beg (car (avi--line))) (let ((beg (car (avy--line)))
(end (car (avi--line))) (end (car (avy--line)))
(pad (if (bolp) "" "\n"))) (pad (if (bolp) "" "\n")))
(move-beginning-of-line nil) (move-beginning-of-line nil)
(save-excursion (save-excursion
@ -377,6 +399,7 @@ ARG lines can be used."
(goto-char end) (goto-char end)
(line-end-position))) (line-end-position)))
pad)))) pad))))
(define-obsolete-function-alias 'avi-copy-region 'avy-copy-region "0.1.0")
(provide 'avy-jump) (provide 'avy-jump)