4

I'm using swiper for searching, one thing i very much miss compared to isearch is to insert the word at point into swiper. I have icicles installed, but M-., which i usally use to insert word at point into the current minifbuffer, doesn't seem to work.

I found some code in the emacs wiki

(define-key swiper-map (kbd "M-.")
  (lambda () (interactive) (insert (format "\\<%s\\>" (with-ivy-window (thing-at-point 'word))))))

That seemed to basically do what I want, except it doesn't really work. It inserts the text with <> surrounded (ok, i could fix that) and multiple calls to M-. don't continue inserting the next word(s) into swiper.

Therefore I wonder if there is any canonical solution to this, if swiper already provides the functionality to insert word at point into the search, then I didn't find it in the documentation.

1

3 Answers 3

2

Its not quite the word at point, but M-j puts the current subword in the minibuffer. If you are at the beginning of the word, it puts the word in.

2
  • Thank you, that is very useful. Is it a swiper feature? Do you know if i can rebind it to M-. would make the shortcut more consistent with how I use icicles.
    – Max
    Nov 7, 2016 at 2:14
  • it is a swiper feature. It runs (ivy-yank-word) Nov 7, 2016 at 3:25
6

You can insert symbol at point with M-n - the same key as the history forward, which is one of the recommended Emacs workflows for inserting thing at point.

Additionally, M-j will extend the minibuffer by word at point, similar to what C-w does for isearch.

0
  1. What happens if you just remove any other (e.g. swiper) binding of M-.? For example, if you do (define-key swiper-map (kbd "M-.") nil).

I'm guessing that won't help, because this is a minibuffer keymap binding, not a swiper-map binding, but you can try it.

  1. Icicle mode binds M-. in the minibuffer keymaps. If you turn on swiper after you turn on Icicle mode (icy-mode) then swiper might change minibuffer keymap bindings.

In that case, you should be able to get back the Icicles M-. behavior by toggling Icicle mode off and on again. Try that, to see if it works for M-..

That might not be the ultimate solution, because Icicle mode might change some minibuffer keys that swiper expects, but at least it will tell you what's going on.

  1. If that's what's happening, then the thing to do is probably to explicitly bind M-. on some swiper mode hook: Just bind it in each of the minibuffer keymaps to command icicle-insert-string-at-point. IOW, after swiper does its thing, binding M-. to whatever, you have it bind it back to the Icicles command.

(Because some minibuffer maps inherit from some other minibuffer maps, you need not bind it in all of the maps, but that depends on your Emacs version. The simplest thing is to just bind it in all of the minibuffer maps.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.