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)
(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 ()
(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
(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))
(ivy--occur-insert-lines
(mapcar
(lambda (cand) (concat "./" cand))
- cands))))
+ cands))
+ (goto-char (point-min))
+ (forward-line 4)))
(ivy-set-occur 'swiper 'swiper-occur)