branch: master commit ee27e27a156f9d0c9c2e328f27d6fcce042cfe09 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
ivy.el (ivy-occur-revert-buffer): Move code to swiper-occur * 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 | 47 ++++++++++++++++++++--------------------------- swiper.el | 21 +++++++++++++++------ 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/ivy.el b/ivy.el index 96eeeb0..5a19227 100644 --- 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 () diff --git a/swiper.el b/swiper.el index bdf3819..a2c3255 100644 --- 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)