emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Proposal: starting of parallel asynchronous shell processes


From: Tobias Naehring
Subject: [O] Proposal: starting of parallel asynchronous shell processes
Date: Thu, 17 May 2012 13:01:59 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]