help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Insert word at point in minibuffer


From: Chat
Subject: Re: Insert word at point in minibuffer
Date: Fri, 15 Aug 2008 18:48:13 -0700
User-agent: Emacs Gnus

The Badger <address@hidden> writes:

> Hi,
>
> I wanted to be able to insert the word at point into the minibuffer.  This is
> useful when doing, for example, M-x query-replace on the word at point.  You
> run the query-replace, hit a key to put the current word into the minibuffer,
> and go from there.  Quite often I want to do this, so it saves time over 
> typing
> the word in over and over.
>
> My solution is presented below.  However, can this be done out of the box in
> Emacs?  The less custom code I have to write, the better.  God knows I have
> enough of that in Emacs already.
>
>
> (defun badger-minibuffer-yank-word ()
>  "Insert into the minibuffer the word at point in the selected
> window.  If invoked outside of the minibuffer, throw an error.
>
> A good way to use this function is to bind it to a key in
> mini-buffer-local-map, like so:
>
>  (define-key
>    minibuffer-local-map (kbd \"C-w\") 'njs-buffer-yank)
>
> If point is not at a word, throw an error."
>
>  (interactive)
>  (insert (njs-call-in-buffer (lambda () (thing-at-point 'word))
>                              (window-buffer (minibuffer-selected-window))))
>   (save-excursion
>     (set-buffer (window-buffer (minibuffer-selected-window)))
>     (thing-at-point 'word)))
> (define-key minibuffer-local-map (kbd "M-w") 'badger-minibuffer-yank-word)
Isn't it simpler to copy the text you want while in the buffer and then
invoke the command? Or even easier to use, write another function that calls
query-replace (or whatever command you want to call)?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]