emacs 2025-05-08

do you know how I can grep a symbol at the cursor using vanilla emacs?

one option on vanilla is to do M-x rgrep

by default it takes the current symbol the cursor is on

I liked it, thanks

1

M-s . will start isearch-symbol with the symbol at point in the current buffer. C-x p g will start project-find-regexp with symbol at point by default

πŸš€ 1

Cool! That is a good way to do it, too, with fewer interactive prompts! Nice!

after starting M-s . you can also execute M-% to rename all occurrences, works like rename symbol πŸ™‚

4

after running project-find-regexp you can hit r in *xref* buffer to start project-wide query replace

also, there's always a way to insert a thing at point into minibuffer prompt by M-n

I use helm-ag package with ripgrep and the following hack to search for things under the cursor:

(defun helm-ag--insert-thing-at-point (thing)
    (helm-aif (thing-at-point thing)
        (s-replace-all '(("-" . "\\-")) (regexp-quote (substring-no-properties it)))
      ""))

(defun helm-do-ag-project-root-custom (sym-at-p)
    (interactive "P")
    (let ((helm-ag-base-command (if (equal current-prefix-arg '(16))
                                    helm-ag-base-command
                                  (concat helm-ag-base-command " -j1")))
          (helm-ag-insert-at-point (when sym-at-p 'symbol)))
      (helm-do-ag-project-root)))

βž• 1

@a13 what M-n stands for? In my emacs version v29.3 this keybinding is undefined

When you're in minibuffer, it's bound to next-history-element command, but if you're at the beginning of the history, it tries to predict your choice

πŸ‘ 1
πŸ‘πŸ½ 1

next-history-element is an interactive native-comp-function in
β€˜simple.el’.

(next-history-element N)

Inferred type: (function (t) t)

Insert into the minibuffer the Nth next element of minibuffer history.
Interactively, N is the prefix numeric argument and defaults to 1.
The value N can go beyond the current position in the minibuffer
history,  and invoke "future history."

and by default it inserts the entity at the point

I'd say it depends

if you use find-file command, M-n will insert the name of the current file

lot of learnings today

πŸ™Œ 1

@rrudakov in grep/search scenarios, it inserts the entity at point

btw, for counsel-find-file it inserts the thing at point, probably an ivy thing

yes, I'm just saying that this command is quite powerful and it's worth trying it in different scenarios πŸ™‚