unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Enter
@ 2008-11-04  8:46 TheFlyingDutchman
  2008-11-04  9:51 ` Enter TheFlyingDutchman
  2008-11-04 10:03 ` Enter Giorgos Keramidas
  0 siblings, 2 replies; 4+ messages in thread
From: TheFlyingDutchman @ 2008-11-04  8:46 UTC (permalink / raw)
  To: help-gnu-emacs


I want to start a shell buffer and then run a command via an Emacs
Lisp function. If I do this:

(shell)
(insert "ls\n")


Emacs will start a shell buffer and insert the command at the prompt
but it seems to be missing the effect of hitting the enter key. Is
there a way to simulate hitting the [enter] key in Emacs Lisp?


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

* Re: Enter
  2008-11-04  8:46 Enter TheFlyingDutchman
@ 2008-11-04  9:51 ` TheFlyingDutchman
  2008-11-04 10:03 ` Enter Giorgos Keramidas
  1 sibling, 0 replies; 4+ messages in thread
From: TheFlyingDutchman @ 2008-11-04  9:51 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 4, 12:46 am, TheFlyingDutchman <zzbba...@aol.com> wrote:
> I want to start a shell buffer and then run a command via an Emacs
> Lisp function. If I do this:
>
> (shell)
> (insert "ls\n")

Well I found something:

(comint-send-input)

seems to do the trick and simulate manually hitting [enter] in the
shell buffer.



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

* Re: Enter
  2008-11-04  8:46 Enter TheFlyingDutchman
  2008-11-04  9:51 ` Enter TheFlyingDutchman
@ 2008-11-04 10:03 ` Giorgos Keramidas
  2008-11-04 19:22   ` Enter TheFlyingDutchman
  1 sibling, 1 reply; 4+ messages in thread
From: Giorgos Keramidas @ 2008-11-04 10:03 UTC (permalink / raw)
  To: help-gnu-emacs

On Tue, 4 Nov 2008 00:46:11 -0800 (PST), TheFlyingDutchman <zzbbaadd@aol.com> wrote:
> I want to start a shell buffer and then run a command via an Emacs
> Lisp function. If I do this:
>
> (shell)
> (insert "ls\n")

You don't need the extra "\n" at the end of the command, but you may
find the function `comint-send-input' useful.

    (shell)
    (insert "ls")
    (comint-send-input)

If you don't really need the command to support interactive input, you
can also call `shell-command' with the full command string:

    (shell-command "ls")

With an optional second argument, you can send the output to a specific
buffer, i.e.:

    (with-temp-buffer
      (shell-command "ls" (current-buffer))

      ;; More stuff that processes parts of (current-buffer).
      ...)




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

* Re: Enter
  2008-11-04 10:03 ` Enter Giorgos Keramidas
@ 2008-11-04 19:22   ` TheFlyingDutchman
  0 siblings, 0 replies; 4+ messages in thread
From: TheFlyingDutchman @ 2008-11-04 19:22 UTC (permalink / raw)
  To: help-gnu-emacs

On Nov 4, 2:03 am, Giorgos Keramidas <keram...@ceid.upatras.gr> wrote:
> On Tue, 4 Nov 2008 00:46:11 -0800 (PST), TheFlyingDutchman <zzbba...@aol.com> wrote:
> > I want to start a shell buffer and then run a command via an Emacs
> > Lisp function. If I do this:
>
> > (shell)
> > (insert "ls\n")
>
> You don't need the extra "\n" at the end of the command, but you may
> find the function `comint-send-input' useful.
>
>     (shell)
>     (insert "ls")
>     (comint-send-input)
>
> If you don't really need the command to support interactive input, you
> can also call `shell-command' with the full command string:
>
>     (shell-command "ls")
>
> With an optional second argument, you can send the output to a specific
> buffer, i.e.:
>
>     (with-temp-buffer
>       (shell-command "ls" (current-buffer))
>
>       ;; More stuff that processes parts of (current-buffer).
>       ...)

Thanks Giorgos. shell-command is probably what I should be using in
most cases instead of shell. Didn't know about with-temp-buffer
either.


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

end of thread, other threads:[~2008-11-04 19:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-04  8:46 Enter TheFlyingDutchman
2008-11-04  9:51 ` Enter TheFlyingDutchman
2008-11-04 10:03 ` Enter Giorgos Keramidas
2008-11-04 19:22   ` Enter TheFlyingDutchman

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