(define-key map (kbd "k") 'ivy-occur-previous-line)
(define-key map (kbd "h") 'backward-char)
(define-key map (kbd "l") 'forward-char)
- (define-key map (kbd "g") 'ivy-occur-press)
+ (define-key map (kbd "f") 'ivy-occur-press)
+ (define-key map (kbd "g") 'ivy-occur-revert-buffer)
(define-key map (kbd "a") 'ivy-occur-read-action)
(define-key map (kbd "o") 'ivy-occur-dispatch)
(define-key map (kbd "c") 'ivy-occur-toggle-calling)
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)
swiper-match-face-2
swiper-match-face-3
swiper-match-face-4)
- "List of `swiper' faces for group matches.")
+ "List of `swiper' faces for group matches."
+ :group 'ivy-faces
+ :type 'list)
(defcustom swiper-min-highlight 2
"Only highlight matches for regexps at least this long."
(defun swiper-occur ()
"Generate a custom occur buffer for `swiper'."
- (ivy-occur-grep-mode)
- (font-lock-mode -1)
(let* ((fname (propertize
(with-ivy-window
(file-name-nondirectory
- (buffer-file-name)))
+ (buffer-file-name
+ (ivy-state-buffer ivy-last))))
'face
'compilation-info))
(cands (mapcar
'face 'compilation-line-number)
(substring s 1)))
ivy--old-cands)))
+ (unless (eq major-mode 'ivy-occur-grep-mode)
+ (ivy-occur-grep-mode)
+ (font-lock-mode -1))
(insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
default-directory))
(insert (format "%d candidates:\n" (length cands)))
(defun swiper--action (x)
"Goto line X."
- (let ((ln (1- (read (if (memq this-command '(ivy-occur-press))
- (when (string-match ":\\([0-9]+\\):.*\\'" x)
- (match-string-no-properties 1 x))
- (get-text-property 0 'display x)))))
+ (let ((ln (1- (read (or (get-text-property 0 'display x)
+ (and (string-match ":\\([0-9]+\\):.*\\'" x)
+ (match-string-no-properties 1 x))))))
(re (ivy--regex ivy-text)))
(if (null x)
(user-error "No candidates")