changeset 97154:f239a0459b5c

(read-file-modes): Set default value to the original mode string using absolute notation like u=rwx,g=rx,o=rx. Use it as the `default' arg of `read-string'.
author Juri Linkov <juri@jurta.org>
date Thu, 31 Jul 2008 17:18:06 +0000
parents 989ae5dfb320
children b4faea6c6c00
files lisp/files.el
diffstat 1 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/files.el	Thu Jul 31 17:17:35 2008 +0000
+++ b/lisp/files.el	Thu Jul 31 17:18:06 2008 +0000
@@ -5765,7 +5765,19 @@
 ORIG-FILE is the original file of which modes will be change."
   (let* ((modes (or (if orig-file (file-modes orig-file) 0)
 		    (error "File not found")))
-	 (value (read-string (or prompt "File modes (octal or symbolic): "))))
+	 (modestr (and (stringp orig-file)
+		       (nth 8 (file-attributes orig-file))))
+	 (default
+	   (and (stringp modestr)
+		(string-match "^.\\(...\\)\\(...\\)\\(...\\)$" modestr)
+		(replace-regexp-in-string
+		 "-" ""
+		 (format "u=%s,g=%s,o=%s"
+			 (match-string 1 modestr)
+			 (match-string 2 modestr)
+			 (match-string 3 modestr)))))
+	 (value (read-string (or prompt "File modes (octal or symbolic): ")
+			     nil nil default)))
     (save-match-data
       (if (string-match "^[0-7]+" value)
 	  (string-to-number value 8)