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

NEW Improves integration with dired-mode #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions ag.el
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,22 @@ If called with a prefix, prompts for flags to pass to ag."
(defalias 'ag-regexp-project-at-point 'ag-project-regexp)
(make-obsolete 'ag-regexp-project-at-point 'ag-project-regexp "0.46")

;;;###autoload
(defun ag-on-marked-files (string)
"Same as `ag`, but look only for the files marked on the current dired buffer."
(interactive (list (ag/read-from-minibuffer "Search string")))
(let ((files (if (version< emacs-version "27.0")
(dired-get-marked-files t current-prefix-arg nil nil)
(dired-get-marked-files t current-prefix-arg nil nil t))))
(ag/search string default-directory :files files)))

;;;###autoload
(defun ag-regexp-on-marked-files (string)
"Same as `ag-regexp`, but look only for the files marked on the current dired buffer."
(interactive (list (ag/read-from-minibuffer "Search regexp")))
(let ((files (dired-get-marked-files t current-prefix-arg nil nil t)))
(ag/search string default-directory :regexp t :files files)))

;;;###autoload
(defun ag-dired (dir string)
"Recursively find files in DIR matching literal search STRING.
Expand All @@ -530,13 +546,22 @@ See also `ag-dired-regexp'."
(ag-dired-regexp dir (ag/escape-pcre string)))

;;;###autoload
(defun ag-dired-regexp (dir regexp)
(defun ag-contents-dired (dir string)
"Same as `ag-dired`, but look at file contents rather than file paths."
(interactive "DDirectory: \nsFile contents pattern: ")
(ag-dired-regexp dir (ag/escape-pcre string) t))

;;;###autoload
(defun ag-dired-regexp (dir regexp &optional match-contents-p)
"Recursively find files in DIR matching REGEXP.
REGEXP should be in PCRE syntax, not Emacs regexp syntax.

The REGEXP is matched against the full path to the file, not
only against the file name.

If `match-contents-p` is non-nil, look at the file contents
rather than the file full paths.

Results are presented as a `dired-mode' buffer with
`default-directory' being DIR.

Expand All @@ -549,12 +574,16 @@ See also `find-dired'."
"*ag dired*"
(format "*ag dired pattern:%s dir:%s*" regexp dir)))
(cmd (if (string= system-type "windows-nt")
(concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " ") " -g \"" regexp "\" "
(concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " ")
(if match-contents-p " -l " " -g ")
"\"" regexp "\" "
(shell-quote-argument dir)
" | grep -v \"^$\" | sed \"s/'/\\\\\\\\'/g\" | xargs -I '{}' "
insert-directory-program " "
dired-listing-switches " '{}' &")
(concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " ") " -g '" regexp "' "
(concat ag-executable " " (combine-and-quote-strings ag-dired-arguments " ")
(if match-contents-p " -l " " -g ")
"'" regexp "' "
(shell-quote-argument dir)
" | grep -v '^$' | sed s/\\'/\\\\\\\\\\'/g | xargs -I '{}' "
insert-directory-program " "
Expand Down Expand Up @@ -592,6 +621,13 @@ See also `find-dired'."
(move-marker (process-mark proc) 1 (current-buffer)))
(setq mode-line-process '(":%s")))))

;;;###autoload
(defun ag-contents-dired-regexp (dir regexp)
"Same as `ag-dired-regexp`, but look for regexp in file contents rather
than in file names."
(interactive "DDirectory: \nsFile contents regexp: ")
(ag-dired-regexp dir regexp t))

;;;###autoload
(defun ag-project-dired (pattern)
"Recursively find files in current project matching PATTERN.
Expand Down