emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Proposal: starting of parallel asynchronous shell processes
@ 2012-05-17 13:01 Tobias Naehring
  2012-08-03 13:33 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Tobias Naehring @ 2012-05-17 13:01 UTC (permalink / raw)
  To: emacs-orgmode

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

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

end of thread, other threads:[~2012-08-03 16:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-17 13:01 Proposal: starting of parallel asynchronous shell processes Tobias Naehring
2012-08-03 13:33 ` Bastien
2012-08-03 13:38   ` Rasmus
2012-08-03 16:28     ` Bastien

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