                 (append '("ag") arguments (list (ag/shell-quote string))))
      'ag-mode)))
 
+(defun ag/dwim-at-point ()
+  "If there's an active selection, return that. Otherwise, get
+the symbol at point."
+  (if (use-region-p)
+      (buffer-substring-no-properties (region-beginning) (region-end))
+    (if (symbol-at-point)
+        (symbol-name (symbol-at-point)))))
+
 (autoload 'vc-git-root "vc-git")
 (autoload 'vc-svn-root "vc-svn")
 

(defun ag-project-at-point (string)
  "Same as ``ag-project'', but with the search string defaulting
to the symbol under point."
   (interactive (list (read-from-minibuffer "Search string: "
                                           (if (symbol-at-point)
                                               (symbol-name (symbol-at-point))))))
   (ag/search string (ag/project-root default-directory)))

;; Taken from grep-filter, just changed the color regex.
(defun ag-filter ()
  "Handle match highlighting escape sequences inserted by the grep process.
This function is called from `compilation-filter-hook'."
  (save-excursion
    (forward-line 0)

(require 'compile)

(defvar ag-match-face 'match
  "Face name to use for ag matches.")


(define-compilation-mode ag-mode "Ag"
