[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4c52362 110/399: swiper.el (swiper-occur): Make wgrep work
From: |
Oleh Krehel |
Subject: |
[elpa] master 4c52362 110/399: swiper.el (swiper-occur): Make wgrep work for narrowed buffers |
Date: |
Sat, 20 Jul 2019 14:56:59 -0400 (EDT) |
branch: master
commit 4c5236284215104b7f4ec106c91145169f6ae648
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el (swiper-occur): Make wgrep work for narrowed buffers
* swiper.el (swiper--occur-cands): Extract and add `line-delta' logic.
(swiper-occur): Update.
(swiper--action): Use `swiper--point-min' only when the buffer is narrowed.
Fixes #1848
---
ivy.el | 12 +++++++-----
swiper.el | 29 +++++++++++++++++++++--------
2 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/ivy.el b/ivy.el
index 1d413b1..d0b4d89 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4493,11 +4493,13 @@ EVENT gives the mouse position."
(with-ivy-window
(setq counsel-grep-last-line nil)
(with-current-buffer (ivy--occur-press-buffer)
- (funcall action
- (if (and (consp coll)
- (consp (car coll)))
- (assoc str coll)
- str)))
+ (save-restriction
+ (widen)
+ (funcall action
+ (if (and (consp coll)
+ (consp (car coll)))
+ (assoc str coll)
+ str))))
(if (memq (ivy-state-caller ivy-last)
'(swiper counsel-git-grep counsel-grep counsel-ag
counsel-rg))
(with-current-buffer (window-buffer (selected-window))
diff --git a/swiper.el b/swiper.el
index 15c40d9..be27efa 100644
--- a/swiper.el
+++ b/swiper.el
@@ -455,6 +455,21 @@ such as `scroll-conservatively' are set to a high value.")
res)))
(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))
+ (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-occur (&optional revert)
"Generate a custom occur buffer for `swiper'.
When REVERT is non-nil, regenerate the current *ivy-occur* buffer.
@@ -472,13 +487,8 @@ When capture groups are present in the input, print them
instead of lines."
(match-string 1 (buffer-name))))
(re (mapconcat #'identity (ivy--split re) ".*?"))
(cands
- (mapcar
- (lambda (s)
- (let* ((n (get-text-property 0 'swiper-line-number s))
- (i (string-match-p "[ \t\n\r]+\\'" n)))
- (when i (setq n (substring n 0 i)))
- (put-text-property 0 (length n) 'face 'ivy-grep-line-number n)
- (format "%s:%s:%s" fname n (substring s 1))))
+ (swiper--occur-cands
+ fname
(if (not revert)
ivy--old-cands
(setq ivy--old-re nil)
@@ -822,7 +832,10 @@ the face, window and priority of the overlay."
(unless (equal (current-buffer)
(ivy-state-buffer ivy-last))
(switch-to-buffer (ivy-state-buffer ivy-last)))
- (goto-char swiper--point-min)
+ (goto-char
+ (if (buffer-narrowed-p)
+ swiper--point-min
+ (point-min)))
(funcall (if swiper-use-visual-line
#'line-move
#'forward-line)
- [elpa] master adab07d 101/399: counsel.el: Simplify counsel-git-grep, (continued)
- [elpa] master adab07d 101/399: counsel.el: Simplify counsel-git-grep, Oleh Krehel, 2019/07/20
- [elpa] master 5b4dbbc 096/399: ivy.el: Silence byte-compiler, Oleh Krehel, 2019/07/20
- [elpa] master 3954bfe 081/399: counsel.el (counsel-compile): Don't modify compilation-start-hook permanently, Oleh Krehel, 2019/07/20
- [elpa] master d92d43a 085/399: counsel.el (counsel-compile-root-functions): Tidy, Oleh Krehel, 2019/07/20
- [elpa] master 2356a1d 091/399: ivy-test.el (counsel--grep-regex): Extend test, Oleh Krehel, 2019/07/20
- [elpa] master cdd7ada 094/399: counsel.el (counsel-url-expand): Avoid null error, Oleh Krehel, 2019/07/20
- [elpa] master 089107a 099/399: counsel.el (counsel-ag): Add a keyword argument caller, Oleh Krehel, 2019/07/20
- [elpa] master 776fbb7 103/399: Make ivy-switch-buffer-occur work with multi-pass regex builders, Oleh Krehel, 2019/07/20
- [elpa] master 8b4c939 100/399: counsel.el (counsel-cd): Add, Oleh Krehel, 2019/07/20
- [elpa] master 0c8cfe8 106/399: ivy-hydra.el (ivy-dispatching-done-idle): Add, Oleh Krehel, 2019/07/20
- [elpa] master 4c52362 110/399: swiper.el (swiper-occur): Make wgrep work for narrowed buffers,
Oleh Krehel <=
- [elpa] master 8c1a2fa 107/399: Allow all re-builders to use ivy-highlight-grep-commands, Oleh Krehel, 2019/07/20
- [elpa] master 78b62f2 102/399: README.md: Mention char-fold-to-regexp, Oleh Krehel, 2019/07/20
- [elpa] master a601e40 104/399: counsel.el (counsel-org-goto-all): Use org-mode outline settings, Oleh Krehel, 2019/07/20
- [elpa] master 468e914 109/399: counsel.el (counsel--file-name-filter): Clean up style, Oleh Krehel, 2019/07/20
- [elpa] master 6373a48 105/399: counsel.el: Fix compiler warning, Oleh Krehel, 2019/07/20
- [elpa] master 164fecb 108/399: Make find-file-occur work with multi-pass regex builders, Oleh Krehel, 2019/07/20
- [elpa] master 3b677d4 113/399: counsel.el (counsel-file-jump-args): Fix dotfiles not being shown, Oleh Krehel, 2019/07/20
- [elpa] master ffa2d8f 112/399: counsel.el (counsel-unicode-char): Fix sorting, Oleh Krehel, 2019/07/20
- [elpa] master 18d7f84 117/399: counsel.el (counsel-yank-pop-action): Also works for strings, Oleh Krehel, 2019/07/20
- [elpa] master c56ad2a 114/399: ivy-hydra.el (ivy-dispatching-done-hydra): Improve, Oleh Krehel, 2019/07/20