[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 70bd6ce 36/78: Search only in the visible region
From: |
Oleh Krehel |
Subject: |
[elpa] master 70bd6ce 36/78: Search only in the visible region |
Date: |
Sat, 23 Jan 2016 13:59:55 +0000 |
branch: master
commit 70bd6cec70f280b67f47f6f94e897f0ec8805873
Author: Yasushi SHOJI <address@hidden>
Commit: Oleh Krehel <address@hidden>
Search only in the visible region
The current version of `avy--regex-candidates` first searches for the
given regex then skip the match if it's invisible. This works fine with
less than a few thousand lines of buffer, however, it takes quit time if
your have tens of thousand lines hidden, say, in org file.
This patch reverse the strategy. Find all visible regions in given the
window first, then map the original search function to that list. This
change reduced candidates search time from 10 or more seconds to instant
on my 100,000+ lines of org file.
It might be possible to have hundreds of visibility-interleaved regions
in a huge window on the 4K or 8K monitor in near the future, but this
reversed strategy should be fast enough for those system.
This fixes #108.
Fixes #109
---
avy.el | 51 +++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/avy.el b/avy.el
index a030468..e0e9359 100644
--- a/avy.el
+++ b/avy.el
@@ -546,6 +546,33 @@ Use OVERLAY-FN to visualize the decision overlay."
(setq avy--overlays-back nil)
(avy--remove-leading-chars))
+(defun avy--next-visible-point ()
+ "Return the next closest point without 'invisible property."
+ (let ((s (point)))
+ (while (and (not (= (point-max) (setq s (next-overlay-change s))))
+ (get-char-property s 'invisible)))
+ s))
+
+(defun avy--next-invisible-point ()
+ "Return the next closest point with 'invisible property."
+ (let ((s (point)))
+ (while (and (not (= (point-max) (setq s (next-overlay-change s))))
+ (not (get-char-property s 'invisible))))
+ s))
+
+(defun avy--find-visible-regions (rbeg rend)
+ "Return a list of all visible regions between RBEG and REND."
+ (let (visibles beg)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region rbeg rend)
+ (setq beg (goto-char (point-min)))
+ (while (not (= (point) (point-max)))
+ (goto-char (avy--next-invisible-point))
+ (push (cons beg (point)) visibles)
+ (setq beg (goto-char (avy--next-visible-point))))
+ (nreverse visibles)))))
+
(defun avy--regex-candidates (regex &optional beg end pred group)
"Return all elements that match REGEX.
Each element of the list is ((BEG . END) . WND)
@@ -556,16 +583,20 @@ When GROUP is non-nil, (BEG . END) should delimit that
regex group."
(not (string= regex (upcase regex)))))
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 group)
- (match-end group))
- wnd) candidates)))))))
+ (dolist (pair (avy--find-visible-regions
+ (or beg (window-start))
+ (or end (window-end (selected-window) t))))
+ (let ((beg (car pair))
+ (end (cdr pair)))
+ (save-excursion
+ (goto-char beg)
+ (while (re-search-forward regex end t)
+ (unless (get-char-property (point) 'invisible)
+ (when (or (null pred)
+ (funcall pred))
+ (push (cons (cons (match-beginning group)
+ (match-end group))
+ wnd) candidates))))))))
(nreverse candidates)))
(defvar avy--overlay-offset 0
- [elpa] master ac16227 27/78: Add padding for wide-width character, (continued)
- [elpa] master ac16227 27/78: Add padding for wide-width character, Oleh Krehel, 2016/01/23
- [elpa] master 67662ef 29/78: Fix indentation of defface, Oleh Krehel, 2016/01/23
- [elpa] master f9d7a76 31/78: Improve avy-goto-char-timer., Oleh Krehel, 2016/01/23
- [elpa] master 3f53a2a 30/78: avy.el (avy-goto-line): Fix off-by-one, Oleh Krehel, 2016/01/23
- [elpa] master acdd9e8 33/78: Modify avy--read-string-timer, Oleh Krehel, 2016/01/23
- [elpa] master 22b4ff0 32/78: Define new face avy-goto-char-timer-face for the highlights, Oleh Krehel, 2016/01/23
- [elpa] master bda04b2 35/78: Properly highlight depending on avy-all-windows, Oleh Krehel, 2016/01/23
- [elpa] master c879498 38/78: New commands avy-goto-line-above and avy-goto-line-below, Oleh Krehel, 2016/01/23
- [elpa] master 248bff0 37/78: avy.el (avy--regex-candidates): Simplify, Oleh Krehel, 2016/01/23
- [elpa] master d439b9d 34/78: avy.el (avy--overlay-at-full): Avoid negative length, Oleh Krehel, 2016/01/23
- [elpa] master 70bd6ce 36/78: Search only in the visible region,
Oleh Krehel <=
- [elpa] master f7ddd4b 39/78: Fix jumping to the last char of a folded Org outline, Oleh Krehel, 2016/01/23
- [elpa] master 528125e 40/78: avy.el (avy--process): Add window to candidates if not present, Oleh Krehel, 2016/01/23
- [elpa] master df181f1 44/78: avy.el (avy--read-candidates): Use avy-window-list, Oleh Krehel, 2016/01/23
- [elpa] master 964664c 45/78: Fix jumping to the last char of a folded Org outline, Oleh Krehel, 2016/01/23
- [elpa] master 0a18a45 43/78: avy.el (avy--read-candidates): Fix reverse order, Oleh Krehel, 2016/01/23
- [elpa] master 513c429 41/78: Make avy-goto-char-timer faster for org-mode, Oleh Krehel, 2016/01/23
- [elpa] master f28d238 46/78: Fix for combined org-indent-mode and visual-line-mode, Oleh Krehel, 2016/01/23
- [elpa] master 2313410 42/78: Optimize avy-goto-char-timer, Oleh Krehel, 2016/01/23
- [elpa] master 0166808 47/78: Beep when there are no matches, Oleh Krehel, 2016/01/23
- [elpa] master 2d07a49 50/78: Make avy--overlay-at use avy--overlay, Oleh Krehel, 2016/01/23