aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTino Calancha2016-04-08 17:04:08 +0300
committerEli Zaretskii2016-04-08 17:04:08 +0300
commitc4e6dd15244506bdf7b71559774979db0c7ea286 (patch)
tree9f1f6b0db9e4b5b36c35e7dffbcb22bbf0df4841
parentbadf7369a63e03a5f4f3817be10763611a6aa8a2 (diff)
downloademacs-c4e6dd15244506bdf7b71559774979db0c7ea286.tar.gz
emacs-c4e6dd15244506bdf7b71559774979db0c7ea286.zip
Make 'dired-do-shell-command' wait for all background jobs
* lisp/dired-aux.el (dired-shell-stuff-it): Force POSIX shells to wait until all background jobs exit. (Bug#23206).
-rw-r--r--lisp/dired-aux.el31
1 files changed, 22 insertions, 9 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 990bf6aa34c..bbb5693aa37 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -730,6 +730,7 @@ can be produced by `dired-get-marked-files', for example."
730 (command (if sequentially 730 (command (if sequentially
731 (substring command 0 (match-beginning 0)) 731 (substring command 0 (match-beginning 0))
732 command)) 732 command))
733 (parallel-in-background (and in-background (not sequentially)))
733 (stuff-it 734 (stuff-it
734 (if (or (string-match-p dired-star-subst-regexp command) 735 (if (or (string-match-p dired-star-subst-regexp command)
735 (string-match-p dired-quark-subst-regexp command)) 736 (string-match-p dired-quark-subst-regexp command))
@@ -741,15 +742,27 @@ can be produced by `dired-get-marked-files', for example."
741 retval)) 742 retval))
742 (lambda (x) (concat command dired-mark-separator x))))) 743 (lambda (x) (concat command dired-mark-separator x)))))
743 (concat 744 (concat
744 (if on-each 745 (cond (on-each
745 (mapconcat stuff-it (mapcar 'shell-quote-argument file-list) 746 (format "%s%s"
746 (if (and in-background (not sequentially)) "&" ";")) 747 (mapconcat stuff-it (mapcar 'shell-quote-argument file-list)
747 (let ((files (mapconcat 'shell-quote-argument 748 (or (and parallel-in-background "&") ";"))
748 file-list dired-mark-separator))) 749 ;; POSIX shells running a list of commands in the background
749 (if (> (length file-list) 1) 750 ;; (LIST = cmd_1 & [cmd_2 & ... cmd_i & ... cmd_N &])
750 (setq files (concat dired-mark-prefix files dired-mark-postfix))) 751 ;; return once cmd_N ends, i.e., the shell does not
751 (funcall stuff-it files))) 752 ;; wait for cmd_i to finish before executing cmd_i+1.
752 (if in-background "&" "")))) 753 ;; That means, running (shell-command LIST) may not show
754 ;; the output of all the commands (Bug#23206).
755 ;; Add 'wait' to force those POSIX shells to wait until
756 ;; all commands finish.
757 (or (and parallel-in-background (not (memq system-type '(ms-dos windows-nt))) "&wait")
758 "")))
759 (t
760 (let ((files (mapconcat 'shell-quote-argument
761 file-list dired-mark-separator)))
762 (when (cdr file-list)
763 (setq files (concat dired-mark-prefix files dired-mark-postfix)))
764 (funcall stuff-it files))))
765 (or (and in-background "&") ""))))
753 766
754;; This is an extra function so that it can be redefined by ange-ftp. 767;; This is an extra function so that it can be redefined by ange-ftp.
755;;;###autoload 768;;;###autoload