2

I'd like to create two keybindings for helm-do-ag-project-root or helm-project-ag

where one would have (setq helm-ag-insert-at-point nil) and one would have (setq helm-ag-insert-at-point 'symbol)

So that I can selectively use word at-point for search.

Below is my attempt but not working.

 (use-package helm-projectile
   :ensure t
   :config

    (defun my-helm-grep-do-git-grep ()
      (setq helm-ag-insert-at-point nil)
      (helm-projectile-ag)
      )
    (global-set-key (kbd "C-c g") 'my-helm-grep-do-git-grep)

    (defun my-helm-grep-do-git-grep-at-point ()
      (setq helm-ag-insert-at-point 'symbol)
      (helm-projectile-ag)
      )
    (global-set-key (kbd "C-c k") 'my-helm-grep-do-git-grep-at-point)


   )
eugene
  • 481
  • 1
  • 5
  • 11
  • See this for an alternative solution which always inserts the symbol, but lets you overtype it if you don't want it: https://emacs.stackexchange.com/a/53219/2498 – Tom Jan 15 '20 at 16:04

3 Answers3

1

This worked fine for me when I was using helm-ag:

(defun mu-helm-ag-thing-at-point ()
  "Search the symbol at point with `helm-ag'."
  (interactive)
  (let ((helm-ag-insert-at-point 'symbol))
    (helm-do-ag-project-root)))
Manuel Uberti
  • 3,150
  • 18
  • 36
0

You should make your functions interactive (see here).

You could also try the helm-grep-do-git-grep command, which I think is a lot smarter at solving this issue. For example, it always searches the symbol at point if it finds one, but as soon as you start typing the Helm buffer updates automatically to display the new candidates.

jagrg
  • 3,824
  • 4
  • 19
0

In Helm, M-n can be used to select thing at point. In most cases.

Stefan
  • 26,154
  • 3
  • 46
  • 84
RichieHH
  • 848
  • 4
  • 9