Closed kaushalmodi closed 9 years ago
Explanation for adding ag/last-search-buffer-name
as seen in the PR. A user could have multiple ag buffers open. The above var makes sure that if the user has
(add-hook 'ag-post-search-hook #'ag/jump-to-result-if-only-one-match)
only the buffer for the last ag search that that only 1 match gets closed.
This does not need to be merged upstream. But this functionality can be achieved by the below AFTER PR https://github.com/Wilfred/ag.el/pull/92 is accepted:
(defun ag/jump-to-result-if-only-one-match ()
"Jump to the first ag result if that ag search came up with just one match."
(let (only-one-match)
(when (member "--stats" ag-arguments)
(with-current-buffer ag/last-search-buffer-name
(save-excursion
(goto-char (point-min))
(setq only-one-match (re-search-forward "^1 matches\\s-*$" nil :noerror))))
(when only-one-match
(next-error)
(kill-buffer ag/last-search-buffer-name)))))
(add-hook 'ag-search-finished-hook #'ag/jump-to-result-if-only-one-match)
ag-post-search-hook
.This is a PR associated to this issue: https://github.com/Wilfred/ag.el/issues/89 Once I figure out how to solve that issue, I can update this PR to be fully functional.