If you use Icicles then you can use M-.
to insert text at or near the cursor into the minibuffer anytime.
So for example to run shell command my-shell-command
, passing it the filename (or whatever) at point you would type this:
M-x shell-command my-shell-command M-. RET
When you hit M-.
the thing at or near point is inserted, so the minibuffer content after the M-x
prompt becomes shell-command /foo/bar/hello.csv
.
Here is the doc string for M-.
:
icicle-insert-string-at-point is an interactive compiled Lisp function
in `icicles-mcmd.el'.
(icicle-insert-string-at-point &optional ARG)
Insert text at the cursor into the minibuffer.
Each time this command is called, some text at or near the cursor is
inserted into the minibuffer. One of two things happens, depending on
the value of option `icicle-default-thing-insertion' and whether or
not you use `C-u'.
See the doc for option `icicle-thing-at-point-functions' for a
complete description of its behavior. What follows is an overview.
`icicle-thing-at-point-functions' is a cons of two parts - call them
ALTERNATIVES and FORWARD-THING.
If ALTERNATIVES is not nil and one of the following is true:
- FORWARD-THING is nil
- the value of `icicle-default-thing-insertion' is `alternatives' and
you have not used plain `C-u' in this series of `M-.'
- the value of `icicle-default-thing-insertion' is `more-of-the-same'
and you have used plain `C-u' in this series of `M-.'
then the next function in ALTERNATIVES is used to retrieve the text to
be inserted.
If FORWARD-THING is not nil and one of the following is true:
- ALTERNATIVES is nil
- the value of `icicle-default-thing-insertion' is `more-of-the-same'
and you have not used `C-u' in this series of `M-.'
- the value of `icicle-default-thing-insertion' is `alternatives' and
you have used `C-u' in this series of `M-.'
then function FORWARD-THING is used to retrieve the text to be
inserted.
If you use a numeric prefix arg (not just plain `C-u'), the behavior
is as follows.
* If a function in ALTERNATIVES is used (see above), then the text
that is grabbed at or near point is read as a Lisp sexp and
evaluated, and the value is inserted instead of the grabbed text.
Yes, this means you need to know when the particular ALTERNATIVES
function that you want is coming up next, and use, say, `C-9' just
before hitting `M-.' for that alternative. So if, e.g., you want to
evaluate the active region and insert the value, then you use
`M-. C-9 M-.', since it is the second `M-.' that grabs the region.
* If the FORWARD-THING is being used, then the prefix arg determines
the number of things to grab, and the direction of grabbing.: A
negative argument grabs text to the left of the cursor; a positive
argument grabs text to the right.
You can use this command only from the minibuffer (`M-.').