branch: master
commit bfdda682b3cf29ea335533fc000f04f8d7960904
Author: Nathan Moreau <[email protected]>
Commit: Oleh Krehel <[email protected]>
swiper.el (swiper-occur): Use ivy-occur-next-error
* ivy.el (ivy-occur-next-error): Add.
This change ensures that next-error and previous-error work
for swiper even for buffer that do not visit a file.
Fixes #2257
Fixes #1354
---
ivy.el | 10 ++++++++++
swiper.el | 3 ++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/ivy.el b/ivy.el
index 9fc579d..ccd53ff 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4636,6 +4636,16 @@ When `ivy-calling' isn't nil, call `ivy-occur-press'."
(ivy-occur-previous-line arg)
(ivy-occur-press-and-switch))))
+(defun ivy-occur-next-error (n &optional reset)
+ "A `next-error-function' for `ivy-occur-mode'."
+ (interactive "p")
+ (when reset
+ (goto-char (point-min)))
+ (setq n (or n 1))
+ (let ((ivy-calling t))
+ (cond ((< n 0) (ivy-occur-previous-line (- n)))
+ (t (ivy-occur-next-line n)))))
+
(define-derived-mode ivy-occur-mode fundamental-mode "Ivy-Occur"
"Major mode for output from \\[ivy-occur].
diff --git a/swiper.el b/swiper.el
index 5e73ba4..af60c5c 100644
--- a/swiper.el
+++ b/swiper.el
@@ -677,7 +677,8 @@ When capture groups are present in the input, print them
instead of lines."
(lambda (cand) (concat "./" cand))
cands))
(goto-char (point-min))
- (forward-line 4))))
+ (forward-line 4)
+ (setq-local next-error-function #'ivy-occur-next-error))))
(ivy-set-occur 'swiper 'swiper-occur)