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

Support for ag-executable in home directory #164

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
19 changes: 15 additions & 4 deletions ag.el
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.

;;; ag.el --- A front-end for ag ('the silver searcher'), the C ack replacement.

;; Copyright (C) 2013-2014 Wilfred Hughes <[email protected]>
Expand Down Expand Up @@ -249,7 +252,7 @@ If REGEXP is non-nil, treat STRING as a regular expression."
(error "No such directory %s" default-directory))
(let ((command-string
(mapconcat #'shell-quote-argument
(append (list ag-executable) arguments (append `(,string) files))
(append (list (ag/ag-executable)) arguments (append `(,string) files))
" ")))
;; If we're called with a prefix, let the user modify the command before
;; running it. Typically this means they want to pass additional arguments.
Expand Down Expand Up @@ -549,12 +552,12 @@ 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/ag-executable) " " (combine-and-quote-strings ag-dired-arguments " ") " -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/ag-executable) " " (combine-and-quote-strings ag-dired-arguments " ") " -g '" regexp "' "
(shell-quote-argument dir)
" | grep -v '^$' | sed s/\\'/\\\\\\\\\\'/g | xargs -I '{}' "
insert-directory-program " "
Expand Down Expand Up @@ -663,7 +666,7 @@ This function is called from `compilation-filter-hook'."

(defun ag/get-supported-types ()
"Query the ag executable for which file types it recognises."
(let* ((ag-output (shell-command-to-string (format "%s --list-file-types" ag-executable)))
(let* ((ag-output (shell-command-to-string (format "%s --list-file-types" (ag/ag-executable))))
(lines (-map #'s-trim (s-lines ag-output)))
(types (--keep (when (s-starts-with? "--" it) (s-chop-prefix "--" it )) lines))
(extensions (--map (s-split " " it) (--filter (s-starts-with? "." it) lines))))
Expand All @@ -684,5 +687,13 @@ This function is called from `compilation-filter-hook'."
(read-from-minibuffer "Filenames which match PCRE: "
(ag/buffer-extension-regex))))))

(defun ag/ag-executable ()
"Expand ag-executable path if needed.
This is needed if ag-executable is set to point to a path under
your home directory."
(if (string-match "^~" ag-executable)
(expand-file-name ag-executable)
ag-executable))

(provide 'ag)
;;; ag.el ends here