branch: master commit efdee7a6e98828f4c1a9e0acfa665d428dd9aab6 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
swiper.el (swiper--occur-insert-lines): Extract * counsel.el (counsel-grep-like-occur): Re-use `swiper--occur-insert-lines'. Re #2203 --- counsel.el | 7 +------ swiper.el | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/counsel.el b/counsel.el index a912a29..4164b05 100644 --- a/counsel.el +++ b/counsel.el @@ -2862,12 +2862,7 @@ Works for `counsel-git-grep', `counsel-ag', etc." switches (shell-quote-argument regex)))))) (cands (counsel--split-string (shell-command-to-string cmd)))) - ;; Need precise number of header lines for `wgrep' to work. - (insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n" - default-directory)) - (insert (format "%d candidates:\n" (length cands))) - (ivy--occur-insert-lines - (mapcar #'counsel--normalize-grep-match cands)))) + (swiper--occur-insert-lines (mapcar #'counsel--normalize-grep-match cands)))) (defun counsel-ag-occur () "Generate a custom occur buffer for `counsel-ag'." diff --git a/swiper.el b/swiper.el index 2777123..1a4f6dd 100644 --- a/swiper.el +++ b/swiper.el @@ -630,6 +630,16 @@ When non-nil, INITIAL-INPUT is the initial search pattern." (setq last-pt pt)) (nreverse res))) +(defun swiper--occur-insert-lines (cands) + ;; Need precise number of header lines for `wgrep' to work. + (insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n" + default-directory)) + (insert (format "%d candidates:\n" (length cands))) + (ivy--occur-insert-lines cands) + (goto-char (point-min)) + (forward-line 4) + (setq-local next-error-function #'ivy-occur-next-error)) + (defun swiper-occur (&optional revert) "Generate a custom occur buffer for `swiper'. When REVERT is non-nil, regenerate the current *ivy-occur* buffer. @@ -668,16 +678,8 @@ When capture groups are present in the input, print them instead of lines." (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))) - (ivy--occur-insert-lines - (mapcar - (lambda (cand) (concat "./" cand)) - cands)) - (goto-char (point-min)) - (forward-line 4) - (setq-local next-error-function #'ivy-occur-next-error)))) + (swiper--occur-insert-lines + (mapcar (lambda (cand) (concat "./" cand)) cands))))) (declare-function evil-set-jump "ext:evil-jumps")