forked from magnars/.emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup-ag.el
More file actions
44 lines (39 loc) · 1.68 KB
/
setup-ag.el
File metadata and controls
44 lines (39 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(require 'ag)
(setq gr-have-ag t)
(defun gr-ag-cd (pattern &optional directory)
(interactive "sGrep Literal String: ")
(message "shell-file-name %s " shell-file-name)
(let ((null-device "/dev/null"))
(ag/search pattern (or directory default-directory)))
)
(defun gr-ag-search-case (string directory &optional regexp)
"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" (cons "--case-sensitive" ag-arguments)))))
(if ag-highlight-search
(setq arguments (append '("--color" "--color-match" "'30;43'") arguments))
(setq arguments (append '("--nocolor") arguments)))
(unless (file-exists-p default-directory)
(error "No such directory %s" default-directory))
(compilation-start
(ag/s-join " "
(append '("ag") arguments (list "--agignore" "~/.agignore" (ag/shell-quote string))))
'ag-mode)))
(defun gr-ag-cd-case (pattern &optional directory)
(interactive "sGrep (case-sensitive) Literal String: ")
(message "shell-file-name %s " shell-file-name)
(let ((null-device "/dev/null"))
(gr-ag-search-case pattern (or directory default-directory))))
(setq ag-highlight-search t)
(require 'ido)
(defun bind-ido-keys ()
"Keybindings for ido mode."
(define-key ido-completion-map (kbd "<down>") 'ido-next-match)
(define-key ido-completion-map (kbd "<up>") 'ido-prev-match)
(define-key ido-completion-map (kbd "<f9>") 'gr-ag-cd)
)
(add-hook 'ido-setup-hook #'bind-ido-keys)
(provide 'setup-ag)