Implement :ag, :agcwd, :rg, & :rgcwd commands for helm

This commit is contained in:
Henrik Lissner 2017-12-07 21:43:31 -05:00
parent 2ebdc1d25a
commit ea80992433
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -7,21 +7,19 @@
(interactive "<a><!>") (interactive "<a><!>")
(helm-swoop :$query search :$multiline bang)) (helm-swoop :$query search :$multiline bang))
(defvar +helm--file-last-search nil) (defun +helm--file-search (beg end query &optional directory options)
;;;###autoload (autoload '+helm:ag "completion/helm/autoload/evil" nil t)
(evil-define-command +helm:ag (beg end query &optional bang directory)
"TODO"
(interactive "<r><a><!>")
(require 'helm-ag) (require 'helm-ag)
(helm-ag--init-state) (helm-ag--init-state)
(let ((helm-ag--default-directory (or directory (doom-project-root))) (let ((helm-ag--default-directory (or directory (doom-project-root)))
(helm-ag--last-query (or query (query (or query
(if (evil-visual-state-p)
(and beg end (and beg end
(> (abs (- end beg)) 1) (> (abs (- end beg)) 1)
(setq +helm--file-last-search (rxt-quote-pcre (buffer-substring-no-properties beg end)))
(rxt-quote-pcre (buffer-substring-no-properties beg end)))) +helm--file-last-query)
+helm--file-last-search)) +helm--file-last-query))
(helm-ag-command-option (concat helm-ag-command-option (if bang " -a ")))) (helm-ag-command-option (concat helm-ag-command-option " " (string-join options " "))))
(setq helm-ag--last-query query)
(helm-attrset 'search-this-file nil helm-ag-source) (helm-attrset 'search-this-file nil helm-ag-source)
(helm-attrset 'name (helm-ag--helm-header helm-ag--default-directory) helm-ag-source) (helm-attrset 'name (helm-ag--helm-header helm-ag--default-directory) helm-ag-source)
(helm :sources '(helm-ag-source) (helm :sources '(helm-ag-source)
@ -30,16 +28,33 @@
:keymap helm-ag-map :keymap helm-ag-map
:history 'helm-ag--helm-history))) :history 'helm-ag--helm-history)))
;;;###autoload (autoload '+helm:ag-cwd "completion/helm/autoload/evil" nil t) (defvar +helm--file-last-search nil)
(evil-define-command +helm:ag-cwd (beg end query &optional bang directory) ;;;###autoload (autoload '+helm:ag "completion/helm/autoload/evil" nil t)
(evil-define-command +helm:ag (beg end query &optional bang)
"TODO" "TODO"
(interactive "<r><a><!>") (interactive "<r><a><!>")
(let ((helm-ag-command-option (if bang " -n "))) (+helm--file-search beg end query nil
(+helm:ag beg end query t default-directory))) (if bang (list "-a" "--hidden"))))
;;;###autoload ;;;###autoload (autoload '+helm:ag-cwd "completion/helm/autoload/evil" nil t)
(defun +helm:rg (&rest _) (interactive) (error "Not implemented yet")) (evil-define-command +helm:ag-cwd (beg end query &optional bang)
;;;###autoload "TODO"
(defun +helm:rg-cwd (&rest _) (interactive) (error "Not implemented yet")) (interactive "<r><a><!>")
;;;###autoload (+helm--file-search beg end query default-directory
(defun +helm:todo (&rest _) (interactive) (error "Not implemented yet")) (list "-n" (if bang "-a"))))
;;;###autoload (autoload '+helm:rg "completion/helm/autoload/evil" nil t)
(evil-define-command +helm:rg (beg end query &optional bang)
"TODO"
(interactive "<r><a><!>")
(let ((helm-ag-base-command "rg --no-heading"))
(+helm--file-search beg end query nil
(if bang (list "-uu")))))
;;;###autoload (autoload '+helm:rg-cwd "completion/helm/autoload/evil" nil t)
(evil-define-command +helm:rg-cwd (beg end query &optional bang)
"TODO"
(interactive "<r><a><!>")
(let ((helm-ag-base-command "rg --no-heading --maxdepth 1"))
(+helm--file-search beg end query default-directory
(if bang (list "-uu")))))