Wilfred/ag.el

Feature request: `ag-regexp` to initialise input prompt with active region

Opened this issue · 0 comments

heaysa commented

On my machine, the output of ag --version is: ag version 2.2.0 Features: +jit +lzma +zlib
My Emacs version is: GNU Emacs 29.4
I'm using: Ubuntu 22

I use ag-regexp for simple searches rather than the ag function. It would be convenient if ag-regexp used ag/read-from-minibuffer as ag does, so that the active region is used as a default search.

Perhaps:

(defun ag-regexp (string directory)
  "Search using ag in a given DIRECTORY for a given regexp.
The regexp should be in PCRE syntax, not Emacs regexp
syntax. STRING defaults to the symbol under point.

If called with a prefix, prompts for flags to pass to ag."
  (interactive (list (ag/read-from-minibuffer "Search string")
                     (read-directory-name "Directory: ")))
  (ag/search string directory :regexp t))

One catch is that an active region returned by ag/read-from-minibuffer will not be escaped to guarantee a matching regex.