branch: externals/embark commit 34272d51c519d99e0e1be989382aca33ae7bc662 Merge: f12955c7ac f9311dedca Author: Omar AntolĂn Camarena <omar.anto...@gmail.com> Commit: GitHub <nore...@github.com>
Merge pull request #568 from astoff/grep-export Add match highlight and count to grep export --- embark-consult.el | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/embark-consult.el b/embark-consult.el index d5603024a6..8b0a39570a 100644 --- a/embark-consult.el +++ b/embark-consult.el @@ -155,6 +155,8 @@ This function is meant to be added to `embark-collect-mode-hook'." ;;; Support for consult-grep +(defvar grep-mode-line-matches) +(defvar grep-num-matches-found) (defvar wgrep-header/footer-parser) (declare-function wgrep-setup "ext:wgrep") @@ -165,12 +167,25 @@ This function is meant to be added to `embark-collect-mode-hook'." (defun embark-consult-export-grep (lines) "Create a grep mode buffer listing LINES." - (let ((buf (generate-new-buffer "*Embark Export Grep*"))) + (let ((buf (generate-new-buffer "*Embark Export Grep*")) + (count 0) + prop) (with-current-buffer buf (insert (propertize "Exported grep results:\n\n" 'wgrep-header t)) (dolist (line lines) (insert line "\n")) (goto-char (point-min)) + (while (setq prop (text-property-search-forward + 'face 'consult-highlight-match t)) + (cl-incf count) + (put-text-property (prop-match-beginning prop) + (prop-match-end prop) + 'font-lock-face + 'match)) + (goto-char (point-min)) (grep-mode) + (when (> count 0) + (setq-local grep-num-matches-found count + mode-line-process grep-mode-line-matches)) ;; Make this buffer current for next/previous-error (setq next-error-last-buffer buf) ;; Set up keymap before possible wgrep-setup, so that wgrep