all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <f92capac@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Tino Calancha <f92capac@gmail.com>, 23206@debbugs.gnu.org
Subject: bug#23206: 25.0.92; dired-shell-stuff-it: wait until all parallel jobs finish
Date: Tue, 5 Apr 2016 14:24:41 +0900 (JST)	[thread overview]
Message-ID: <alpine.LRH.2.20.1604051423310.9018@calancha-ilc.kek.jp> (raw)
In-Reply-To: <83inzxnv5m.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 338 bytes --]

>This means the fix should only affect systems with a Posix
>shell.
>The stock MS-Windows shells don't have a 'wait' command (and
>don't need this fix in the first place, as the problem doesn't exist
>on MS-Windows, AFAICS).
I see.  Thank you.
I rewrote the patch so that it adds 'wait' when 'system-type' is
not in '(ms-dos windows-nt).

[-- Attachment #2: Type: text/plain, Size: 4627 bytes --]

From 5d4b99d84b1b329d7a0047b9ff00be94dd58e18c Mon Sep 17 00:00:00 2001
From: Tino Calancha <f92capac@gmail.com>
Date: Tue, 5 Apr 2016 14:08:57 +0900
Subject: [PATCH] Wait until all parallel shell commands finish

* lisp/dired-aux.el (dired-shell-stuff-it):
Drop all trailing ';' and '&' in command;
change indentation with \t to ?\s;
Force POSIX shells to wait until all background jobs finish.
(Bug#23206).
---
 lisp/dired-aux.el | 69 ++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 26 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index d29abf3..f5106bb 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -722,33 +722,50 @@ dired-shell-stuff-it
 ;; (coming from interactive P and currently ignored) to decide what to do.
 ;; Smart would be a way to access basename or extension of file names.
   (let* ((in-background (string-match "[ \t]*&[ \t]*\\'" command))
-	 (command (if in-background
-		      (substring command 0 (match-beginning 0))
-		    command))
-	 (sequentially (string-match "[ \t]*;[ \t]*\\'" command))
-	 (command (if sequentially
-		      (substring command 0 (match-beginning 0))
-		    command))
-	 (stuff-it
-	  (if (or (string-match-p dired-star-subst-regexp command)
-		  (string-match-p dired-quark-subst-regexp command))
-	      (lambda (x)
-		(let ((retval command))
-		  (while (string-match
-			  "\\(^\\|[ \t]\\)\\([*?]\\)\\([ \t]\\|$\\)" retval)
-		    (setq retval (replace-match x t t retval 2)))
-		  retval))
-	    (lambda (x) (concat command dired-mark-separator x)))))
+         (command (if in-background
+                      (let ((cmd command))
+                        (while (string-match "[ \t]*[&]+[ \t]*\\'" cmd)
+                          (setq cmd (substring cmd 0 (match-beginning 0)))) cmd)
+                    command))
+         (sequentially (string-match "[ \t]*;[ \t]*\\'" command))
+         (command (if sequentially
+                      (let ((cmd command))
+                        (while (string-match "[ \t]*[;]+[ \t]*\\'" cmd)
+                          (setq cmd (substring cmd 0 (match-beginning 0)))) cmd)
+                    command))
+         (in-back-no-seq (and in-background (not sequentially)))
+         (stuff-it
+          (if (or (string-match-p dired-star-subst-regexp command)
+                  (string-match-p dired-quark-subst-regexp command))
+              (lambda (x)
+                (let ((retval command))
+                  (while (string-match
+                          "\\(^\\|[ \t]\\)\\([*?]\\)\\([ \t]\\|$\\)" retval)
+                    (setq retval (replace-match x t t retval 2)))
+                  retval))
+            (lambda (x) (concat command dired-mark-separator x)))))
     (concat
-     (if on-each
-	 (mapconcat stuff-it (mapcar 'shell-quote-argument file-list)
-		    (if (and in-background (not sequentially)) "&" ";"))
-       (let ((files (mapconcat 'shell-quote-argument
-			       file-list dired-mark-separator)))
-	 (if (> (length file-list) 1)
-	     (setq files (concat dired-mark-prefix files dired-mark-postfix)))
-	 (funcall stuff-it files)))
-     (if in-background "&" ""))))
+     (cond (on-each
+            (format "%s%s"
+                    (mapconcat stuff-it (mapcar 'shell-quote-argument file-list)
+                               (or (and in-back-no-seq "&") ";"))
+                    ;; POSIX shells running a list of commands in the background
+                    ;; (LIST = cmd_1 & [cmd_2 & ... cmd_i & ... cmd_N &])
+                    ;; return once cmd_N ends, i.e., the shell does not
+                    ;; wait for cmd_i to finish before executing cmd_i+1.
+                    ;; That means, running (shell-command LIST) may not show
+                    ;; the output of all the commands (Bug#23206).
+                    ;; Add 'wait' to force those POSIX shells to wait until
+                    ;; all commands finish.
+                    (or (and in-back-no-seq (not (memq system-type '(ms-dos windows-nt))) "&wait")
+                        "")))
+           (t
+            (let ((files (mapconcat 'shell-quote-argument
+                                    file-list dired-mark-separator)))
+              (when (cdr file-list)
+                (setq files (concat dired-mark-prefix files dired-mark-postfix)))
+              (funcall stuff-it files))))
+     (or (and in-background "&") ""))))
 
 ;; This is an extra function so that it can be redefined by ange-ftp.
 ;;;###autoload
-- 
2.8.0.rc3


  reply	other threads:[~2016-04-05  5:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-03 13:02 bug#23206: 25.0.92; dired-shell-stuff-it: wait until all parallel jobs finish Tino Calancha
2016-04-03 15:03 ` Eli Zaretskii
2016-04-03 16:38   ` Tino Calancha
2016-04-04  6:20     ` Tino Calancha
2016-04-04 17:25     ` Eli Zaretskii
2016-04-05  5:24       ` Tino Calancha [this message]
2016-04-05 14:59         ` Eli Zaretskii
2016-04-05 15:58           ` Tino Calancha
2016-04-08 14:06             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.20.1604051423310.9018@calancha-ilc.kek.jp \
    --to=f92capac@gmail.com \
    --cc=23206@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.