[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 487d5ea 11/17: Abstract windows and rely on subword
From: |
Oleh Krehel |
Subject: |
[elpa] master 487d5ea 11/17: Abstract windows and rely on subword |
Date: |
Fri, 08 May 2015 13:42:12 +0000 |
branch: master
commit 487d5ea20152100cb3f9fa2c69347e348c764750
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Abstract windows and rely on subword
* avy-jump.el (avy-dowindows): New macro.
(avy--regex-candidates): Use `avy-dowindows'.
(avy-goto-subword-0): Rely on `subword-backward'.
(avy--line): Use `avy-dowindows'.
Fixes #4
---
avy-jump.el | 103 ++++++++++++++++++++++++++++++----------------------------
1 files changed, 53 insertions(+), 50 deletions(-)
diff --git a/avy-jump.el b/avy-jump.el
index 89b8423..126b02b 100644
--- a/avy-jump.el
+++ b/avy-jump.el
@@ -59,6 +59,23 @@
"Face for whole window background during selection.")
;;* Internals
+(defcustom avy-all-windows t
+ "When non-nil, loop though all windows for candidates."
+ :type 'boolean)
+
+(defmacro avy-dowindows (flip &rest body)
+ "Depending on FLIP and `avy-all-windows' run BODY in each or selected
window."
+ (declare (indent 1))
+ `(let ((avy-all-windows (if ,flip
+ (not avy-all-windows)
+ avy-all-windows)))
+ (dolist (wnd (if avy-all-windows
+ (window-list)
+ (list (selected-window))))
+ (with-selected-window wnd
+ (unless (memq major-mode '(image-mode doc-view-mode))
+ ,@body)))))
+
(defun avy--goto (x)
"Goto X.
X is (POS . WND)
@@ -109,30 +126,22 @@ POS is either a position or (BEG . END)."
(setq avy--overlays-back nil)
(avy--remove-leading-chars))
-(defcustom avy-all-windows t
- "When non-nil, loop though all windows for candidates."
- :type 'boolean)
-
(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 avy-all-windows
- (window-list)
- (list (selected-window))))
- (with-selected-window wnd
- (unless (memq major-mode '(image-mode doc-view-mode))
- (let ((we (or end (window-end (selected-window) t))))
- (save-excursion
- (goto-char (or beg (window-start)))
- (while (re-search-forward regex we t)
- (unless (get-char-property (point) 'invisible)
- (when (or (null pred)
- (funcall pred))
- (push (cons (cons (match-beginning 0)
- (match-end 0))
- wnd) candidates)))))))))
+ (avy-dowindows nil
+ (let ((we (or end (window-end (selected-window) t))))
+ (save-excursion
+ (goto-char (or beg (window-start)))
+ (while (re-search-forward regex we t)
+ (unless (get-char-property (point) 'invisible)
+ (when (or (null pred)
+ (funcall pred))
+ (push (cons (cons (match-beginning 0)
+ (match-end 0))
+ wnd) candidates)))))))
(nreverse candidates)))
(defvar avy--overlay-offset 0
@@ -308,49 +317,43 @@ The window scope is determined by `avy-all-windows' (ARG
negates it)."
str))))
(avy--generic-jump regex arg avy-goto-word-style)))
+(declare-function subword-backward "subword")
+
;;;###autoload
(defun avy-goto-subword-0 (&optional arg)
"Jump to a word or subword start.
The window scope is determined by `avy-all-windows' (ARG negates it)."
(interactive "P")
- (let* ((avy-all-windows
- (if arg
- (not avy-all-windows)
- avy-all-windows))
- (avy-keys (number-sequence ?a ?z))
- (case-fold-search nil)
- (candidates (avy--regex-candidates
- "\\(\\b\\sw\\)\\|\\(?:[^A-Z]\\([A-Z]\\)\\)")))
- (dolist (x candidates)
- (when (> (- (cdar x) (caar x)) 1)
- (cl-incf (caar x))))
+ (require 'subword)
+ (let ((avy-keys (number-sequence ?a ?z))
+ (case-fold-search nil)
+ candidates)
+ (avy-dowindows arg
+ (let ((ws (window-start)))
+ (save-excursion
+ (goto-char (window-end (selected-window) t))
+ (subword-backward)
+ (while (> (point) ws)
+ (push (cons (point) (selected-window)) candidates)
+ (subword-backward)))))
(avy--goto
(avy--process candidates (avy--style-fn avy-goto-word-style)))))
(defun avy--line (&optional arg)
"Select line in current window."
(let ((avy-background nil)
- (avy-all-windows
- (if arg
- (not avy-all-windows)
- avy-all-windows))
candidates)
- (dolist (wnd (if avy-all-windows
- (window-list)
- (list (selected-window))))
- (with-selected-window wnd
- (unless (memq major-mode '(image-mode doc-view-mode))
- (let ((ws (window-start)))
- (save-excursion
- (save-restriction
- (narrow-to-region ws (window-end (selected-window) t))
- (goto-char (point-min))
- (while (< (point) (point-max))
- (unless (get-char-property
- (max (1- (point)) ws) 'invisible)
- (push (cons (point) (selected-window))
- candidates))
- (forward-line 1))))))))
+ (avy-dowindows arg
+ (let ((ws (window-start)))
+ (save-excursion
+ (save-restriction
+ (narrow-to-region ws (window-end (selected-window) t))
+ (goto-char (point-min))
+ (while (< (point) (point-max))
+ (unless (get-char-property
+ (max (1- (point)) ws) 'invisible)
+ (push (cons (point) (selected-window)) candidates))
+ (forward-line 1))))))
(avy--process (nreverse candidates) #'avy--overlay-pre)))
;;;###autoload
- [elpa] master 1684e6a 03/17: Avoid image-mode and doc-view-mode, (continued)
- [elpa] master 1684e6a 03/17: Avoid image-mode and doc-view-mode, Oleh Krehel, 2015/05/08
- [elpa] master 1d184b0 05/17: Regexp-quote strings of avy-goto-char* functions., Oleh Krehel, 2015/05/08
- [elpa] master 33546b6 06/17: Fix avy-goto-subword-0, Oleh Krehel, 2015/05/08
- [elpa] master 5677270 04/17: Move obsoletes to one place, Oleh Krehel, 2015/05/08
- [elpa] master 18cf1ef 07/17: README.md: add, Oleh Krehel, 2015/05/08
- [elpa] master 6c1f2f6 02/17: Move from "avi-" to "avy-", leave old stuff obsolete, Oleh Krehel, 2015/05/08
- [elpa] master 974e55b 09/17: avy-jump.el (avy--line): Avoid image-mode and doc-view-mode, Oleh Krehel, 2015/05/08
- [elpa] master 5d2979b 01/17: Initial import, Oleh Krehel, 2015/05/08
- [elpa] master e9d2e60 08/17: Customize the leading char style for chars and words, Oleh Krehel, 2015/05/08
- [elpa] master 903e172 12/17: Special-case char RET to allow for jumping to end-of-lines., Oleh Krehel, 2015/05/08
- [elpa] master 487d5ea 11/17: Abstract windows and rely on subword,
Oleh Krehel <=
- [elpa] master ca1ca04 14/17: Add avy-goto-subword-1, Oleh Krehel, 2015/05/08
- [elpa] master e4f493e 10/17: README.md: Add command descriptions, Oleh Krehel, 2015/05/08
- [elpa] master 3200351 16/17: avy-jump.el (avy-setup-default): Setup some bindings, Oleh Krehel, 2015/05/08
- [elpa] master b2112e0 13/17: avy-jump.el (avy-goto-word-1): Fix for ".", Oleh Krehel, 2015/05/08
- [elpa] master f2290f2 15/17: avy.el: Update commentary, Oleh Krehel, 2015/05/08
- [elpa] master 876d210 17/17: Add 'packages/avy/' from commit '32003515c8efa2cf38b62c45499dae30bc7cacb8', Oleh Krehel, 2015/05/08