From bef01b141931f80afeb9716ba199eaaa9d0c1505 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 22 Feb 2021 10:49:28 +0200 Subject: feat(tazjin/emacs): Add #'rg-in-project Uses project.el to anchor the ripgrep search. In combination with my project detection logic, this means that grepping in TVL subprojects works automatically. Change-Id: I2705466d1de156c08ff0401a71112864aa24f976 Reviewed-on: https://cl.tvl.fyi/c/depot/+/2542 Reviewed-by: tazjin Tested-by: BuildkiteCI --- users/tazjin/emacs/config/bindings.el | 3 +++ users/tazjin/emacs/config/functions.el | 8 ++++++++ users/tazjin/emacs/config/init.el | 3 +-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/users/tazjin/emacs/config/bindings.el b/users/tazjin/emacs/config/bindings.el index 7188bd3ef3..029aa2d0e5 100644 --- a/users/tazjin/emacs/config/bindings.el +++ b/users/tazjin/emacs/config/bindings.el @@ -34,6 +34,9 @@ ;; Open a file in project: (global-set-key (kbd "C-c f") 'project-find-file) +;; Search in a project +(global-set-key (kbd "C-c r g") 'rg-in-project) + ;; Open a file via magit: (global-set-key (kbd "C-c C-f") #'magit-find-file-worktree) diff --git a/users/tazjin/emacs/config/functions.el b/users/tazjin/emacs/config/functions.el index 74c737ad71..5963d142c1 100644 --- a/users/tazjin/emacs/config/functions.el +++ b/users/tazjin/emacs/config/functions.el @@ -317,4 +317,12 @@ the GPG agent correctly." (url-retrieve "https://songwhip.com/api/" #'songwhip--handle-result nil t t) (message "Requesting Songwhip URL ... please hold the line."))) +(defun rg-in-project (&optional prefix) + "Interactively call ripgrep in the current project, or fall + back to ripgrep default behaviour if prefix is set." + (interactive "P") + (counsel-rg nil (unless prefix + (if-let ((pr (project-current))) + (project-root pr))))) + (provide 'functions) diff --git a/users/tazjin/emacs/config/init.el b/users/tazjin/emacs/config/init.el index 158ee67d69..b473746fbe 100644 --- a/users/tazjin/emacs/config/init.el +++ b/users/tazjin/emacs/config/init.el @@ -45,8 +45,7 @@ (use-package counsel :after (ivy) - :config (counsel-mode 1) - :bind (("C-c r g" . counsel-rg))) + :config (counsel-mode 1)) (use-package dash) (use-package dash-functional) -- cgit 1.4.1