It much easy to call ag for current directory via modifier then prefix argument.
--- a/.emacs-my Thu Mar 02 22:41:44 2017 +0200
+++ b/.emacs-my Mon Mar 06 15:40:53 2017 +0200
@@ -818,6 +818,7 @@
(call-interactively #'rgrep))))
(global-set-key [f7] 'my/ag)
+(global-set-key [S-f7] 'my/ag-default-directory)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(message "highlighting")
--- a/ag.el Thu Mar 02 22:41:44 2017 +0200
+++ b/ag.el Mon Mar 06 15:40:53 2017 +0200
@@ -95,19 +95,31 @@
default-directory))
(error default-directory)))
+(defun my/ag-read-regex ()
+ (let* ( (def (when my/ag-regex-history (car my/ag-regex-history)))
+ (part (when def (if (< (length def) 20)
+ def
+ (concat (substring def 0 20) "...")))) )
+ (read-string
+ (if part (format "Regex [%s]: " part) "Regex: ")
+ "" 'my/ag-regex-history def t)))
+
;;;###autoload
(defun my/ag (regex)
- (interactive
- (let* ( (def (when my/ag-regex-history (car my/ag-regex-history)))
- (part (when def (if (< (length def) 20)
- def
- (concat (substring def 0 20) "...")))) )
- (list (read-string
- (if part (format "Regex [%s]: " part) "Regex: ")
- "" 'my/ag-regex-history def t))))
+ "Search in 'ag' recursively from VCS root directory and fall to
+current directory if VCS root is not defined."
+ (interactive (list (my/ag-read-regex)))
(my/ag-setup-buffer (if current-prefix-arg default-directory (my/ag-project-root)))
(my/ag-run regex))
+;;;###autoload
+(defun my/ag-default-directory (regex)
+ "Search in 'ag' recursively from current directory."
+ (interactive (list (my/ag-read-regex)))
+ (my/ag-setup-buffer default-directory)
+ (my/ag-run regex))
+
+
(provide 'ag)
;;; ag.el ends here