From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tobias Naehring Subject: Proposal: starting of parallel asynchronous shell processes Date: Thu, 17 May 2012 13:01:59 +0000 (UTC) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([208.118.235.92]:35372) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SV0LW-0003pP-Iw for emacs-orgmode@gnu.org; Thu, 17 May 2012 09:02:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SV0LM-0004xB-Hk for emacs-orgmode@gnu.org; Thu, 17 May 2012 09:02:22 -0400 Received: from plane.gmane.org ([80.91.229.3]:37659) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SV0LM-0004wz-BN for emacs-orgmode@gnu.org; Thu, 17 May 2012 09:02:12 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SV0LI-0007nC-Si for emacs-orgmode@gnu.org; Thu, 17 May 2012 15:02:08 +0200 Received: from dslb-178-000-244-013.pools.arcor-ip.net ([178.0.244.13]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 May 2012 15:02:08 +0200 Received: from i_inbox by dslb-178-000-244-013.pools.arcor-ip.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 17 May 2012 15:02:08 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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