From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: The Badger Newsgroups: gmane.emacs.help Subject: Re: Insert word at point in minibuffer Date: Mon, 18 Aug 2008 16:37:09 -0700 Message-ID: <48AA07A5.1020807@example.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------040305090806060505010600" X-Trace: ger.gmane.org 1219041442 9668 80.91.229.12 (18 Aug 2008 06:37:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 Aug 2008 06:37:22 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Chat Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 18 08:38:15 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KUyNY-0007im-Mx for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Aug 2008 08:38:13 +0200 Original-Received: from localhost ([127.0.0.1]:47135 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KUyMb-0005sz-HF for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Aug 2008 02:37:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KUyMH-0005sp-Cf for help-gnu-emacs@gnu.org; Mon, 18 Aug 2008 02:36:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KUyMF-0005sS-JN for help-gnu-emacs@gnu.org; Mon, 18 Aug 2008 02:36:52 -0400 Original-Received: from [199.232.76.173] (port=34053 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KUyMF-0005sP-DI for help-gnu-emacs@gnu.org; Mon, 18 Aug 2008 02:36:51 -0400 Original-Received: from bld-mail02.adl2.internode.on.net ([203.16.214.66]:40874 helo=mail.internode.on.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KUyME-0001tp-Qd for help-gnu-emacs@gnu.org; Mon, 18 Aug 2008 02:36:51 -0400 Original-Received: from [192.168.4.105] (unverified [59.167.83.3]) by mail.internode.on.net (SurgeMail 3.8f2) with ESMTP id 336618822-1927428 for multiple; Mon, 18 Aug 2008 16:06:44 +0930 (CST) User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) In-Reply-To: X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:56740 Archived-At: This is a multi-part message in MIME format. --------------040305090806060505010600 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Chat wrote: > The Badger 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. --------------040305090806060505010600 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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.
--------------040305090806060505010600--