Skip to content

Commit

Permalink
Allow the arguments to ag itself to be overriden, if a prefix argument
Browse files Browse the repository at this point in the history
is used.

Fixes #36.
  • Loading branch information
Wilfred committed Feb 20, 2014
1 parent 689f6fc commit 4a6bf0b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ buffers.

## Changelog

### 0.39

The commands `ag`, `ag-files`, `ag-regexp`, `ag-project`,
`ag-project-files` and `ag-project-regexp` can now take a prefix
argument. For example, `C-u M-x ag`. If given a prefix argument, you
are also prompted for the flags to pass ag itself.

### 0.38

`ag-dired` and `ag-project-dired` should now work on Mac OS X
Expand Down
38 changes: 27 additions & 11 deletions ag.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
;;
;; Author: Wilfred Hughes <[email protected]>
;; Created: 11 January 2013
;; Version: 0.38
;; Version: 0.39

;;; Commentary:

Expand Down Expand Up @@ -125,10 +125,12 @@ different window, according to `ag-open-in-other-window'."
"Run ag searching for the STRING given in DIRECTORY.
If REGEXP is non-nil, treat STRING as a regular expression."
(let ((default-directory (file-name-as-directory directory))
(arguments (if regexp
ag-arguments
(cons "--literal" ag-arguments)))
(arguments (if current-prefix-arg
(read (read-from-minibuffer "Arg arguments: " (prin1-to-string ag-arguments)))
ag-arguments))
(shell-command-switch "-c"))
(unless regexp
(setq arguments (cons "--literal" arguments)))
(if ag-highlight-search
(setq arguments (append '("--color" "--color-match" "30;43") arguments))
(setq arguments (append '("--nocolor") arguments)))
Expand Down Expand Up @@ -267,45 +269,57 @@ matched literally."
;;;###autoload
(defun ag (string directory)
"Search using ag in a given DIRECTORY for a given search STRING,
with STRING defaulting to the symbol under point."
with STRING defaulting to the symbol under point.
If called with a prefix, prompts for flags to pass to ag."
(interactive (list (read-from-minibuffer "Search string: " (ag/dwim-at-point))
(read-directory-name "Directory: ")))
(ag/search string directory))

;;;###autoload
(defun ag-files (string file-regex directory)
"Search using ag in a given DIRECTORY and file type regex FILE-REGEX
for a given search STRING, with STRING defaulting to the symbol under point."
for a given search STRING, with STRING defaulting to the symbol under point.
If called with a prefix, prompts for flags to pass to ag."
(interactive (list (read-from-minibuffer "Search string: " (ag/dwim-at-point))
(read-from-minibuffer "In filenames matching PCRE: " (ag/buffer-extension-regex))
(read-directory-name "Directory: ")))
(ag/search string directory :file-regex file-regex))

;;;###autoload
(defun ag-regexp (string directory)
"Search using ag in a given directory for a given regexp."
"Search using ag in a given directory for a given regexp.
If called with a prefix, prompts for flags to pass to ag."
(interactive "sSearch regexp: \nDDirectory: ")
(ag/search string directory :regexp t))

;;;###autoload
(defun ag-project (string)
"Guess the root of the current project and search it with ag
for the given string."
for the given string.
If called with a prefix, prompts for flags to pass to ag."
(interactive (list (read-from-minibuffer "Search string: " (ag/dwim-at-point))))
(ag/search string (ag/project-root default-directory)))

;;;###autoload
(defun ag-project-files (string file-regex)
"Search using ag in a given DIRECTORY and file type regex FILE-REGEX
for a given search STRING, with STRING defaulting to the symbol under point."
for a given search STRING, with STRING defaulting to the symbol under point.
If called with a prefix, prompts for flags to pass to ag."
(interactive (list (read-from-minibuffer "Search string: " (ag/dwim-at-point))
(read-from-minibuffer "In filenames matching PCRE: " (ag/buffer-extension-regex))))
(ag/search string (ag/project-root default-directory) :file-regex file-regex))

;;;###autoload
(defun ag-project-regexp (regexp)
"Guess the root of the current project and search it with ag
for the given regexp."
for the given regexp.
If called with a prefix, prompts for flags to pass to ag."
(interactive "sSearch regexp: ")
(ag/search regexp (ag/project-root default-directory) :regexp t))

Expand All @@ -317,7 +331,9 @@ for the given regexp."
;;;###autoload
(defun ag-regexp-project-at-point (regexp)
"Same as ``ag-regexp-project'', but with the search regexp defaulting
to the symbol under point."
to the symbol under point.
If called with a prefix, prompts for flags to pass to ag."
(interactive (list (read-from-minibuffer "Search regexp: " (ag/dwim-at-point))))

(ag/search regexp (ag/project-root default-directory) :regexp t))
Expand Down

0 comments on commit 4a6bf0b

Please sign in to comment.