5

How can I insert some text (thing) at point from the buffer into the minibuffer at a text prompt or during an incremental search? Is there a convenient way to insert, e.g., the sexp around point?

  • 2
    Can you elaborate your use case? In the case you are trying to search for the thing at point (guessed from the isearch tag that you added), you can do M-s . C-s in emacs 24.4. – Kaushal Modi Dec 14 '14 at 5:13
  • For example with el-get-install. Surely I can install from package-menu buffer, but it not so quick. Or for grep commands. – Netsu Dec 14 '14 at 8:48
  • 2
    No reason to be sorry. Many, maybe most, users have the same mistaken impression. What Isearch does is complicated. It sets overriding-terminal-local-map temporarily, so it interprets each input char/event its own way. It binds cursor-in-echo-area, to show the cursor in the echo area. And it uses message to show the "prompt" and the current search string in the echo area. In short, it uses the echo area (an output area) instead of the minibuffer (an input area). – Drew Dec 14 '14 at 21:23
  • 1
    OK, I've edited the question to make it clear that this is about inserting buffer text into the minibuffer, not yanking buffer text onto the Isearch search string. – Drew Dec 15 '14 at 15:14
  • 1
    Create different questions. Each question post should pose a single, clear question. Thx. – Drew Dec 15 '14 at 15:43
7

If you use library Icicles then you can use M-. at any time from the minibuffer to insert a thing-at-point from the buffer.

You can repeat M-. to either (a) append subsequent such things from the buffer or (b) change the kind of thing, inserting a different kind instead (cycling through thing types). This is explained at Icicles - Inserting Text from Cursor.

If you use library ThingAtPoint+ (thingatpt+.el) then you can grab additional kinds of thing, and you can grab them near point as well as at point.


Keep in mind that none of this has to do with Isearch, which does not in fact use the minibuffer (except when you use M-e, to edit the search string).

If you want to grab (yank) a thing at point and append it to your Isearch search string, you can use library Isearch+ (isearch+.el) to yank these kinds of thing:

  • C-y C-_ isearchp-yank-symbol-or-char
  • C-y C-( isearchp-yank-sexp-symbol-or-char
  • C-y C-c isearchp-yank-char
  • C-y C-e isearchp-yank-line
  • C-y C-w isearchp-yank-word-or-char

And you can define your own yank command that yanks whatever you want from the buffer. For example, you can have it move point around temporarily and grab, for example, the full word (or sexp or whatever) that point is in. See the definitions of other Isearch yank commands for how this is done. It is quite simple, but since you do not specify what behavior you are after there is little sense in showing code here that tries to guess what that is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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