From 64b51947763acc9de425f0f5d2d37e6659b1fda8 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Mon, 12 Sep 2011 16:45:56 -0400 Subject: [PATCH] * dired-aux.el (dired-mark-read-string): Don't use default value on empty input. (dired-do-chxxx): Treat empty input for "touch" as no -t option. Omit initial minibuffer contents. (dired-do-chmod): Signal an error on empty input. (dired-mark-read-string): Don't return default on empty input. * files.el (file-modes-symbolic-to-number): Doc fix. Fixes: debbugs:9361 --- lisp/ChangeLog | 11 +++++++ lisp/dired-aux.el | 78 ++++++++++++++++++++++++++--------------------- lisp/dired.el | 2 +- lisp/files.el | 2 +- 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 139863e4a58..b96b2a4a542 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2011-09-12 Chong Yidong + + * dired-aux.el (dired-mark-read-string): Don't return default + value on empty input (Bug#9361). + (dired-do-chxxx): Treat empty input for "touch" as no -t option. + Omit initial minibuffer contents. + (dired-do-chmod): Signal an error on empty input. + (dired-mark-read-string): Don't return default on empty input. + + * files.el (file-modes-symbolic-to-number): Doc fix. + 2011-09-12 Stefan Monnier * international/mule-cmds.el (ucs-completions): Remove. diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index ec157fc4939..2f2d28e596c 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -236,18 +236,16 @@ List has a form of (file-name full-file-name (attribute-list))." ;; OP-SYMBOL is the type of operation (for use in `dired-mark-pop-up'). ;; ARG describes which files to use, as in `dired-get-marked-files'. (let* ((files (dired-get-marked-files t arg)) - (initial - (if (eq op-symbol 'touch) - (format-time-string "%Y%m%d%H%M.%S"))) - (default - (if (eq op-symbol 'touch) - (and (stringp (car files)) - (format-time-string "%Y%m%d%H%M.%S" - (nth 5 (file-attributes (car files))))))) - (new-attribute - (dired-mark-read-string - (concat "Change " attribute-name " of %s to: ") - initial op-symbol arg files default)) + (default (and (eq op-symbol 'touch) + (stringp (car files)) + (format-time-string "%Y%m%d%H%M.%S" + (nth 5 (file-attributes (car files)))))) + (prompt (concat "Change " attribute-name " of %s to" + (if (eq op-symbol 'touch) + " (default now): " + ": "))) + (new-attribute (dired-mark-read-string prompt nil op-symbol + arg files default)) (operation (concat program " " new-attribute)) failures) (setq failures @@ -255,9 +253,10 @@ List has a form of (file-name full-file-name (attribute-list))." (function dired-check-process) (append (list operation program) - (if (eq op-symbol 'touch) - '("-t") nil) - (list new-attribute) + (unless (string-equal new-attribute "") + (if (eq op-symbol 'touch) + (list "-t" new-attribute) + (list new-attribute))) (if (string-match "gnu" system-configuration) '("--") nil)) files)) @@ -285,10 +284,19 @@ Symbolic modes like `g+w' are allowed." (match-string 2 modestr) (match-string 3 modestr))))) (modes (dired-mark-read-string - "Change mode of %s to: " nil + "Change mode of %s to: " + ;; Insert initial input if there's only one file. + (unless (cadr files) default) 'chmod arg files default)) - (num-modes (if (string-match "^[0-7]+" modes) - (string-to-number modes 8)))) + num-modes) + + (cond ((equal modes "") + ;; We used to treat empty input as DEFAULT, but that is not + ;; such a good idea (Bug#9361). + (error "No file mode specified")) + ((string-match "^[0-7]+" modes) + (setq num-modes (string-to-number modes 8)))) + (dolist (file files) (set-file-modes file @@ -379,22 +387,24 @@ Uses the shell command coming from variables `lpr-command' and 'print arg file-list))) (dired-run-shell-command (dired-shell-stuff-it command file-list nil)))) -;; Read arguments for a marked-files command that wants a string -;; that is not a file name, -;; perhaps popping up the list of marked files. -;; ARG is the prefix arg and indicates whether the files came from -;; marks (ARG=nil) or a repeat factor (integerp ARG). -;; If the current file was used, the list has but one element and ARG -;; does not matter. (It is non-nil, non-integer in that case, namely '(4)). - -(defun dired-mark-read-string (prompt initial op-symbol arg files &optional default) - ;; PROMPT for a string, with INITIAL input and DEFAULT value. - ;; Other args are used to give user feedback and pop-up: - ;; OP-SYMBOL of command, prefix ARG, marked FILES. - (dired-mark-pop-up - nil op-symbol files - (function read-string) - (format prompt (dired-mark-prompt arg files)) initial nil default)) +(defun dired-mark-read-string (prompt initial op-symbol arg files + &optional standard-value) + "Read args for a Dired marked-files command, prompting with PROMPT. +Return the user input (a string). + +INITIAL, if non-nil, is the initial minibuffer input. +OP-SYMBOL is an operation symbol (see `dired-no-confirm'). +ARG is normally the prefix argument for the calling command. +FILES should be a list of file names. + +STANDARD-VALUE, if non-nil, should be a \"standard\" value or +list of such values, available via history commands. Note that +if the user enters empty input, this function returns the empty +string, not STANDARD-VALUE." + (dired-mark-pop-up nil op-symbol files + 'read-from-minibuffer + (format prompt (dired-mark-prompt arg files)) + initial nil nil nil standard-value)) ;;; Cleaning a directory: flagging some backups for deletion. diff --git a/lisp/dired.el b/lisp/dired.el index ecb626a275e..3428f5bef8b 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -3663,7 +3663,7 @@ Ask means pop up a menu for the user to select one of copy, move or link." ;;;;;; dired-run-shell-command dired-do-shell-command dired-do-async-shell-command ;;;;;; dired-clean-directory dired-do-print dired-do-touch dired-do-chown ;;;;;; dired-do-chgrp dired-do-chmod dired-compare-directories dired-backup-diff -;;;;;; dired-diff) "dired-aux" "dired-aux.el" "bbb53a5b6bf56c413fe0f898559bef8d") +;;;;;; dired-diff) "dired-aux" "dired-aux.el" "bbc9babe193843cad535d73492326c48") ;;; Generated autoloads from dired-aux.el (autoload 'dired-diff "dired-aux" "\ diff --git a/lisp/files.el b/lisp/files.el index a0f55517546..5ca9af6783d 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6301,7 +6301,7 @@ as in \"og+rX-w\"." "Convert symbolic file modes to numeric file modes. MODES is the string to convert, it should match \"[ugoa]*([+-=][rwxXstugo]*)+,...\". -See (info \"(coreutils)File permissions\") for more information on this +See Info node `(coreutils)File permissions' for more information on this notation. FROM (or 0 if nil) gives the mode bits on which to base permissions if MODES request to add, remove, or set permissions based on existing ones, -- 2.39.2