It's a simple thing. My cursor is over a word and I want to get the word so that I can do something with it. I see a few different ways to do this but want to avoid reinvention and use a standard method.
-
1The question is unclear. Do something with it where? In a program (code)? Interactively? Both? What kind of something? – Drew Nov 3 '16 at 16:07
-
"Read" in Emacs and Emacs Lisp generally means read interactively or read (load) Lisp code. I've edited the question to say "get" the word instead of "read" it. – Drew Nov 3 '16 at 16:14
-
What does "get the word" mean? Do you want a Lisp expression whose value is a string contianing the word? Do you want to mark the word? Do you want to put the word in the kill ring? – Omar Nov 4 '16 at 4:59
You can use the function thing-at-point
and tell it to return the word
at point and not return any text properties (unless you need them). Example buffer contents (| is the cursor):
Hello wor|ld
Calling (thing-at-point 'word 'no-properties)
returns "world".
(current-word &optional STRICT REALLY-WORD)
Return the word at or near point, as a string. The return value includes no text properties.
If you want to insert the word (or anything else - file name etc.) at point into the minibuffer, when you are editing input, just use M-.
, if you use Icicles.
See Inserting Text from Cursor.
You can use M-.
repeatedly (e.g. M-. M-. M-.
) to either:
- Cycle to a different kind of thing to grab at point, and insert it.
- Insert more (i.e., successive) things of the same type (e.g. words) from the buffer.