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

* Re: Proposal: starting of parallel asynchronous shell processes
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2012-08-03 13:33 UTC (permalink / raw)
  To: Tobias Naehring; +Cc: emacs-orgmode

Hi Tobias,

Tobias Naehring <i_inbox@tn-home.de> writes:

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

I've implement this poor man's solution.  The new buffers are added to
`clean-buffer-list-kill-buffer-names', and you can get rid of the
buffers with M-x clean-buffer-list RET.

Thanks for this idea,

-- 
 Bastien

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

* Re: Proposal: starting of parallel asynchronous shell processes
  2012-08-03 13:33 ` Bastien
@ 2012-08-03 13:38   ` Rasmus
  2012-08-03 16:28     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus @ 2012-08-03 13:38 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@gnu.org> writes:

> Tobias Naehring <i_inbox@tn-home.de> writes:
>
>> 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"))))
>
> I've implement this poor man's solution.  The new buffers are added to
> `clean-buffer-list-kill-buffer-names', and you can get rid of the
> buffers with M-x clean-buffer-list RET.

BTW: are you aware of  emacs-async at: 

  https://github.com/jwiegley/emacs-async

It mainly make sense with time-consuming processes, though.  I think
John is trying to push it to Emacs-core.

–Rasmus

-- 
. . . It begins of course with The Internet.  A Net of Peers.

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

* Re: Proposal: starting of parallel asynchronous shell processes
  2012-08-03 13:38   ` Rasmus
@ 2012-08-03 16:28     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2012-08-03 16:28 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hi Rasmus,

Rasmus <rasmus@gmx.us> writes:

> BTW: are you aware of  emacs-async at: 
>
>   https://github.com/jwiegley/emacs-async

Yes.

> It mainly make sense with time-consuming processes, though.  I think
> John is trying to push it to Emacs-core.

Not only with time-consuming processes, but for processes that are
triggered by a program rather than by the user directly.

Async shell commands in Org are always triggered directly by the user
when he opens a shell link -- so allowing async processes is just a
small convenience and should happen not very often, async is to big 
of a hammer for this.

But I certainly hope John's proof of concept will made his way, 
either in Emacs or in Emacs maintainers imagination!

-- 
 Bastien

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