Refactor helm commands

This commit is contained in:
Henrik Lissner 2019-03-02 02:03:15 -05:00
parent 7b2e80c711
commit ce22e21853
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -162,9 +162,10 @@ order.
(string-join (delq nil (cdr command)) " ")
(abbreviate-file-name directory))
helm-source-do-ag)
(cl-letf ((+helm-global-prompt prompt)
((symbol-function 'helm-do-ag--helm)
(helm-attrset '+helm-command command helm-source-do-ag)
(cl-letf (((symbol-function 'helm-do-ag--helm)
(lambda () (helm :sources '(helm-source-do-ag)
:prompt prompt
:buffer "*helm-ag*"
:keymap helm-do-ag-map
:input query
@ -177,7 +178,7 @@ order.
return (intern (format format tool))))
;;;###autoload
(defun +helm/project-search (&optional all-files-p)
(defun +helm/project-search (&optional arg)
"Performs a project search from the project root.
Uses the first available search backend from `+helm-project-search-engines'. If
@ -186,10 +187,10 @@ ones, in the search."
(interactive "P")
(funcall (or (+helm--get-command "+helm/%s")
#'+helm/grep)
(or all-files-p current-prefix-arg)))
arg))
;;;###autoload
(defun +helm/project-search-from-cwd (&optional all-files-p)
(defun +helm/project-search-from-cwd (&optional arg)
"Performs a project search recursively from the current directory.
Uses the first available search backend from `+helm-project-search-engines'. If
@ -198,7 +199,7 @@ ones."
(interactive "P")
(funcall (or (+helm--get-command "+helm/%s-from-cwd")
#'+helm/grep-from-cwd)
(or all-files-p current-prefix-arg)))
arg))
;; Relative to project root
@ -213,21 +214,31 @@ ones."
(dolist (engine `(,@(cl-remove-duplicates +helm-project-search-engines :from-end t) grep))
(defalias (intern (format "+helm/%s" engine))
(lambda (all-files-p &optional query directory)
(lambda (arg &optional query directory)
(interactive "P")
(+helm-file-search engine :query query :in directory :all-files all-files-p))
(+helm-file-search engine
:query query
:in directory
:all-files (and (not (null arg))
(listp arg))))
(format "Perform a project file search using %s.
QUERY is a regexp. If omitted, the current selection is used. If no selection is
active, the last known search is used.
ARG is the universal argument. If a number is passed through it, e.g. C-u 3, then
If ALL-FILES-P, search compressed and hidden files as well."
engine))
(defalias (intern (format "+helm/%s-from-cwd" engine))
(lambda (all-files-p &optional query)
(lambda (arg &optional query)
(interactive "P")
(+helm-file-search engine :query query :in default-directory :all-files all-files-p))
(+helm-file-search engine
:query query
:in default-directory
:all-files (and (not (null arg))
(listp arg))))
(format "Perform a project file search from the current directory using %s.
QUERY is a regexp. If omitted, the current selection is used. If no selection is