* sending commands to shell with emacs lisp
@ 2009-09-13 5:15 Corey Foote
2009-09-13 5:45 ` tomas
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Corey Foote @ 2009-09-13 5:15 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 548 bytes --]
I'm trying to send commands to a shell buffer. I'm able to send the command "hello world" by calling this:
(defun exec-command ()
(interactive)
(set-buffer (get-buffer "*shell*"))
(insert "hello world"))
But I can't figure out how to send over the "enter key" to actually make it execute the shell command. I'm an emacs lisp newbie!
Thanks everybody!
- Corey
_________________________________________________________________
Hotmail: Free, trusted and rich email service.
http://clk.atdmt.com/GBL/go/171222984/direct/01/
[-- Attachment #2: Type: text/html, Size: 760 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: sending commands to shell with emacs lisp
2009-09-13 5:15 sending commands to shell with emacs lisp Corey Foote
@ 2009-09-13 5:45 ` tomas
2009-09-13 6:43 ` Corey Foote
[not found] ` <mailman.6560.1252824219.2239.help-gnu-emacs@gnu.org>
2009-09-13 6:55 ` Thierry Volpiatto
[not found] ` <mailman.6558.1252820105.2239.help-gnu-emacs@gnu.org>
2 siblings, 2 replies; 8+ messages in thread
From: tomas @ 2009-09-13 5:45 UTC (permalink / raw)
To: Corey Foote; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sun, Sep 13, 2009 at 01:15:38AM -0400, Corey Foote wrote:
>
> I'm trying to send commands to a shell buffer. I'm able to send the command "hello world" by calling this:
>
> (defun exec-command ()
> (interactive)
> (set-buffer (get-buffer "*shell*"))
> (insert "hello world"))
>
> But I can't figure out how to send over the "enter key" to actually make it execute the shell command. I'm an emacs lisp newbie!
I think what you are looking for is "call-process" and "start-process".
Evaluating
(call-process "ls" nil t t "-l")
for example, you get the current directory listing in long form inserted
at point into the current buffer.
(call-process waits for the process to terminate, while start-process
just lets the process run while Emacs goes on with its other tasks).
There are so many options and variants that I'll stop here and refer you
to the documentation -- but do ask here if you get stuck.
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFKrIbkBcgs9XrR2kYRAvHvAJ4iqHDOcRWoJz+861efBHlUMn9qBACfRUgI
pjtfndJKqUQ6W7HTCkmtGgg=
=V2HY
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: sending commands to shell with emacs lisp
2009-09-13 5:45 ` tomas
@ 2009-09-13 6:43 ` Corey Foote
2009-09-13 10:21 ` tomas
[not found] ` <mailman.6560.1252824219.2239.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 8+ messages in thread
From: Corey Foote @ 2009-09-13 6:43 UTC (permalink / raw)
To: tomas, help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1977 bytes --]
Thanks, but I really am just looking for a way to send an "enter" keystroke to my *shell* buffer after I've inserted a command. I'm just trying to save myself a few keystrokes in my edit, compile, execute cycle.
> Date: Sun, 13 Sep 2009 07:45:08 +0200
> From: tomas@tuxteam.de
> To: coreyfoote@hotmail.com
> CC: help-gnu-emacs@gnu.org
> Subject: Re: sending commands to shell with emacs lisp
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Sun, Sep 13, 2009 at 01:15:38AM -0400, Corey Foote wrote:
> >
> > I'm trying to send commands to a shell buffer. I'm able to send the command "hello world" by calling this:
> >
> > (defun exec-command ()
> > (interactive)
> > (set-buffer (get-buffer "*shell*"))
> > (insert "hello world"))
> >
> > But I can't figure out how to send over the "enter key" to actually make it execute the shell command. I'm an emacs lisp newbie!
>
> I think what you are looking for is "call-process" and "start-process".
>
> Evaluating
>
> (call-process "ls" nil t t "-l")
>
> for example, you get the current directory listing in long form inserted
> at point into the current buffer.
>
> (call-process waits for the process to terminate, while start-process
> just lets the process run while Emacs goes on with its other tasks).
>
> There are so many options and variants that I'll stop here and refer you
> to the documentation -- but do ask here if you get stuck.
>
> Regards
> - -- tomás
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFKrIbkBcgs9XrR2kYRAvHvAJ4iqHDOcRWoJz+861efBHlUMn9qBACfRUgI
> pjtfndJKqUQ6W7HTCkmtGgg=
> =V2HY
> -----END PGP SIGNATURE-----
_________________________________________________________________
Ready for Fall shows? Use Bing to find helpful ratings and reviews on digital tv's.
http://www.bing.com/shopping/search?q=digital+tv's&form=MSHNCB&publ=WLHMTAG&crea=TEXT_MSHNCB_Vertical_Shopping_DigitalTVs_1x1
[-- Attachment #2: Type: text/html, Size: 2401 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: sending commands to shell with emacs lisp
2009-09-13 5:15 sending commands to shell with emacs lisp Corey Foote
2009-09-13 5:45 ` tomas
@ 2009-09-13 6:55 ` Thierry Volpiatto
[not found] ` <mailman.6558.1252820105.2239.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 8+ messages in thread
From: Thierry Volpiatto @ 2009-09-13 6:55 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
Corey Foote <coreyfoote@hotmail.com> writes:
> I'm trying to send commands to a shell buffer. I'm able to send the command "hello world" by calling this:
>
> (defun exec-command ()
> (interactive)
> (set-buffer (get-buffer "*shell*"))
> (insert "hello world"))
You probably want:
,----
| (with-current-buffer "*shell*"
| (goto-char (point-max))
| (insert "echo hello world"))
`----
Or
,----
| (switch-to-buffer "*shell*"
| (goto-char (point-max))
| (insert "echo hello world"))
`----
All that assume shell is started.
If not just run the shell you want from your function before inserting.
If you want a complete mode to send commands to a shell (even an xterm)
from emacs, have a look at eev-mode.
http://www.emacswiki.org/cgi-bin/wiki/EevMode
> But I can't figure out how to send over the "enter key" to actually make it execute the shell command. I'm an emacs lisp newbie!
If you use eshell as shell, the command is `eshell-send-input', but i
think it's better to use enter to be sure you really want to send the
command inserted.
But maybe what you only need is instead of all that is:
(shell-command "echo hello world")
Put point at end of this expression and hit C-x C-e.
> Thanks everybody!
>
> - Corey
>
> _________________________________________________________________
> Hotmail: Free, trusted and rich email service.
> http://clk.atdmt.com/GBL/go/171222984/direct/01/
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: sending commands to shell with emacs lisp
[not found] <mailman.6557.1252818947.2239.help-gnu-emacs@gnu.org>
@ 2009-09-13 7:14 ` Helmut Eller
0 siblings, 0 replies; 8+ messages in thread
From: Helmut Eller @ 2009-09-13 7:14 UTC (permalink / raw)
To: help-gnu-emacs
* Corey Foote [2009-09-13 07:15+0200] writes:
> I'm trying to send commands to a shell buffer. I'm able to send the command
> "hello world" by calling this:
>
> (defun exec-command ()
> (interactive)
> (set-buffer (get-buffer "*shell*"))
> (insert "hello world"))
>
> But I can't figure out how to send over the "enter key" to actually make it
> execute the shell command. I'm an emacs lisp newbie!
comint-send-input sends the region (and a newline) to the subprocess.
So:
(defun exec-command ()
(interactive)
(set-buffer (get-buffer "*shell*"))
(insert "hello world")
(comint-send-input))
should work.
Helmut
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: sending commands to shell with emacs lisp
[not found] ` <mailman.6558.1252820105.2239.help-gnu-emacs@gnu.org>
@ 2009-09-13 7:45 ` Bruno Barbier
0 siblings, 0 replies; 8+ messages in thread
From: Bruno Barbier @ 2009-09-13 7:45 UTC (permalink / raw)
To: help-gnu-emacs
On 2009-09-13, tomas@tuxteam.de <tomas@tuxteam.de> wrote:
>
> On Sun, Sep 13, 2009 at 01:15:38AM -0400, Corey Foote wrote:
>>
>> I'm trying to send commands to a shell buffer. I'm able to send the
>> command "hello world" by calling this:
>>
>> (defun exec-command ()
>> (interactive)
>> (set-buffer (get-buffer "*shell*"))
>> (insert "hello world"))
>>
>> But I can't figure out how to send over the "enter key" to actually
>> make it execute the shell command. I'm an emacs lisp newbie!
I'm using the following code to send a command to an existing shell:
(with-current-buffer buffer
(let ((process (get-buffer-process (current-buffer)))
)
(unless process
(error "No process in %s" buffer-or-name))
(goto-char (process-mark process))
(insert command-string)
(comint-send-input nil
t ;; artificial
)
))
so, the magic is:
(comint-send-input nil t)
When I'm not using a shell and I just want the shell command result,
I'm doing:
(with-output-to-temp-buffer "*shell result*"
(shell-command "echo hello world" "*shell result*")
)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: sending commands to shell with emacs lisp
2009-09-13 6:43 ` Corey Foote
@ 2009-09-13 10:21 ` tomas
0 siblings, 0 replies; 8+ messages in thread
From: tomas @ 2009-09-13 10:21 UTC (permalink / raw)
To: Corey Foote; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Sun, Sep 13, 2009 at 02:43:29AM -0400, Corey Foote wrote:
>
> Thanks, but I really am just looking for a way to send an "enter" keystroke to my *shell* buffer [...]
I see. There are other useful suggestions as to what to do in that case.
My approach would have been to look at what a shell buffer does when
ENTER is hit. You can peek at that by hitting "C-h k" (aka "describe
key") in a shell buffer and then hitting ENTER. You get:
RET (translated from <return>) runs the command comint-send-input,
which is an interactive compiled Lisp function in `comint.el'.
(which is what Helmut proposes in this thread).
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFKrMe2Bcgs9XrR2kYRAgfkAJ0ZGUAVGzcSli0qeiFtZx+6vrxMLQCdF40S
cq0Gum4wk+CPeN5C5rRSJ+U=
=nmDp
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: sending commands to shell with emacs lisp
[not found] ` <mailman.6560.1252824219.2239.help-gnu-emacs@gnu.org>
@ 2009-09-13 14:39 ` despen
0 siblings, 0 replies; 8+ messages in thread
From: despen @ 2009-09-13 14:39 UTC (permalink / raw)
To: help-gnu-emacs
Corey Foote <coreyfoote@hotmail.com> writes:
> Thanks, but I really am just looking for a way to send an "enter"
> keystroke to my *shell* buffer after I've inserted a command. I'm just
> trying to save myself a few keystrokes in my edit, compile, execute cycle.
For that, you want to use a Makefile and M-x compile.
For example, in the Makefile:
all: foo.test
foo: foo.c
cc foo.c -o foo
foo.test: foo
foo args
With that Makefile, just do M-x compile and your module
is compiled if need be, then the test is run.
You might use diff in the .test rule to capture the test output
and verify the results.
I've got M-x compile bound to F1 and M-x next-error bound to
F2.
So typically, for do the edit/compile/execute cycle, I finish
my edits, Hit F1, return, and I'm done.
An important advantage with M-x compile is that Emacs will
ask you if you want to save the file before the compile starts.
It's not necessary to remember to save the file.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2009-09-13 14:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-13 5:15 sending commands to shell with emacs lisp Corey Foote
2009-09-13 5:45 ` tomas
2009-09-13 6:43 ` Corey Foote
2009-09-13 10:21 ` tomas
[not found] ` <mailman.6560.1252824219.2239.help-gnu-emacs@gnu.org>
2009-09-13 14:39 ` despen
2009-09-13 6:55 ` Thierry Volpiatto
[not found] ` <mailman.6558.1252820105.2239.help-gnu-emacs@gnu.org>
2009-09-13 7:45 ` Bruno Barbier
[not found] <mailman.6557.1252818947.2239.help-gnu-emacs@gnu.org>
2009-09-13 7:14 ` Helmut Eller
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).