summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2015-12-23 11:00:29 +0100
committerAlan Pearce2015-12-23 11:00:29 +0100
commit5cb0ce04c8d1b3633a26b103ab3c0ee962b2f4c2 (patch)
treebdb98ba7b0cf4fee64e841176c47d64df7a89b36
parent2d0a04dd67f6b6b67c80e4991b19bb96a074c02e (diff)
downloadnixfiles-5cb0ce04c8d1b3633a26b103ab3c0ee962b2f4c2.tar.lz
nixfiles-5cb0ce04c8d1b3633a26b103ab3c0ee962b2f4c2.tar.zst
nixfiles-5cb0ce04c8d1b3633a26b103ab3c0ee962b2f4c2.zip
Emacs: Add `pt` with projectile search override
-rw-r--r--tag-emacs/emacs.d/init.org51
1 files changed, 51 insertions, 0 deletions
diff --git a/tag-emacs/emacs.d/init.org b/tag-emacs/emacs.d/init.org
index a41c341e..b0babcc5 100644
--- a/tag-emacs/emacs.d/init.org
+++ b/tag-emacs/emacs.d/init.org
@@ -205,6 +205,57 @@ By default, Emacs displays page breaks as ^L.  Lines look much nicer.
     :config (setq ag-project-root-function #'projectile-project-root))
 #+END_SRC
 
+** The Platinum Searcher
+
+[[https://github.com/monochromegane/the_platinum_searcher][The Platinum Searcher]] is a code search tool similar to ack and
+the_silver_searcher(ag). It supports multi platforms and multi
+encodings.
+
+#+BEGIN_SRC sh :tangle no
+brew install pt
+#+END_SRC
+
+#+BEGIN_SRC emacs-lisp
+  (use-package pt
+    :pin melpa-stable
+    :bind* ("C-c p s" . ap/projectile-pt)
+    :config (progn
+              (defun pt (string directory &optional args)
+                (interactive (list (read-from-minibuffer "Pt search for: " (thing-at-point 'symbol))
+                                   (read-directory-name "Directory: ")))
+                (let ((default-directory directory))
+                  (compilation-start
+                   (mapconcat 'identity
+                              (append (list pt-executable)
+                                      pt-arguments
+                                      args
+                                      '("--nogroup" "--nocolor" "--")
+                                      (list (shell-quote-argument string) ".")) " "))))
+
+              (defun ap/projectile-pt (search-term &optional arg)
+                "Run a pt search with SEARCH-TERM in the project.
+
+  With an optional prefix argument ARG SEARCH-TERM is interpreted as a
+  regular expression."
+                (interactive
+                 (list (read-from-minibuffer
+                        (projectile-prepend-project-name (format "Pt %ssearch for: " (if current-prefix-arg "regexp " "")))
+                        (projectile-symbol-or-selection-at-point))
+                       current-prefix-arg))
+                (if (require 'pt nil 'noerror)
+                    (let ((pt-command (if arg 'pt-regexp 'pt))
+                          (ignore-list (-map #'shell-quote-argument
+                                             (ag/format-ignore
+                                              (-union ag-ignore-list
+                                                      (append
+                                                       (projectile-ignored-files-rel) (projectile-ignored-directories-rel)
+                                                       grep-find-ignored-files grep-find-ignored-directories)))))
+                          ;; reset the prefix arg, otherwise it will affect the pt-command
+                          (current-prefix-arg nil))
+                      (funcall pt-command search-term (projectile-project-root) ignore-list))
+                  (error "Package 'pt' is not available")))))
+#+END_SRC
+
 ** Projectile
 
 Projectile is awesome for working in projects, especially VCS-backed