ag.el
changeset 1502 72c63cea35d3
parent 1501 636e49ed6d27
child 1515 a28c181c1412
--- 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