 
 (defun pt--search (pattern directory)
   (let ((default-directory directory))
-  (compilation-start (concat "pt --nogroup --nocolor --smart-case " (shell-quote-argument pattern))
-                     'pt-search-compilation-mode)))
+    (compilation-start
+     (mapconcat 'identity
+                (append (list pt-executable)
+                        pt-arguments
+                        '("--nogroup" "--nocolor" "--")
+                        (list (shell-quote-argument pattern))) " ")
+     'pt-search-mode)))
 
 ;;;###autoload
-(defun pt (pattern directory)
-  (interactive (list (read-from-minibuffer "Search: " (thing-at-point 'symbol))
+(defun pt-regexp (regexp directory)
+  "Run a pt search with REGEXP rooted at DIRECTORY."
+  (interactive (list (read-from-minibuffer "Pt search for: " (thing-at-point 'symbol))
                      (read-directory-name "Directory: ")))
-  (pt--search pattern directory))
+  (pt--search regexp directory))
 
 ;;;###autoload
-(defun projectile-pt (pattern)
-  (interactive (list (read-from-minibuffer "Search: " (thing-at-point 'symbol))))
-  (pt--search pattern (projectile-project-root)))
+(defun projectile-pt (regexp)
+  "Run a pt search with REGEXP rooted at the current projectile project root."
+  (interactive (list (read-from-minibuffer "Pt search for: " (thing-at-point 'symbol))))
+  (if (fboundp 'projectile-project-root)
+      (pt--search regexp (projectile-project-root))
+    (error "Projectile is not available")))
 
 (provide 'pt)
 ;;; pt.el ends here

;;; pt.el --- A front-end for pt, The Platinum Searcher.

;; Copyright (C) 2014 Bailey Ling <bling@live.ca>

;;; Commentary:

;;; License:

;; This file is not part of GNU Emacs.
;; However, it is distributed under the same license.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Code:
(eval-when-compile (require 'cl))
(require 'compile)
(require 'grep)
(require 'thingatpt)

;; copied from ag.el/ag-filter
(defun pt--filter ()

        (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
          (replace-match "" t t))))))

(define-compilation-mode pt-search-mode "Pt"
  "Platinum searcher results compilation mode"
  (set (make-local-variable 'truncate-lines) t)
  (set (make-local-variable 'compilation-disable-input) t)
