[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 11b0007 158/399: swiper.el (swiper--action): Simplify
From: |
Oleh Krehel |
Subject: |
[elpa] master 11b0007 158/399: swiper.el (swiper--action): Simplify |
Date: |
Sat, 20 Jul 2019 14:57:14 -0400 (EDT) |
branch: master
commit 11b00073cb348aedf1d648a991bab71e20178268
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper--action): Simplify
* ivy.el (ivy-occur-press): Pass the same string to the action
function as `ivy-done' would. This means if
e.g. `swiper--occur-cands' adds something to each candidate, it has
to put into the 'offset property how much it added.
---
ivy.el | 3 ++-
swiper.el | 52 +++++++++++++++++++++++++++-------------------------
2 files changed, 29 insertions(+), 26 deletions(-)
diff --git a/ivy.el b/ivy.el
index 862f660..07d271b 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4491,6 +4491,7 @@ EVENT gives the mouse position."
(str (buffer-substring
(match-beginning 1)
(match-end 1)))
+ (offset (or (get-text-property 0 'offset str) 0))
(coll (ivy-state-collection ivy-last))
(action (ivy--get-action ivy-last))
(ivy-exit 'done))
@@ -4503,7 +4504,7 @@ EVENT gives the mouse position."
(if (and (consp coll)
(consp (car coll)))
(assoc str coll)
- str))))
+ (substring str offset)))))
(if (memq (ivy-state-caller ivy-last)
'(swiper swiper-isearch
counsel-git-grep counsel-grep counsel-ag counsel-rg))
diff --git a/swiper.el b/swiper.el
index bb41cf5..ad29724 100644
--- a/swiper.el
+++ b/swiper.el
@@ -482,33 +482,37 @@ such as `scroll-conservatively' are set to a high value.")
(defun swiper--occur-cands (fname 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* ((pt-min (point-min))
+ (line-delta
+ (save-restriction
+ (widen)
+ (1- (line-number-at-pos pt-min))))
+ (lines
+ (if (eq (ivy-state-caller ivy-last) 'swiper-isearch)
+ (swiper--isearch-occur-cands cands)
+ (mapcar (lambda (s)
+ (let ((l (get-text-property 0 'swiper-line-number
s)))
+ (setq s (substring s 1))
+ (put-text-property 0 1 'swiper-line-number l s)
+ (cons (read l) s)))
+ cands)))
+ (offset (+ (length fname) 2)))
+ (mapcar (lambda (x)
+ (let ((nn (number-to-string
+ (+ (car x) line-delta))))
+ (put-text-property 0 (length nn) 'face
'ivy-grep-line-number nn)
+ (put-text-property 0 1 'offset (+ offset (length nn))
fname)
+ (format "%s:%s:%s" fname nn (cdr x))))
+ lines)))))
+
+(defun swiper--isearch-occur-cands (cands)
(let* ((last-pt (get-text-property 0 'point (car cands)))
(line (1+ (line-number-at-pos last-pt)))
- res pt nn)
+ res pt)
(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)
+ (push (cons line cand) res)
(setq last-pt pt))
(nreverse res)))
@@ -867,9 +871,7 @@ the face, window and priority of the overlay."
(defun swiper--action (x)
"Goto line X."
- (let ((ln (1- (read (or (get-text-property 0 'swiper-line-number x)
- (and (string-match ":\\([0-9]+\\):.*\\'" x)
- (match-string-no-properties 1 x))))))
+ (let ((ln (1- (read (get-text-property 0 'swiper-line-number x))))
(re (ivy--regex ivy-text)))
(if (null x)
(user-error "No candidates")
- [elpa] master 05a4e59 147/399: Do not use invalid :preselect as a regexp, (continued)
- [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, 2019/07/20
- [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 <=
- [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
- [elpa] master 92ec03c 163/399: ivy-test.el (ivy-use-selectable-prompt): Add tests, Oleh Krehel, 2019/07/20
- [elpa] master b2693d1 160/399: counsel.el (counsel-locate-db-path): New defcustom, Oleh Krehel, 2019/07/20
- [elpa] master 44ea8b5 166/399: counsel.el (counsel-git-grep-cmd-function): Add, Oleh Krehel, 2019/07/20