From 6facc534ce4023e18f25d03c6636ca9a1ab76d98 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 5 Dec 2019 16:10:46 -0500 Subject: [PATCH] completion/helm: replace helm-ag with helm-rg --- modules/completion/helm/autoload/helm.el | 52 ++++++------------------ modules/completion/helm/config.el | 18 ++++---- modules/completion/helm/packages.el | 2 +- 3 files changed, 22 insertions(+), 50 deletions(-) diff --git a/modules/completion/helm/autoload/helm.el b/modules/completion/helm/autoload/helm.el index 70105d239..ec741c093 100644 --- a/modules/completion/helm/autoload/helm.el +++ b/modules/completion/helm/autoload/helm.el @@ -51,46 +51,18 @@ workspace." (declare (indent defun)) (unless (executable-find "rg") (user-error "Couldn't find ripgrep in your PATH")) - (require 'helm-ag) - (helm-ag--init-state) - (let* ((project-root (or (doom-project-root) default-directory)) - (directory (or in project-root)) - (default-directory directory) - (helm-ag--default-directory directory) - (helm-ag--default-target (list directory)) - (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 "[rg %s] " - (cond ((file-equal-p directory project-root) - (projectile-project-name)) - ((file-equal-p directory default-directory) - "./") - ((file-relative-name directory project-root))))) - (command - (list "rg --no-heading --line-number --color never" - "-S" - (when all-files "-z -uu") - (unless recursive "--maxdepth 1"))) - (helm-ag-base-command (string-join (delq nil command) " "))) - ;; TODO Define our own sources instead - (helm-attrset 'name (format "[rg %s] Searching %s" - (string-join (delq nil (cdr command)) " ") - (abbreviate-file-name directory)) - helm-source-do-ag) - (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-rg*" - :keymap helm-do-ag-map - :input query - :history 'helm-ag--helm-history)))) - (helm-do-ag directory)))) + (require 'helm-rg) + (let ((helm-rg-default-directory (or in (doom-project-root) default-directory)) + (helm-rg-default-extra-args + (delq nil (list (when all-files "-z -uu") + (unless recursive "--maxdepth 1"))))) + (helm-rg (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) + (buffer-substring-no-properties beg end)))) + "")))) ;;;###autoload (defun +helm/project-search (&optional arg initial-query directory) diff --git a/modules/completion/helm/config.el b/modules/completion/helm/config.el index 071c33335..7ee5d35a5 100644 --- a/modules/completion/helm/config.el +++ b/modules/completion/helm/config.el @@ -77,7 +77,6 @@ be negative.") (let ((fuzzy (featurep! +fuzzy))) (setq helm-M-x-fuzzy-match fuzzy - helm-ag-fuzzy-match fuzzy helm-apropos-fuzzy-match fuzzy helm-apropos-fuzzy-match fuzzy helm-bookmark-show-location fuzzy @@ -125,14 +124,15 @@ be negative.") :config (helm-flx-mode +1)) -(after! helm-ag - (map! :map helm-ag-edit-map :n "RET" #'compile-goto-error) - (define-key helm-ag-edit-map [remap quit-window] #'helm-ag--edit-abort) - (set-popup-rule! "^\\*helm-ag-edit" :size 0.35 :ttl 0 :quit nil) - ;; Recenter after jumping to match - (advice-add #'helm-ag--find-file-action :after-while #'doom-recenter-a) - ;; And record position before jumping - (advice-add #'helm-ag--find-file-action :around #'doom-set-jump-maybe-a)) +(after! helm-rg + (set-popup-rule! "^helm-rg-" :ttl nil :select t :size 0.45) + (map! :map helm-rg-map + "C-c C-e" #'helm-rg--bounce) + (map! :map helm-rg--bounce-mode-map + "q" #'kill-current-buffer + "C-c C-c" (λ! (helm-rg--bounce-dump) (kill-current-buffer)) + "C-x C-c" #'helm-rg--bounce-dump-current-file + "C-c C-k" #'kill-current-buffer)) ;;;###package helm-bookmark diff --git a/modules/completion/helm/packages.el b/modules/completion/helm/packages.el index eb343b566..4bfb434f0 100644 --- a/modules/completion/helm/packages.el +++ b/modules/completion/helm/packages.el @@ -2,7 +2,7 @@ ;;; completion/helm/packages.el (package! helm) -(package! helm-ag) +(package! helm-rg) (package! helm-c-yasnippet) (package! helm-company) (package! helm-describe-modes :recipe (:host github :repo "emacs-helm/helm-describe-modes"))