2018-06-02 20:32:52 +02:00
|
|
|
;;; completion/helm/autoload/helm.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/tasks (&optional _arg)
|
|
|
|
(interactive "P")
|
|
|
|
;; TODO Implement `+helm/tasks'
|
|
|
|
(error "Not implemented yet"))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Project search
|
|
|
|
;;
|
|
|
|
|
2018-06-20 15:37:31 +02:00
|
|
|
;;;###autoload
|
|
|
|
(cl-defun +helm-file-search (engine &key query in all-files (recursive t))
|
|
|
|
"Conduct a file search using ENGINE, which can be any of: rg, ag, pt, and
|
|
|
|
grep. If omitted, ENGINE will default to the first one it detects, in that
|
|
|
|
order.
|
|
|
|
|
|
|
|
:query STRING
|
|
|
|
Determines the initial input to search for.
|
|
|
|
:in PATH
|
|
|
|
Sets what directory to base the search out of. Defaults to the current
|
|
|
|
project's root.
|
|
|
|
:recursive BOOL
|
|
|
|
Whether or not to search files recursively from the base directory."
|
|
|
|
(declare (indent defun))
|
2018-06-02 20:32:52 +02:00
|
|
|
(require 'helm-ag)
|
|
|
|
(helm-ag--init-state)
|
|
|
|
(let* ((project-root (doom-project-root))
|
|
|
|
(directory (or in project-root))
|
|
|
|
(default-directory directory)
|
|
|
|
(helm-ag--default-directory directory)
|
2018-06-05 19:49:34 +02:00
|
|
|
(helm-ag--default-target (list directory))
|
2018-06-02 20:32:52 +02:00
|
|
|
(engine (or engine
|
2018-07-24 14:07:13 +02:00
|
|
|
(cl-loop for tool in +helm-project-search-engines
|
2018-07-23 00:06:47 +02:00
|
|
|
if (executable-find (symbol-name tool))
|
|
|
|
return tool)
|
2018-06-02 20:32:52 +02:00
|
|
|
(and (or (executable-find "grep")
|
|
|
|
(executable-find "git"))
|
|
|
|
'grep)
|
|
|
|
(error "No search engine specified (is ag, rg, pt or git installed?)")))
|
|
|
|
(query (or query
|
|
|
|
(when (use-region-p)
|
|
|
|
(let ((beg (or (bound-and-true-p evil-visual-beginning) (region-beginning)))
|
|
|
|
(end (or (bound-and-true-p evil-visual-end) (region-end))))
|
|
|
|
(when (> (abs (- end beg)) 1)
|
|
|
|
(rxt-quote-pcre (buffer-substring-no-properties beg end)))))
|
|
|
|
""))
|
|
|
|
(prompt (format "%s%%s %s"
|
|
|
|
(symbol-name engine)
|
|
|
|
(cond ((equal directory default-directory)
|
|
|
|
"./")
|
|
|
|
((equal directory project-root)
|
|
|
|
(projectile-project-name))
|
|
|
|
(t
|
|
|
|
(file-relative-name directory project-root)))))
|
|
|
|
(command
|
|
|
|
(pcase engine
|
|
|
|
('grep
|
|
|
|
(let* ((helm-ff-default-directory directory)
|
|
|
|
(helm-grep-in-recurse recursive)
|
|
|
|
(helm-grep-ignored-files
|
|
|
|
(unless all-files
|
|
|
|
(cl-union (projectile-ignored-files-rel) grep-find-ignored-files)))
|
|
|
|
(helm-grep-ignored-directories
|
|
|
|
(unless all-files
|
|
|
|
(cl-union (mapcar 'directory-file-name (projectile-ignored-directories-rel))
|
|
|
|
grep-find-ignored-directories)))
|
|
|
|
(helm-grep-default-command
|
|
|
|
(if (and nil (eq (projectile-project-vcs) 'git))
|
|
|
|
(format "git --no-pager grep --no-color -n%%c -e %%p %s -- %%f"
|
|
|
|
(if recursive "" "--max-depth 1 "))
|
|
|
|
(format "grep -si -a%s %%e -n%%cH -e %%p %%f %s"
|
|
|
|
(if recursive " -R" "")
|
|
|
|
(if recursive "." "./*"))))
|
|
|
|
(helm-grep-default-recurse-command helm-grep-default-command))
|
|
|
|
(setq helm-source-grep
|
|
|
|
(helm-build-async-source (capitalize (helm-grep-command t))
|
|
|
|
:header-name (lambda (_name) "Helm Projectile Grep (C-c ? Help)")
|
|
|
|
:candidates-process #'helm-grep-collect-candidates
|
|
|
|
:filter-one-by-one #'helm-grep-filter-one-by-one
|
|
|
|
:candidate-number-limit 9999
|
|
|
|
:nohighlight t
|
|
|
|
:keymap helm-grep-map
|
|
|
|
:history 'helm-grep-history
|
|
|
|
:action (apply #'helm-make-actions helm-projectile-grep-or-ack-actions)
|
|
|
|
:persistent-action 'helm-grep-persistent-action
|
|
|
|
:persistent-help "Jump to line (`C-u' Record in mark ring)"
|
|
|
|
:requires-pattern 2))
|
|
|
|
(helm :sources 'helm-source-grep
|
|
|
|
:input query
|
|
|
|
:prompt prompt
|
|
|
|
:buffer "*helm grep*"
|
|
|
|
:default-directory directory
|
|
|
|
:keymap helm-grep-map
|
|
|
|
:history 'helm-grep-history
|
|
|
|
:truncate-lines helm-grep-truncate-lines))
|
|
|
|
(cl-return t))
|
|
|
|
(`ag
|
2018-06-05 19:49:34 +02:00
|
|
|
(list "ag -zS"
|
|
|
|
(if IS-WINDOWS "--vimgrep" "--nocolor --nogroup")
|
2018-06-02 20:32:52 +02:00
|
|
|
(when all-files "-a")
|
|
|
|
(unless recursive "--depth 1")))
|
|
|
|
(`rg
|
|
|
|
(list "rg -zS --no-heading --line-number --color never"
|
|
|
|
(when all-files "-uu")
|
|
|
|
(unless recursive "--maxdepth 1")))
|
|
|
|
(`pt
|
|
|
|
(list "pt -zS --nocolor --nogroup -e"
|
|
|
|
(when all-files "-a")
|
|
|
|
(unless recursive "--depth 1")))))
|
|
|
|
(helm-ag-base-command (string-join command " ")))
|
2018-06-05 19:49:34 +02:00
|
|
|
(if (and (eq engine 'ag)
|
|
|
|
(equal query ""))
|
|
|
|
(helm-do-ag directory)
|
|
|
|
(setq helm-ag--last-query query)
|
|
|
|
(helm-attrset 'search-this-file nil helm-ag-source)
|
|
|
|
(helm-attrset 'name (helm-ag--helm-header helm-ag--default-directory) helm-ag-source)
|
|
|
|
(helm :sources '(helm-ag-source)
|
|
|
|
:input query
|
|
|
|
:prompt prompt
|
|
|
|
:buffer "*helm-ag*"
|
|
|
|
:keymap helm-ag-map
|
|
|
|
:history 'helm-ag--helm-history))))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/project-search (arg)
|
|
|
|
"Performs a project search using the first available search backend from a
|
|
|
|
list of: ripgrep, ag, pt, git-grep and grep. If ARG (universal argument),
|
|
|
|
preform search from current directory."
|
|
|
|
(interactive "P")
|
|
|
|
(call-interactively
|
2018-07-24 14:18:44 +02:00
|
|
|
(or (cl-loop for tool in (cl-remove-duplicates +helm-project-search-engines :from-end t)
|
2018-07-23 00:06:47 +02:00
|
|
|
if (executable-find (symbol-name tool))
|
|
|
|
return (intern (format "+helm/%s%s" tool (if arg "-from-cwd" ""))))
|
|
|
|
(if arg
|
|
|
|
#'+helm/grep-from-cwd
|
|
|
|
#'+helm/grep))))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;; Relative to project root
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/rg (all-files-p &optional query directory)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'rg :query query :in directory :all-files all-files-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/ag (all-files-p &optional query directory)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'ag :query query :in directory :all-files all-files-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/pt (all-files-p &optional query directory)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'pt :query query :in directory :all-files all-files-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/grep (all-files-p &optional query directory)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'grep :query query :in directory :all-files all-files-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;; Relative to current directory
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/rg-from-cwd (recurse-p &optional query)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'rg :query query :in default-directory :recursive recurse-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/ag-from-cwd (recurse-p &optional query)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'ag :query query :in default-directory :recursive recurse-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/pt-from-cwd (recurse-p &optional query)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'pt :query query :in default-directory :recursive recurse-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +helm/grep-from-cwd (recurse-p &optional query)
|
|
|
|
"TODO"
|
|
|
|
(interactive "P")
|
2018-06-20 15:37:31 +02:00
|
|
|
(+helm-file-search 'grep :query query :in default-directory :recursive recurse-p))
|
2018-06-02 20:32:52 +02:00
|
|
|
|