* bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
@ 2012-09-09 22:43 Juri Linkov
2012-09-11 14:41 ` Bastien
0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2012-09-09 22:43 UTC (permalink / raw
To: 12399
`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)))
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
2012-09-09 22:43 bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer Juri Linkov
@ 2012-09-11 14:41 ` Bastien
2012-09-11 19:05 ` Juri Linkov
0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2012-09-11 14:41 UTC (permalink / raw
To: Juri Linkov; +Cc: 12399
[-- Attachment #1: Type: text/plain, Size: 1077 bytes --]
Hi Juri,
Juri Linkov <juri@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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-aux.el.patch --]
[-- Type: text/x-patch, Size: 535 bytes --]
=== 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): "
[-- Attachment #3: Type: text/plain, Size: 14 bytes --]
--
Bastien
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
2012-09-11 14:41 ` Bastien
@ 2012-09-11 19:05 ` Juri Linkov
2012-09-11 20:46 ` Stefan Monnier
0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2012-09-11 19:05 UTC (permalink / raw
To: Bastien; +Cc: 12399
> 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)))
\f
;;; 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))
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
2012-09-11 19:05 ` Juri Linkov
@ 2012-09-11 20:46 ` Stefan Monnier
2012-09-11 22:50 ` Juri Linkov
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Monnier @ 2012-09-11 20:46 UTC (permalink / raw
To: Juri Linkov; +Cc: Bastien, 12399
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
2012-09-11 20:46 ` Stefan Monnier
@ 2012-09-11 22:50 ` Juri Linkov
2012-09-13 23:42 ` Juri Linkov
0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2012-09-11 22:50 UTC (permalink / raw
To: Stefan Monnier; +Cc: Bastien, 12399
> 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)))
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
2012-09-11 22:50 ` Juri Linkov
@ 2012-09-13 23:42 ` Juri Linkov
2012-09-14 22:59 ` Juri Linkov
0 siblings, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2012-09-13 23:42 UTC (permalink / raw
To: Stefan Monnier; +Cc: Bastien, 12399-done
>> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer
2012-09-13 23:42 ` Juri Linkov
@ 2012-09-14 22:59 ` Juri Linkov
0 siblings, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2012-09-14 22:59 UTC (permalink / raw
To: 12399
>>> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-09-14 22:59 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-09 22:43 bug#12399: 24.2.50; dired-do-touch doesn't recognize empty input in minibuffer Juri Linkov
2012-09-11 14:41 ` Bastien
2012-09-11 19:05 ` Juri Linkov
2012-09-11 20:46 ` Stefan Monnier
2012-09-11 22:50 ` Juri Linkov
2012-09-13 23:42 ` Juri Linkov
2012-09-14 22:59 ` Juri Linkov
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.