emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]