Subject: bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer

From: Juri Linkov <[email-masked]>
Date: Tue, 11 Sep 2012 22:05:01 +0300

> I'm not sure why the simple patch below should not be enough,
> taking the current time instead of the one from the first file
> in the set of marked file.

Sorry, but it removes using the modification time of current file
for editing in the minibuffer via M-n, and what is worse, it uses
the current time as the argument of `touch' that might cause race
conditions as described in
http://thread.gmane.org/gmane.emacs.devel/142449/focus=142494

Fortunately, thanks to `completing-read-function'
it's easy to fix this with a small change that adds
a new function `completing-read-without-default'
that works like `completing-read-default'
but returns the empty string for empty input
like `read-from-minibuffer':

=== modified file 'lisp/dired-aux.el'
--- lisp/dired-aux.el	2012-09-08 14:48:27 +0000
+++ lisp/dired-aux.el	2012-09-11 19:04:20 +0000
@@ -391,10 +391,11 @@ (defun dired-mark-read-string (prompt in
 
 Optional arg COLLECTION is a collection of possible completions,
 passed as the second arg to `completing-read'."
+  (let ((completing-read-function 'completing-read-without-default))
   (dired-mark-pop-up nil op-symbol files
 		     'completing-read
 		     (format prompt (dired-mark-prompt arg files))
-		     collection nil nil initial nil default-value nil))
+		       collection nil nil initial nil default-value nil)))
 
 ;;; Cleaning a directory: flagging some backups for deletion.
 
=== modified file 'lisp/minibuffer.el'
--- lisp/minibuffer.el	2012-09-01 04:28:24 +0000
+++ lisp/minibuffer.el	2012-09-11 19:03:14 +0000
@@ -3089,11 +3108,14 @@ (defvar completing-read-function 'comple
   "The function called by `completing-read' to do its work.
 It should accept the same arguments as `completing-read'.")
 
-(defun completing-read-default (prompt collection &optional predicate
+(defun completing-read-without-default (prompt collection &optional predicate
                                        require-match initial-input
                                        hist def inherit-input-method)
-  "Default method for reading from the minibuffer with completion.
-See `completing-read' for the meaning of the arguments."
+  "Read a string with completion and without returning the default value.
+See `completing-read' for the meaning of the arguments.
+Unlike `completing-read-default', for empty input it returns
+the empty string instead of the default value.  Thus it handles
+empty input like `read-from-minibuffer'."
 
   (when (consp initial-input)
     (setq initial-input
@@ -3121,10 +3143,23 @@ (defun completing-read-default (prompt c
                     base-keymap)))
          (result (read-from-minibuffer prompt initial-input keymap
                                        nil hist def inherit-input-method)))
+    result))
+
+(defun completing-read-default (prompt collection &optional predicate
+                                       require-match initial-input
+                                       hist def inherit-input-method)
+  "Default method for reading from the minibuffer with completion.
+See `completing-read' for the meaning of the arguments.
+Unlike `completing-read-without-default', for empty input it returns
+the default value instead of the empty string."
+  (let ((result (completing-read-without-default
+		 prompt collection predicate require-match
+		 initial-input hist def inherit-input-method)))
     (when (and (equal result "") def)
       (setq result (if (consp def) (car def) def)))
     result))