all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Emacs-Lisp question about "shell-command"
@ 2004-02-19 11:32 Kay Ulbrich
  2004-02-19 14:39 ` Joakim Hove
  2004-02-19 16:01 ` Floyd Davidson
  0 siblings, 2 replies; 3+ messages in thread
From: Kay Ulbrich @ 2004-02-19 11:32 UTC (permalink / raw)


Hello!

Under Linux (version information see end of message) I am using a
simple emacs-lisp function (the actual function is more complex, but
this question is just about "shell-command"):

;; __________________________________________________
(defun my-command ()
  (interactive)
  (let (command)
    (setq command ("some-shell-command-generating-output &"))
    (shell-command command "buffername")
    ))
;; __________________________________________________

When executing the function from an unsplit emacs-frame, the window is
split and the output of the shell is written into the newly appeared
window, which containins the buffer "buffername". This obviously is
the default behaviour of "shell-command".

Is there an easy way to run the command without a new window
appearing, i.e., having the buffer created but not shown
automatically, so that my visible windows are not changed? I do not
want to open a new frame to run the function in.

Using (replace-buffer-in-windows "buffername") as the last command
in the function just did this, when I had the frame split into two
halves right away.

Output of "M-x emacs-version": GNU Emacs 21.3.1 (i686-pc-linux-gnu, X
toolkit, Xaw3d scroll bars) of 2004-01-19 on HOSTNAME

Thank you for advice!
Kay

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

* Re: Emacs-Lisp question about "shell-command"
  2004-02-19 11:32 Emacs-Lisp question about "shell-command" Kay Ulbrich
@ 2004-02-19 14:39 ` Joakim Hove
  2004-02-19 16:01 ` Floyd Davidson
  1 sibling, 0 replies; 3+ messages in thread
From: Joakim Hove @ 2004-02-19 14:39 UTC (permalink / raw)



Kay Ulbrich <news_nospam@web.de> writes:

> Hello!
>
> Under Linux (version information see end of message) I am using a
> simple emacs-lisp function (the actual function is more complex, but
> this question is just about "shell-command"):
>
> ;; __________________________________________________
> (defun my-command ()
>   (interactive)
>   (let (command)
>     (setq command ("some-shell-command-generating-output &"))
>     (shell-command command "buffername")
>     ))
> ;; __________________________________________________

This seems to work:

(defun my-command ()
  (interactive)
  (let ((window-c (current-window-configuration))
        (command  "some-shell-command ..."))
    (shell-command command)
    (set-window-configuration window-c)))

i.e. the current window configuration is stored, and then
subsequently recovered after the shell command is completed.


HTH - Joakim


-- 
  /--------------------------------------------------------------------\
 / Joakim Hove  / hove@bccs.no  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /
  \--------------------------------------------------------------------/

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

* Re: Emacs-Lisp question about "shell-command"
  2004-02-19 11:32 Emacs-Lisp question about "shell-command" Kay Ulbrich
  2004-02-19 14:39 ` Joakim Hove
@ 2004-02-19 16:01 ` Floyd Davidson
  1 sibling, 0 replies; 3+ messages in thread
From: Floyd Davidson @ 2004-02-19 16:01 UTC (permalink / raw)


Kay Ulbrich <news_nospam@web.de> wrote:
>Hello!
>
>Under Linux (version information see end of message) I am using a
>simple emacs-lisp function (the actual function is more complex, but
>this question is just about "shell-command"):
>
>;; __________________________________________________
>(defun my-command ()
>  (interactive)
>  (let (command)
>    (setq command ("some-shell-command-generating-output &"))
>    (shell-command command "buffername")
>    ))
>;; __________________________________________________
>
>When executing the function from an unsplit emacs-frame, the window is
>split and the output of the shell is written into the newly appeared
>window, which containins the buffer "buffername". This obviously is
>the default behaviour of "shell-command".
>
>Is there an easy way to run the command without a new window
>appearing, i.e., having the buffer created but not shown
>automatically, so that my visible windows are not changed? I do not
>want to open a new frame to run the function in.

You can wrap the portion that changes the frame with
save-window-excursion and possibily also with save-excursion.

Using save-excursion will restore the cursor position in your current
buffer, if you do anything that would move it, such as if the
rest of your actual function collects some text generated in the
new buffer and uses it to modify the original current buffer.

Your code might look like this,

(defun my-command ()
  (interactive)
  (let (command)
    (setq command ("some-shell-command-generating-output &"))
    (save-window-excursion
      (save-excursion
        (shell-command command "buffername")))))

>Using (replace-buffer-in-windows "buffername") as the last command
>in the function just did this, when I had the frame split into two
>halves right away.
>
>Output of "M-x emacs-version": GNU Emacs 21.3.1 (i686-pc-linux-gnu, X
>toolkit, Xaw3d scroll bars) of 2004-01-19 on HOSTNAME
>
>Thank you for advice!
>Kay

--
Floyd L. Davidson           <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@barrow.com

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

end of thread, other threads:[~2004-02-19 16:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-19 11:32 Emacs-Lisp question about "shell-command" Kay Ulbrich
2004-02-19 14:39 ` Joakim Hove
2004-02-19 16:01 ` Floyd Davidson

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.