From: The Badger <badgy@example.com>
To: Chat <chatter70.xspam@xspam.sbcglobal.net>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Insert word at point in minibuffer
Date: Mon, 18 Aug 2008 16:37:09 -0700 [thread overview]
Message-ID: <48AA07A5.1020807@example.com> (raw)
In-Reply-To: <ufxp5k9wi.fsf@ganesha.sbcglobal.net>
[-- Attachment #1: Type: text/plain, Size: 2591 bytes --]
Chat wrote:
> The Badger <badgy@example.com> 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)?
>
>
Copying the text, running (for example) query-replace, then pasting the
text requires the following steps:
C-M-SPC ;; mark-sexp
M-w ;; kill-ring-save
M-% ;; query-replace
C-y ;; yank
RET ;; newline
Running the command, then hitting my custom M-w key, requires the
following steps:
M-% ;; query-replace
M-C-w ;; badger-minibuffer-yank-sexp
RET ;; newline
So, there's 2 extra steps in there. Not a big deal, but I also tend to
invoke query-replace before I select the query text. Perhaps that's
because I think in English where the verb comes first in "replace dog
with cat"?
Also, regarding writing another function that calls query-replace;
that's a good idea, but I'm happy with my solution so far. I guess I
just want to be able to yank the word at point into the minibuffer -
this is re-usable in many situations - rather than a cooler, more
souped-up query-replace.
[-- Attachment #2: Type: text/html, Size: 3413 bytes --]
next prev parent reply other threads:[~2008-08-18 23:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.16858.1218833586.18990.help-gnu-emacs@gnu.org>
2008-08-16 1:48 ` Insert word at point in minibuffer Chat
2008-08-18 23:37 ` The Badger [this message]
2008-08-15 22:47 The Badger
2008-08-16 18:31 ` Nick Sandow
2008-08-16 6:43 ` Drew Adams
2008-08-19 0:20 ` Nick Sandow
2008-08-18 8:02 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48AA07A5.1020807@example.com \
--to=badgy@example.com \
--cc=chatter70.xspam@xspam.sbcglobal.net \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).