emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tobias Naehring <i_inbox@tn-home.de>
To: emacs-orgmode@gnu.org
Subject: Proposal: starting of parallel asynchronous shell processes
Date: Thu, 17 May 2012 13:01:59 +0000 (UTC)	[thread overview]
Message-ID: <loom.20120517T145957-51@post.gmane.org> (raw)

Currently, only one asynchronous shell process can be started inside an org
buffer via

[[shell: ... &]]

The reason is that in `org-open-at-point' only the default shell output buffer
`*Shell Command Output*' is used for `shell-command'.

A poor man's solution to allow parallel shell processes would be to replace the
code fragment

		(progn
		  (message "Executing %s" cmd)
		  (shell-command cmd))
	      (error "Abort"))))

from `org-open-at-point' by

		(progn
		  (message "Executing %s" cmd)
		  (shell-command cmd (generate-new-buffer "*org-shell-output")))
	      (error "Abort"))))

The problem with that solution is that it creates one output buffer for each
shell command and does not care what happens to the buffer after the shell
process has finished. If one starts several shell processes this behavior can
litter the buffer list.

One alternative would be the following code fragment which uses dying-mode from
"http://emacswiki.org/emacs/dying.el" to get rid of the used shell output buffers:

		(let* ((buf-name (generate-new-buffer-name (concat "*org-shell-output"
(substring cmd 0 (min (length cmd) 20)))))
		       (buf (get-buffer-create buf-name)))
		  (message "Executing %s in buffer %s" cmd buf-name)
		  (shell-command cmd buf-name)
		  (let ((proc (get-buffer-process buf)))
		    (if (and proc (null (eq (process-status proc) 'exit)))
			     (set-process-sentinel proc '(lambda (proc event)
							   (if (eq (process-status proc) 'exit)
							       (with-current-buffer (process-buffer proc) (dying-mode 't)))))
		      (kill-buffer buf))))
	      (error "Abort"))))

The dying mode makes sure that the shell output buffers live for some time (more
exactly: `dying-lifetime') after the process has finished. In this time the user
can inspect the process output. If he wants to keep the output he can switch off
`dying-mode' for that buffer or extent its lifetime.

With best regards,
Tobias

             reply	other threads:[~2012-05-17 13:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-17 13:01 Tobias Naehring [this message]
2012-08-03 13:33 ` Proposal: starting of parallel asynchronous shell processes Bastien
2012-08-03 13:38   ` Rasmus
2012-08-03 16:28     ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20120517T145957-51@post.gmane.org \
    --to=i_inbox@tn-home.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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