[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d7cafcb 56/68: avy-jump.el: add example commands using avy
From: |
Oleh Krehel |
Subject: |
[elpa] master d7cafcb 56/68: avy-jump.el: add example commands using avy |
Date: |
Sat, 21 Mar 2015 19:07:07 +0000 |
branch: master
commit d7cafcb9643fc5b1d98bb231a4de9123c856ef8a
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
avy-jump.el: add example commands using avy
---
avy-jump.el | 153 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 153 insertions(+), 0 deletions(-)
diff --git a/avy-jump.el b/avy-jump.el
new file mode 100644
index 0000000..ee1cb35
--- /dev/null
+++ b/avy-jump.el
@@ -0,0 +1,153 @@
+;;; avy-jump.el --- jump to things tree-style
+
+;; Author: Oleh Krehel <address@hidden>
+;; Version: 0.1.0
+;; Keywords: point
+
+;; This file is not part of GNU Emacs
+
+;; This file is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; For a full copy of the GNU General Public License
+;; see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; This package offers various commands for navigating to things using `avy',
such as
+;; `avy-jump-char', `avy-double-char', and `avy-jump-line'.
+
+;;; Code:
+(require 'avy)
+(require 'ace-window)
+
+(defgroup avy-jump nil
+ "Jump to things tree-style."
+ :group 'convenience
+ :prefix "avy-")
+
+(defcustom avy-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)
+ "Keys for jumping.")
+
+(defun avy--goto (x)
+ "Goto X.
+X is (POSITION . WINDOW)."
+ (select-window (cdr x))
+ (goto-char (car x)))
+
+(defun avy--process (candidates action &optional nobackground)
+ "Select one of CANDIDATES using `avy-read'.
+Call ACTION on that candidate."
+ (unwind-protect
+ (let ((aw-background (not nobackground)))
+ (aw--make-backgrounds (list (selected-window)))
+ (cl-case (length candidates)
+ (0
+ (message "zero candidates"))
+ (1
+ (funcall action (car candidates)))
+ (t
+ (funcall
+ action
+ (avy-read (avy-tree candidates avy-keys)
+ #'aw--lead-overlay
+ #'aw--remove-leading-chars)))))
+ (aw--done)))
+
+(defun avy--regex-candidates (regex &optional wnd)
+ "Return all elements that match REGEX in WND.
+Each element of the list is (POSITION . WND)."
+ (let ((we (window-end))
+ candidates)
+ (setq wnd (or wnd (selected-window)))
+ (save-window-excursion
+ (select-window wnd)
+ (save-excursion
+ (goto-char (window-start))
+ (while (re-search-forward regex we t)
+ (push (cons (1- (point)) wnd) candidates)))
+ (nreverse candidates))))
+
+(defun avy-jump-char ()
+ "Read one char and jump to it in current window."
+ (interactive)
+ (avy--process (avy--regex-candidates
+ (string (read-char "char: "))
+ (selected-window))
+ #'avy--goto))
+
+(defun avy-jump-double-char ()
+ "Read two chars and jump to them in current window."
+ (interactive)
+ (avy--process (avy--regex-candidates
+ (string
+ (read-char "char 1: ")
+ (read-char "char 2: "))
+ (selected-window))
+ #'avy--goto))
+
+(defun avy-jump-isearch ()
+ "Jump to one of the current isearch candidates."
+ (interactive)
+ (let ((candidates
+ (mapcar (lambda (x) (cons (1+ (car x))
+ (cdr x)))
+ (avy--regex-candidates isearch-string))))
+ (avy--process candidates #'avy--goto t)
+ (isearch-done)))
+
+(defun avy-jump-zero-word ()
+ "Jump to a word start in current buffer"
+ (interactive)
+ (let ((we (window-end))
+ candidates)
+ (save-excursion
+ (goto-char (window-start))
+ (while (< (point) we)
+ (forward-word 2)
+ (forward-word -1)
+ (push (cons (point) (selected-window))
+ candidates)))
+ (avy--process (nreverse candidates)
+ #'avy--goto)))
+
+(defun avy-jump-one-word ()
+ "Jump to a word start in current buffer.
+Read one char with which the word should start."
+ (interactive)
+ (let ((candidates (avy--regex-candidates
+ (string (read-char "char: "))
+ (selected-window))))
+ (save-excursion
+ (setq candidates (cl-remove-if-not
+ (lambda (x)
+ (goto-char (car x))
+ (looking-at "\\b"))
+ (nreverse candidates))))
+ (avy--process candidates #'avy--goto)))
+
+(defun avy-jump-line ()
+ "Jump to a line start in current buffer."
+ (interactive)
+ (let ((we (window-end))
+ candidates)
+ (save-excursion
+ (goto-char (window-start))
+ (while (< (point) we)
+ (push (cons (point) (selected-window))
+ candidates)
+ (forward-line 1)))
+ (avy--process (nreverse candidates)
+ #'avy--goto
+ t)))
+
+(provide 'avy-jump)
+
+;;; avy-jump.el ends here
- [elpa] master 064c4fb 49/68: ace-window.el (aw-select): Rename from `aw--doit', (continued)
- [elpa] master 064c4fb 49/68: ace-window.el (aw-select): Rename from `aw--doit', Oleh Krehel, 2015/03/21
- [elpa] master b351b51 48/68: Clean up code, Oleh Krehel, 2015/03/21
- [elpa] master 4570578 46/68: ace-window.el (aw--doit): simplify, Oleh Krehel, 2015/03/21
- [elpa] master df86665 51/68: ace-window.el (aw-ignored-buffers): add "*LV*", Oleh Krehel, 2015/03/21
- [elpa] master fa7cb4d 47/68: `aw--doit' simply returns a window now, Oleh Krehel, 2015/03/21
- [elpa] master e1ae6ba 50/68: Try not to end in `aw-ignored-p' when ace method isn't invoked, Oleh Krehel, 2015/03/21
- [elpa] master 47bd115 52/68: Allow customizing the leading char face, Oleh Krehel, 2015/03/21
- [elpa] master c897759 55/68: Update avy interface, Oleh Krehel, 2015/03/21
- [elpa] master 574b3bd 57/68: Add `aw-leading-char-style' extra-awesome custom var, Oleh Krehel, 2015/03/21
- [elpa] master 8b5f10a 53/68: Update outlines, Oleh Krehel, 2015/03/21
- [elpa] master d7cafcb 56/68: avy-jump.el: add example commands using avy,
Oleh Krehel <=
- [elpa] master fcc64ab 59/68: avy-jump.el (avi--regex-candidates): Add optional bounds, Oleh Krehel, 2015/03/21
- [elpa] master d932090 60/68: avy-jump.el (avi--overlay): Fix bug, Oleh Krehel, 2015/03/21
- [elpa] master f0050fb 62/68: avy.el (avy-read): Give a more precise error, Oleh Krehel, 2015/03/21
- [elpa] master 4e5ca87 58/68: avy-jump.el: Major update, Oleh Krehel, 2015/03/21
- [elpa] master ee0fa60 64/68: Add show keys on mode line feature., Oleh Krehel, 2015/03/21
- [elpa] master 30abc92 61/68: avy-jump.el (avi-goto-word-0): Simplify, Oleh Krehel, 2015/03/21
- [elpa] master a3d4817 63/68: Allow switching to the previous window, Oleh Krehel, 2015/03/21
- [elpa] master b83b941 65/68: Add `ace-window-display-mode' minor mode, Oleh Krehel, 2015/03/21
- [elpa] master d81f079 54/68: Remove dependency on ace-jump-mode, Oleh Krehel, 2015/03/21
- [elpa] master 2580bf9 67/68: ace-window.el (aw-mode-line-face): Inherit from mode-line-buffer-id, Oleh Krehel, 2015/03/21