* Writing an interactive function to accept a string argument, then call a Python script?
@ 2007-02-09 13:08 Endless Story
2007-02-09 14:18 ` Stack
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Endless Story @ 2007-02-09 13:08 UTC (permalink / raw)
To: help-gnu-emacs
I have hacked out a Python script to do something trivial but
reasonably valuable to me (search a bunch of files for a matching
string pulled from another file). Well, okay, now I want to call this
script from the Emacs minibuffer ... but my understanding of lisp is
pretty poor, which is why I wrote the script in Python to begin with!
(took me a couple of hours instead of a month).
Can anyone give me a simple recipe for an interactive function that
will do the following:
1) In the minibuffer, prompt me for a string to enter.
2) Feed the string as the sole argument to the Python script (let's
say it's at /home/me/myscript.py).
3) Display the return value in the minibuffer
Much thanks -
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing an interactive function to accept a string argument, then call a Python script?
2007-02-09 13:08 Writing an interactive function to accept a string argument, then call a Python script? Endless Story
@ 2007-02-09 14:18 ` Stack
2007-02-10 8:49 ` Kevin Rodgers
[not found] ` <mailman.4285.1171097378.2155.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 7+ messages in thread
From: Stack @ 2007-02-09 14:18 UTC (permalink / raw)
To: help-gnu-emacs
"Endless Story" <usable.thought@gmail.com> writes:
> 1) In the minibuffer, prompt me for a string to enter.
> 2) Feed the string as the sole argument to the Python script (let's
> say it's at /home/me/myscript.py).
> 3) Display the return value in the minibuffer
Try M-x shell-command
Cheers,
Stack
--
"This is no longer a slum neighbourhood. I haven't heard of a Cubs fan
being shot in a long time."
- Anonymous Wrigley Field Neighbour, Chicago, IL
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing an interactive function to accept a string argument, then call a Python script?
2007-02-09 13:08 Writing an interactive function to accept a string argument, then call a Python script? Endless Story
2007-02-09 14:18 ` Stack
@ 2007-02-10 8:49 ` Kevin Rodgers
[not found] ` <mailman.4285.1171097378.2155.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2007-02-10 8:49 UTC (permalink / raw)
To: help-gnu-emacs
Endless Story wrote:
> I have hacked out a Python script to do something trivial but
> reasonably valuable to me (search a bunch of files for a matching
> string pulled from another file). Well, okay, now I want to call this
> script from the Emacs minibuffer ... but my understanding of lisp is
> pretty poor, which is why I wrote the script in Python to begin with!
> (took me a couple of hours instead of a month).
>
> Can anyone give me a simple recipe for an interactive function that
> will do the following:
>
> 1) In the minibuffer, prompt me for a string to enter.
> 2) Feed the string as the sole argument to the Python script (let's
> say it's at /home/me/myscript.py).
> 3) Display the return value in the minibuffer
(defun trivial-but-reasonably-valuable (string-to-match)
(interactive "sMatch: ")
(shell-command (format "/home/me/myscript.py %s"
(shell-quote-argument string-to-match))))
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing an interactive function to accept a string argument, then call a Python script?
[not found] ` <mailman.4285.1171097378.2155.help-gnu-emacs@gnu.org>
@ 2007-02-10 10:57 ` Endless Story
2007-02-13 6:20 ` Kevin Rodgers
[not found] ` <mailman.4406.1171347657.2155.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 7+ messages in thread
From: Endless Story @ 2007-02-10 10:57 UTC (permalink / raw)
To: help-gnu-emacs
On Feb 10, 8:49 am, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> Endless Story wrote:
> (defun trivial-but-reasonably-valuable (string-to-match)
> (interactive "sMatch: ")
> (shell-command (format "/home/me/myscript.py %s"
> (shell-quote-argument string-to-match))))
Thanks! Below is what I ended up writing (after only 90 minutes of
Googling!!) - now I'm going to try your suggestion of adding shell-
quote-argument (which I gather from the doco does nice things like
escape characters as necessary). Maybe it will obviate the need to
remind the user (me) to use double quotes around multi-word input.
Boy, lisp is SO different than anything else I'm used to ...
(defun wl-psb (searchname)
(interactive"MName to search for, double-quoted: ")
(shell-command (concat "python c:/cygwin/home/texas/name_search.py
" searchname)))
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing an interactive function to accept a string argument, then call a Python script?
2007-02-10 10:57 ` Endless Story
@ 2007-02-13 6:20 ` Kevin Rodgers
[not found] ` <mailman.4406.1171347657.2155.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 7+ messages in thread
From: Kevin Rodgers @ 2007-02-13 6:20 UTC (permalink / raw)
To: help-gnu-emacs
Endless Story wrote:
> On Feb 10, 8:49 am, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
>> Endless Story wrote:
>> (defun trivial-but-reasonably-valuable (string-to-match)
>> (interactive "sMatch: ")
>> (shell-command (format "/home/me/myscript.py %s"
>> (shell-quote-argument string-to-match))))
>
> Thanks! Below is what I ended up writing (after only 90 minutes of
> Googling!!) - now I'm going to try your suggestion of adding shell-
> quote-argument (which I gather from the doco does nice things like
> escape characters as necessary). Maybe it will obviate the need to
> remind the user (me) to use double quotes around multi-word input.
Yep.
> Boy, lisp is SO different than anything else I'm used to ...
In a a good way, I'm sure, unless you're used to modern functional
languages.
> (defun wl-psb (searchname)
> (interactive"MName to search for, double-quoted: ")
> (shell-command (concat "python c:/cygwin/home/texas/name_search.py
> " searchname)))
Just curious: Is the `M' interactive code necessary in your experience?
I've always just used `s'.
--
Kevin Rodgers
Denver, Colorado, USA
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing an interactive function to accept a string argument, then call a Python script?
[not found] ` <mailman.4406.1171347657.2155.help-gnu-emacs@gnu.org>
@ 2007-02-13 11:21 ` Endless Story
2007-02-14 17:32 ` Edward Dodge
0 siblings, 1 reply; 7+ messages in thread
From: Endless Story @ 2007-02-13 11:21 UTC (permalink / raw)
To: help-gnu-emacs
On Feb 13, 6:20 am, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
>
> Just curious: Is the `M' interactive code necessary in your experience?
> I've always just used `s'.
Well, since I was hacking it out blindly, I grabbed the first thing I
saw in the GNU Emacs Lisp Reference Manual that looked like it should
work. I guess M is fancier than s, but both will work in this instance
- from the manual:
'M'
Arbitrary text, read in the minibuffer using the current buffer's
input method,
and returned as a string (see Input Methods). Prompt.
's'
Arbitrary text, read in the minibuffer and returned as a string
(see Text from
Minibuffer). Terminate the input with either C-j or <RET>. (C-q
may be used
to include either of these characters in the input.) Prompt.
Meanwhile, since you're into lisp, I have a question for you: Would
there be any real advantage to my learning it, aside from customizing
Emacs beyond the things that other people have done that I can find on
the Web? My impression is that the answer is no. I'm really just a
writer who stumbled into scripting by accident, during a few years
when I was documenting software as a technical writer. I enjoy
fiddling with code mostly to automate various things I do with text
processing. Python has been perfect for this purpose - easy to learn,
easy to put down and then pick up again every few months as needed. I
once thought about learning lisp - in fact I went so far as to buy
"The Little Schemer" - but in the end I decided I could no more afford
to take the time to learn it than I could continue to learn C, which I
once dabbled in briefly for fun.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Writing an interactive function to accept a string argument, then call a Python script?
2007-02-13 11:21 ` Endless Story
@ 2007-02-14 17:32 ` Edward Dodge
0 siblings, 0 replies; 7+ messages in thread
From: Edward Dodge @ 2007-02-14 17:32 UTC (permalink / raw)
To: help-gnu-emacs
> Meanwhile, since you're into lisp, I have a question for you: Would
> there be any real advantage to my learning it, aside from
> customizing Emacs beyond the things that other people have done that
> I can find on the Web? My impression is that the answer is no.
I can't speak for Mr. Rodgers, but I just started learning Lisp in
earnest these past couple of months. And I find the study
fascinating, and useful. Of course it helps that I use a CAD program
at work with a Lisp dialect as its extension language. Without this
excuse to learn Lisp, I'm not sure I be so studious, even though I
also happen to be a die-hard Emacs-user.
If you want to hear some interesting stories about how cool Lisp is
and how useful it can be, I recommend a sampling of the entries at
this site:
http://wiki.alu.org/The_Road_to_Lisp_Survey
Some of these stories helped me on my current path to learning Lisp by
helping me to understand that it's okay to learn Lisp. True, it's not
the acclaimed Language Du Jour, but it can still be an important and
powerful skill in your programming/computing experience. If you want
to see a good example of that in a man who is both a writer and a
programmer, check out this blog:
http://www.paulgraham.com/index.html
> I'm really just a writer who stumbled into scripting by accident,
> during a few years when I was documenting software as a technical
> writer. I enjoy fiddling with code mostly to automate various things
> I do with text processing. Python has been perfect for this purpose
> - easy to learn, easy to put down and then pick up again every few
> months as needed. I once thought about learning lisp - in fact I
> went so far as to buy "The Little Schemer" - but in the end I
> decided I could no more afford to take the time to learn it than I
> could continue to learn C, which I once dabbled in briefly for fun.
I tried "The Little Lisper" and found it helped clear up the concept
of recursion. But what is really helping me stay focussed on learning
the language as a practical matter is a book that is aptly titled
"Practical Common Lisp" by Peter Seibel. The full text of the book is
available for free online:
http://www.gigamonkeys.com/book/
I bought the dead-tree edition for reading and study away from the
computer.
--
Edward Dodge
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-02-14 17:32 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-09 13:08 Writing an interactive function to accept a string argument, then call a Python script? Endless Story
2007-02-09 14:18 ` Stack
2007-02-10 8:49 ` Kevin Rodgers
[not found] ` <mailman.4285.1171097378.2155.help-gnu-emacs@gnu.org>
2007-02-10 10:57 ` Endless Story
2007-02-13 6:20 ` Kevin Rodgers
[not found] ` <mailman.4406.1171347657.2155.help-gnu-emacs@gnu.org>
2007-02-13 11:21 ` Endless Story
2007-02-14 17:32 ` Edward Dodge
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).