Skip to content

Commit

Permalink
Merge 64e211c into 444a8cc
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarrientos committed Apr 27, 2022
2 parents 444a8cc + 64e211c commit 82f2b34
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/usage.org
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@
Visit match in file.
:END:

If [[opt:rg-group-result][rg-group-result]] is enabled, the [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html][Imenu]] facility is configured to
jump across files.

*** Refine search
From the results buffer it's easy to change the search
parameters. Some bindings toggle a flag while others allow you to
Expand Down
23 changes: 21 additions & 2 deletions rg-result.el
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,17 @@ Commands:
(setq rg-cur-search search)
(rg-history-push (rg-search-copy rg-cur-search)
rg-search-history)
(rg-maybe-show-header))
(rg-maybe-show-header)
(rg-configure-imenu))

(defun rg-recompile ()
"Rerun the current search."
(interactive)
(let ((rg-recompile t))
(recompile))
(hack-dir-local-variables-non-file-buffer)
(rg-maybe-show-header))
(rg-maybe-show-header)
(rg-configure-imenu))

(defun rg-rerun (&optional no-history)
"Run `recompile' with `compilation-arguments' taken from `rg-cur-search'.
Expand Down Expand Up @@ -763,6 +765,23 @@ previous file with grouped matches."
(rg-rerun 'no-history))
(message "No more history elements for forward.")))

(defun rg-configure-imenu ()
"Add files with matches to imenu if rg-group-result is enabled."
(when rg-group-result
(setq imenu-create-index-function
(lambda ()
(goto-char (point-min))
(let ((elements nil)
(filepath nil)
(nextfile (point-min)))
(while (setq nextfile (rg-navigate-file-message nextfile nil 1))
(save-excursion
(goto-char nextfile)
(skip-chars-forward "File: ")
(setq filepath (buffer-substring-no-properties (point) (line-end-position))))
(push (cons filepath nextfile) elements))
(nreverse elements))))))

(provide 'rg-result)

;; Local Variables:
Expand Down

0 comments on commit 82f2b34

Please sign in to comment.