GNU bug report logs - #12399
24.2.50; dired-do-touch doesn't recognize empty input in minibuffer

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> jurta.org>

Date: Sun, 9 Sep 2012 22:50:01 UTC

Severity: normal

Found in version 24.2.50

Done: Juri Linkov <juri <at> jurta.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 12399 in the body.
You can then email your comments to 12399 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#12399; Package emacs. (Sun, 09 Sep 2012 22:50:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 09 Sep 2012 22:50:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
Date: Mon, 10 Sep 2012 01:43:14 +0300
`dired-do-touch' used to get the current time for empty input.
Its prompt says that the default value is "now".

But currently its default value is the file modification time,
not the current time.  Thus `T RET' has no effect in dired.

The problem is that `dired-mark-read-string' now uses `completing-read'
(to be able to provide completion) instead of `read-from-minibuffer'.

These functions differ in how they handle defaults:
`read-from-minibuffer' returns the empty string for empty input, but
`completing-read' returns the default value and can't recognize
empty input.

This requires a new function that provides completion like
`completing-read-default' but without these two lines:

    (when (and (equal result "") def)
      (setq result (if (consp def) (car def) def)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12399; Package emacs. (Tue, 11 Sep 2012 14:42:02 GMT) Full text and rfc822 format available.

Message #8 received at 12399 <at> debbugs.gnu.org (full text, mbox):

From: Bastien <bzg <at> altern.org>
To: Juri Linkov <juri <at> jurta.org>
Cc: 12399 <at> debbugs.gnu.org
Subject: Re: bug#12399: 24.2.50;
	dired-do-touch doesn't recognize empty input in minibuffer
Date: Tue, 11 Sep 2012 16:41:13 +0200
[Message part 1 (text/plain, inline)]
Hi Juri,

Juri Linkov <juri <at> jurta.org> writes:

> `dired-do-touch' used to get the current time for empty input.
> Its prompt says that the default value is "now".
>
> But currently its default value is the file modification time,
> not the current time.  Thus `T RET' has no effect in dired.
>
> The problem is that `dired-mark-read-string' now uses `completing-read'
> (to be able to provide completion) instead of `read-from-minibuffer'.
>
> These functions differ in how they handle defaults:
> `read-from-minibuffer' returns the empty string for empty input, but
> `completing-read' returns the default value and can't recognize
> empty input.
>
> This requires a new function that provides completion like
> `completing-read-default' but without these two lines:
>
>     (when (and (equal result "") def)
>       (setq result (if (consp def) (car def) def)))

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.

If it's good for you, I'll apply this within this week.

[dired-aux.el.patch (text/x-patch, inline)]
=== modified file 'lisp/dired-aux.el'
--- lisp/dired-aux.el	2012-09-08 14:48:26 +0000
+++ lisp/dired-aux.el	2012-09-11 14:38:39 +0000
@@ -225,8 +225,7 @@
   (let* ((files (dired-get-marked-files t arg))
 	 (default (and (eq op-symbol 'touch)
 		       (stringp (car files))
-		       (format-time-string "%Y%m%d%H%M.%S"
-					   (nth 5 (file-attributes (car files))))))
+		       (format-time-string "%Y%m%d%H%M.%S")))
 	 (prompt (concat "Change " attribute-name " of %s to"
 			 (if (eq op-symbol 'touch)
 			     " (default now): "

[Message part 3 (text/plain, inline)]
-- 
 Bastien

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12399; Package emacs. (Tue, 11 Sep 2012 19:11:02 GMT) Full text and rfc822 format available.

Message #11 received at 12399 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Bastien <bzg <at> altern.org>
Cc: 12399 <at> debbugs.gnu.org
Subject: Re: bug#12399: 24.2.50;
	dired-do-touch doesn't recognize empty input in minibuffer
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))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12399; Package emacs. (Tue, 11 Sep 2012 20:48:01 GMT) Full text and rfc822 format available.

Message #14 received at 12399 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Juri Linkov <juri <at> jurta.org>
Cc: Bastien <bzg <at> altern.org>, 12399 <at> debbugs.gnu.org
Subject: Re: bug#12399: 24.2.50;
	dired-do-touch doesn't recognize empty input in minibuffer
Date: Tue, 11 Sep 2012 16:46:10 -0400
> 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':

There's another way to do that: check (eq val default), since the
returned value will be `eq' to the `default' if the minibuffer was
empty, whereas if it comes from a non-empty minibuffer it will at best
be `equal'.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12399; Package emacs. (Tue, 11 Sep 2012 22:54:02 GMT) Full text and rfc822 format available.

Message #17 received at 12399 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Bastien <bzg <at> altern.org>, 12399 <at> debbugs.gnu.org
Subject: Re: bug#12399: 24.2.50;
	dired-do-touch doesn't recognize empty input in minibuffer
Date: Wed, 12 Sep 2012 01:50:35 +0300
> There's another way to do that: check (eq val default), since the
> returned value will be `eq' to the `default' if the minibuffer was
> empty, whereas if it comes from a non-empty minibuffer it will at best
> be `equal'.

I tried this in the following patch and it works.
There is too little space in comments to explain
this hack, so I added a bug reference.

Old (string-equal new-attribute "") remains as
a precaution against possible unexpected changes in
`dired-mark-read-string'.

=== modified file 'lisp/dired-aux.el'
--- lisp/dired-aux.el	2012-09-08 14:48:27 +0000
+++ lisp/dired-aux.el	2012-09-11 22:48:01 +0000
@@ -244,7 +244,10 @@ (defun dired-do-chxxx (attribute-name pr
 			     (function dired-check-process)
 			     (append
 			      (list operation program)
-			      (unless (string-equal new-attribute "")
+			      (unless (or (string-equal new-attribute "")
+					  ;; Use `eq' instead of `equal'
+					  ;; to detect empty input (bug#12399).
+					  (eq new-attribute default))
 				(if (eq op-symbol 'touch)
 				    (list "-t" new-attribute)
 				  (list new-attribute)))




Reply sent to Juri Linkov <juri <at> jurta.org>:
You have taken responsibility. (Thu, 13 Sep 2012 23:46:02 GMT) Full text and rfc822 format available.

Notification sent to Juri Linkov <juri <at> jurta.org>:
bug acknowledged by developer. (Thu, 13 Sep 2012 23:46:02 GMT) Full text and rfc822 format available.

Message #22 received at 12399-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Bastien <bzg <at> altern.org>, 12399-done <at> debbugs.gnu.org
Subject: Re: bug#12399: 24.2.50;
	dired-do-touch doesn't recognize empty input in minibuffer
Date: Fri, 14 Sep 2012 02:42:53 +0300
>> There's another way to do that: check (eq val default), since the
>> returned value will be `eq' to the `default' if the minibuffer was
>> empty, whereas if it comes from a non-empty minibuffer it will at best
>> be `equal'.
>
> I tried this in the following patch and it works.

Installed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#12399; Package emacs. (Fri, 14 Sep 2012 23:02:03 GMT) Full text and rfc822 format available.

Message #25 received at 12399 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: 12399 <at> debbugs.gnu.org
Subject: Re: bug#12399: 24.2.50;
	dired-do-touch doesn't recognize empty input in minibuffer
Date: Sat, 15 Sep 2012 01:59:31 +0300
>>> There's another way to do that: check (eq val default), since the
>>> returned value will be `eq' to the `default' if the minibuffer was
>>> empty, whereas if it comes from a non-empty minibuffer it will at best
>>> be `equal'.
>>
>> I tried this in the following patch and it works.
>
> Installed.

I noticed the same problem in `dired-do-chmod' and fixed it the same way.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 13 Oct 2012 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 219 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.