Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the last ag search buffer name #92

Closed

Conversation

kaushalmodi
Copy link

Can you please add this so that I can have a function like below in my config:

Using ag/last-search-buffer-name ensures that I kill only the last ag search buffer and not one of the prior open ones (if any).

    (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)

@Wilfred
Copy link
Owner

Wilfred commented Aug 9, 2015

This shouldn't be necessary. ag-search-finished-hook is executed in the context of the results buffer, so you should just be able to use (current-buffer). Does that meet your need?

@kaushalmodi
Copy link
Author

You're correct. Operations happen in the current ag buffer. Thanks.

kaushalmodi/.emacs.d@be25ade

@kaushalmodi kaushalmodi deleted the cache-last-ag-search-buf-name branch August 10, 2015 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants