all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Insert word at point in minibuffer
@ 2008-08-15 22:47 The Badger
  2008-08-16 18:31 ` Nick Sandow
  0 siblings, 1 reply; 7+ messages in thread
From: The Badger @ 2008-08-15 22:47 UTC (permalink / raw)
  To: help-gnu-emacs

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)




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Insert word at point in minibuffer
       [not found] <mailman.16858.1218833586.18990.help-gnu-emacs@gnu.org>
@ 2008-08-16  1:48 ` Chat
  2008-08-18 23:37   ` The Badger
  0 siblings, 1 reply; 7+ messages in thread
From: Chat @ 2008-08-16  1:48 UTC (permalink / raw)
  To: help-gnu-emacs

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)?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Insert word at point in minibuffer
  2008-08-16 18:31 ` Nick Sandow
@ 2008-08-16  6:43   ` Drew Adams
  2008-08-19  0:20     ` Nick Sandow
  0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2008-08-16  6:43 UTC (permalink / raw)
  To: 'Nick Sandow', 'The Badger'; +Cc: help-gnu-emacs

> yank into the minibuffer the word at point.
> 
> Really, what I want to know is, can this be done "out of the 
> box" in Emacs?


1. I don't believe that Emacs has anything that lets you do this out of the box.

There have been discussions in emacs-devel@gnu.org about providing such a
facility - see, for instance,
http://lists.gnu.org/archive/html/emacs-devel/2006-02/msg01074.html. But nothing
has come of it so far, AFAIK.


2. Sometimes commands provide some text at or near the cursor as the default
value, which can be inserted in the minibuffer using `M-n'.

The OP mentioned `query-replace', for instance. The versions of commands such as
`query-replace' provided by library `replace+.el' do this - see
http://www.emacswiki.org/cgi-bin/wiki/ReplacePlus. Library ffap.el does this for
file names and URLs at point - see
http://www.emacswiki.org/cgi-bin/wiki/FindFileAtPoint.


3. The code you sent generalizes this idea, letting you insert some text at
point into the minibuffer at any time.

Icicles does this too, but you can also repeat the key (`M-.') to retrieve and
insert additional bits of text (e.g. words, filenames, etc.) successively, or
you can repeat it to retrieve alternative kinds of thing (words, filenames,
etc.) at point. See
http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Inserting_Text_from_Cursor.






^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Insert word at point in minibuffer
  2008-08-15 22:47 The Badger
@ 2008-08-16 18:31 ` Nick Sandow
  2008-08-16  6:43   ` Drew Adams
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Sandow @ 2008-08-16 18:31 UTC (permalink / raw)
  To: The Badger; +Cc: help-gnu-emacs

Hello again,

Actually, the code below is broken.  Allow me to try posting that 
again.  As mentioned before, this allows you to yank into the minibuffer 
the word at point.

Really, what I want to know is, can this be done "out of the box" in Emacs?

Here's the code:

(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\") 'badger-minibuffer-yank-word)

If point is not at a word, throw an error."
  (interactive)
  (insert (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)

The Badger wrote:
> 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)
>
>
>




^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: Insert word at point in minibuffer
  2008-08-19  0:20     ` Nick Sandow
@ 2008-08-18  8:02       ` Drew Adams
  0 siblings, 0 replies; 7+ messages in thread
From: Drew Adams @ 2008-08-18  8:02 UTC (permalink / raw)
  To: 'Nick Sandow'; +Cc: help-gnu-emacs, 'The Badger'

> Thanks for some useful links.  I will definitely check out
> replace+.el and icicles.  Icicles in particular seems to
> offer a lot of functionality and thus may take some time to digest.

You don't need to consume and digest it all - just take a bite and see if you
like the taste.

It's like the rest of Emacs: you can dig deeper later if you want, but you don't
need to. You should be able to get some benefit right away, in complete
ignorance and with no practice.
	
> Will any of this stuff end up in Emacs itself?

I doubt it.

The good news is that it is easy to customize Emacs the way you like. Getting
others to agree that some of your customizations should be made part of vanilla
Emacs is a different ball game. But you can still share with others who do
appreciate them, and thanks to free source code and language extensibility it is
easy to do so. The Emacs Wiki is a great tool/medium in this regard.

> It seems to me some things - such as M-x query-replace
> suggesting a default where currently it does not - are just plain
> good ideas.

There are lots of good Emacs ideas (and bad) that never find their way into
Emacs.

If you are interested, please consider adding your voice to the discussions at
emacs-devel@gnu.org. If you do, don't get frustrated if you find that some of
your suggestions are not greeted with wild enthusiasm all around. Suggestions
are always welcome, especially from new sources, but the discussion can
unfortunately sometimes lead to more heat than light. Patience, perseverence,
and a thick skin help.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Insert word at point in minibuffer
  2008-08-16  1:48 ` Insert word at point in minibuffer Chat
@ 2008-08-18 23:37   ` The Badger
  0 siblings, 0 replies; 7+ messages in thread
From: The Badger @ 2008-08-18 23:37 UTC (permalink / raw)
  To: Chat; +Cc: help-gnu-emacs

[-- 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 --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Insert word at point in minibuffer
  2008-08-16  6:43   ` Drew Adams
@ 2008-08-19  0:20     ` Nick Sandow
  2008-08-18  8:02       ` Drew Adams
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Sandow @ 2008-08-19  0:20 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs, 'The Badger'

[-- Attachment #1: Type: text/plain, Size: 1796 bytes --]

Drew Adams wrote:
>> yank into the minibuffer the word at point.
>>
>> Really, what I want to know is, can this be done "out of the 
>> box" in Emacs?
>>     
>
>
> 1. I don't believe that Emacs has anything that lets you do this out of the box.
>
> There have been discussions in emacs-devel@gnu.org about providing such a
> facility - see, for instance,
> http://lists.gnu.org/archive/html/emacs-devel/2006-02/msg01074.html. But nothing
> has come of it so far, AFAIK.
>
>
> 2. Sometimes commands provide some text at or near the cursor as the default
> value, which can be inserted in the minibuffer using `M-n'.
>
> The OP mentioned `query-replace', for instance. The versions of commands such as
> `query-replace' provided by library `replace+.el' do this - see
> http://www.emacswiki.org/cgi-bin/wiki/ReplacePlus. Library ffap.el does this for
> file names and URLs at point - see
> http://www.emacswiki.org/cgi-bin/wiki/FindFileAtPoint.
>
>
> 3. The code you sent generalizes this idea, letting you insert some text at
> point into the minibuffer at any time.
>
> Icicles does this too, but you can also repeat the key (`M-.') to retrieve and
> insert additional bits of text (e.g. words, filenames, etc.) successively, or
> you can repeat it to retrieve alternative kinds of thing (words, filenames,
> etc.) at point. See
> http://www.emacswiki.org/cgi-bin/wiki/Icicles_-_Inserting_Text_from_Cursor.
>
>
>   
Thanks for some useful links.  I will definitely check out replace+.el 
and icicles.  Icicles in particular seems to offer a lot of 
functionality and thus may take some time to digest.

Will any of this stuff end up in Emacs itself?  It seems to me some 
things - such as M-x query-replace suggesting a default where currently 
it does not - are just plain good ideas.

cheers


[-- Attachment #2: Type: text/html, Size: 2669 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-08-19  0:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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
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

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.