[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 0d2ab52 157/399: swiper.el (swiper--isearch-occur-cands):
From: |
Oleh Krehel |
Subject: |
[elpa] master 0d2ab52 157/399: swiper.el (swiper--isearch-occur-cands): Faster version |
Date: |
Sat, 20 Jul 2019 14:57:14 -0400 (EDT) |
branch: master
commit 0d2ab52f8b6ba684ea7c26fa89f97d01813b8bb7
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper--isearch-occur-cands): Faster version
Don't use `line-number-at-pos', since it's O(N*2) in terms of the
number of candidates. Instead, use `count-lines' between each
consecutive candidate which is O(N).
---
swiper.el | 51 +++++++++++++++++++++++++++++++--------------------
1 file changed, 31 insertions(+), 20 deletions(-)
diff --git a/swiper.el b/swiper.el
index d688907..bb41cf5 100644
--- a/swiper.el
+++ b/swiper.el
@@ -480,26 +480,37 @@ such as `scroll-conservatively' are set to a high value.")
(nreverse res)))
(defun swiper--occur-cands (fname cands)
- (with-current-buffer (ivy-state-buffer ivy-last)
- (let* ((pt-min (point-min))
- (line-delta
- (save-restriction
- (widen)
- (1- (line-number-at-pos pt-min)))))
- (mapcar
- (lambda (s)
- (let* ((n (get-text-property 0 'swiper-line-number s))
- (pt (get-text-property 0 'point s))
- (nn (number-to-string
- (if n
- (progn
- (setq s (substring s 1))
- (+ (read n) line-delta))
- (line-number-at-pos pt)))))
- (put-text-property 0 1 'point pt fname)
- (put-text-property 0 (length nn) 'face 'ivy-grep-line-number nn)
- (format "%s:%s:%s" fname nn s)))
- cands))))
+ (when cands
+ (with-current-buffer (ivy-state-buffer ivy-last)
+ (if (eq (ivy-state-caller ivy-last) 'swiper-isearch)
+ (swiper--isearch-occur-cands fname cands)
+ (let* ((pt-min (point-min))
+ (line-delta
+ (save-restriction
+ (widen)
+ (1- (line-number-at-pos pt-min)))))
+ (mapcar
+ (lambda (s)
+ (let* ((n (get-text-property 0 'swiper-line-number s))
+ (nn (number-to-string
+ (+ (read n) line-delta))))
+ (put-text-property 0 (length nn) 'face 'ivy-grep-line-number nn)
+ (format "%s:%s:%s" fname nn (substring s 1))))
+ cands))))))
+
+(defun swiper--isearch-occur-cands (fname cands)
+ (let* ((last-pt (get-text-property 0 'point (car cands)))
+ (line (1+ (line-number-at-pos last-pt)))
+ res pt nn)
+ (dolist (cand cands)
+ (setq pt (get-text-property 0 'point cand))
+ (cl-incf line (1- (count-lines last-pt pt)))
+ (setq nn (number-to-string line))
+ (put-text-property 0 (length nn) 'face 'ivy-grep-line-number nn)
+ (put-text-property 0 1 'point pt fname)
+ (push (format "%s:%s:%s" fname nn cand) res)
+ (setq last-pt pt))
+ (nreverse res)))
(defun swiper-occur (&optional revert)
"Generate a custom occur buffer for `swiper'.
- [elpa] master eaba38a 145/399: counsel.el (counsel-dired-jump-args): Fix for OSX, (continued)
- [elpa] master eaba38a 145/399: counsel.el (counsel-dired-jump-args): Fix for OSX, Oleh Krehel, 2019/07/20
- [elpa] master 7c9d960 143/399: swiper.el (swiper--add-cursor-overlay): Extract, Oleh Krehel, 2019/07/20
- [elpa] master 9988904 150/399: counsel.el (counsel--switch-buffer-update-fn): Fix for when find-file fails, Oleh Krehel, 2019/07/20
- [elpa] master 05a4e59 147/399: Do not use invalid :preselect as a regexp, Oleh Krehel, 2019/07/20
- [elpa] master 3ab3d5f 152/399: swiper.el (swiper-isearch): Check executing-kbd-macro, Oleh Krehel, 2019/07/20
- [elpa] master 302d23f 149/399: counsel.el: Fix org-version testing, Oleh Krehel, 2019/07/20
- [elpa] master cd41f70 153/399: ivy-test.el: Add inhibit-message, Oleh Krehel, 2019/07/20
- [elpa] master 1df4ccf 154/399: ivy.el (ivy-occur-revert-buffer): Add swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master 4f1bbc1 151/399: swiper.el (swiper-isearch-function): Full point history for DEL, Oleh Krehel, 2019/07/20
- [elpa] master 0bf94f8 156/399: ivy.el (ivy--occur-press-update-window): Add swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master 0d2ab52 157/399: swiper.el (swiper--isearch-occur-cands): Faster version,
Oleh Krehel <=
- [elpa] master 1bf56c3 165/399: swiper.el (swiper--query-replace-setup): Fix for ivy--regex-ignore-order, Oleh Krehel, 2019/07/20
- [elpa] master 4492054 167/399: ivy.el (ivy--recompute-index): Speed up, Oleh Krehel, 2019/07/20
- [elpa] master 11b0007 158/399: swiper.el (swiper--action): Simplify, Oleh Krehel, 2019/07/20
- [elpa] master 1ebbb5f 136/399: swiper.el (swiper-isearch): Set swiper-min-highlight to 1, Oleh Krehel, 2019/07/20
- [elpa] master b34bf45 140/399: counsel.el (counsel-dired): Add, Oleh Krehel, 2019/07/20
- [elpa] master 1e38ed4 146/399: counsel.el (counsel-minor): Add command to toggle minor mode, Oleh Krehel, 2019/07/20
- [elpa] master 2098d27 148/399: swiper.el: Set up occur for swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master dceecd8 155/399: swiper.el (swiper-occur): Adapt to swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master f38bb51 161/399: ivy.el (ivy--prompt-selectable-p): Allow to select "", Oleh Krehel, 2019/07/20
- [elpa] master 1b13ee8 162/399: ivy.el (ivy--use-selectable-prompt): Cache ivy--prompt-selected-p, Oleh Krehel, 2019/07/20