]> code.delx.au - gnu-emacs-elpa/commitdiff
ivy.el (ivy-occur-revert-buffer): Move code to swiper-occur
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 4 Mar 2016 14:24:50 +0000 (15:24 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 4 Mar 2016 14:27:12 +0000 (15:27 +0100)
* ivy.el (ivy-occur-revert-buffer): Shouldn't know what's going on with
  `swiper'.

* swiper.el (swiper-occur): Now takes an optional arg. Also moves the
  point to the first cand.

TODO: The recovery of `ivy-text' is still hacky.

ivy.el
swiper.el

diff --git a/ivy.el b/ivy.el
index 96eeeb064a24bb4c8242e69892a78539d5dd77f5..5a19227948b320a89e60bf27e266ddff1c988dee 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -2704,33 +2704,6 @@ buffer would modify `ivy-last'.")
     map)
   "Keymap for Ivy Occur mode.")
 
-(defun ivy-occur-revert-buffer ()
-  "Refresh the buffer making it up-to date with the collection.
-
-Currently only works for `swiper'. In that specific case, the
-*ivy-occur* buffer becomes nearly useless as the orignal buffer
-is updated, since the line numbers no longer match.
-
-Calling this function is as if you called `ivy-occur' on the
-updated original buffer."
-  (interactive)
-  (let ((caller (ivy-state-caller ivy-occur-last))
-        (text (progn (string-match "\"\\(.*\\)\"" (buffer-name))
-                     (match-string 1 (buffer-name))))
-        (ivy-last ivy-occur-last))
-    (when (eq caller 'swiper)
-      (let ((buffer (ivy-state-buffer ivy-occur-last)))
-        (unless (buffer-live-p buffer)
-          (error "buffer was killed"))
-        (with-current-buffer buffer
-          (setq ivy--old-re nil)
-          (setq ivy--old-cands (ivy--filter text (swiper--candidates))))
-        (let ((inhibit-read-only t))
-          (erase-buffer)
-          (swiper-occur)
-          (goto-char (point-min))
-          (forward-line 4))))))
-
 (defun ivy-occur-toggle-calling ()
   "Toggle `ivy-calling'."
   (interactive)
@@ -2829,6 +2802,26 @@ There is no limit on the number of *ivy-occur* buffers."
       (ivy-exit-with-action
        `(lambda (_) (pop-to-buffer ,buffer))))))
 
+(defun ivy-occur-revert-buffer ()
+  "Refresh the buffer making it up-to date with the collection.
+
+Currently only works for `swiper'. In that specific case, the
+*ivy-occur* buffer becomes nearly useless as the orignal buffer
+is updated, since the line numbers no longer match.
+
+Calling this function is as if you called `ivy-occur' on the
+updated original buffer."
+  (interactive)
+  (let ((caller (ivy-state-caller ivy-occur-last))
+        (ivy-last ivy-occur-last))
+    (when (eq caller 'swiper)
+      (let ((buffer (ivy-state-buffer ivy-occur-last)))
+        (unless (buffer-live-p buffer)
+          (error "buffer was killed"))
+        (let ((inhibit-read-only t))
+          (erase-buffer)
+          (funcall (plist-get ivy--occurs-list caller) t))))))
+
 (declare-function wgrep-change-to-wgrep-mode "ext:wgrep")
 
 (defun ivy-wgrep-change-to-wgrep-mode ()
index bdf38197f3e418a764e89624949ed3acbc175fcb..a2c325554e0abb20f7cd924e0598e20c8afe7184 100644 (file)
--- a/swiper.el
+++ b/swiper.el
@@ -316,13 +316,13 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
 
 (declare-function string-trim-right "subr-x")
 
-(defun swiper-occur ()
+(defun swiper-occur (&optional revert)
   "Generate a custom occur buffer for `swiper'."
-  (let* ((fname (propertize
+  (let* ((buffer (ivy-state-buffer ivy-last))
+         (fname (propertize
                  (with-ivy-window
                    (file-name-nondirectory
-                    (buffer-file-name
-                     (ivy-state-buffer ivy-last))))
+                    (buffer-file-name buffer)))
                  'face
                  'compilation-info))
          (cands (mapcar
@@ -334,7 +334,14 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
                              (get-text-property 0 'display s))
                             'face 'compilation-line-number)
                            (substring s 1)))
-                 ivy--old-cands)))
+                 (if (null revert)
+                     ivy--old-cands
+                   (setq ivy--old-re nil)
+                   (ivy--filter
+                    (progn (string-match "\"\\(.*\\)\"" (buffer-name))
+                           (match-string 1 (buffer-name)))
+                    (with-current-buffer buffer
+                      (swiper--candidates)))))))
     (unless (eq major-mode 'ivy-occur-grep-mode)
       (ivy-occur-grep-mode)
       (font-lock-mode -1))
@@ -344,7 +351,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
     (ivy--occur-insert-lines
      (mapcar
       (lambda (cand) (concat "./" cand))
-      cands))))
+      cands))
+    (goto-char (point-min))
+    (forward-line 4)))
 
 (ivy-set-occur 'swiper 'swiper-occur)