From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: suggestion for set-file-modes Date: Tue, 29 Jul 2008 20:43:50 +0300 Organization: JURTA Message-ID: <87r69cfuw9.fsf@jurta.org> References: <200801201812.m0KICxYl009632@sallyv1.ics.uci.edu> <871w7jqiic.fsf@cadilhac.name> <200802112200.m1BM0pke028675@sallyv1.ics.uci.edu> <87r6fjoybf.fsf@cadilhac.name> <87y79ku2tf.fsf@jurta.org> <87r6fc33g5.fsf@cadilhac.name> <87ir0oscs1.fsf@jurta.org> <87lk5k30cz.fsf@cadilhac.name> <873arso1bv.fsf@jurta.org> <874pc8s82w.fsf@catnip.gol.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1217353580 6572 80.91.229.12 (29 Jul 2008 17:46:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Jul 2008 17:46:20 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 29 19:47:10 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KNtHP-0002W3-8x for ged-emacs-devel@m.gmane.org; Tue, 29 Jul 2008 19:46:35 +0200 Original-Received: from localhost ([127.0.0.1]:50640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNtGV-0004F6-0Y for ged-emacs-devel@m.gmane.org; Tue, 29 Jul 2008 13:45:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KNtG7-0003zS-HY for emacs-devel@gnu.org; Tue, 29 Jul 2008 13:45:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KNtG6-0003yY-GI for emacs-devel@gnu.org; Tue, 29 Jul 2008 13:45:14 -0400 Original-Received: from [199.232.76.173] (port=56668 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNtG6-0003yB-86 for emacs-devel@gnu.org; Tue, 29 Jul 2008 13:45:14 -0400 Original-Received: from smtp-out.neti.ee ([194.126.126.37]:50870) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KNtG5-0001GQ-O8 for emacs-devel@gnu.org; Tue, 29 Jul 2008 13:45:14 -0400 X-Virus-Scanned: Debian amavisd-new at estpak.ee Original-Received: from Relayhost3.neti.ee (relayhost3.estpak.ee [88.196.174.169]) by MXR-8.estpak.ee (Postfix) with ESMTP id 9DF69148F55 for ; Tue, 29 Jul 2008 20:45:08 +0300 (EEST) Original-Received: from mail.estpak.ee (66.132.191.90.dyn.estpak.ee [90.191.132.66]) by Relayhost3.neti.ee (Postfix) with ESMTP id 52D89D3A00 for ; Tue, 29 Jul 2008 20:45:07 +0300 (EEST) In-Reply-To: <874pc8s82w.fsf@catnip.gol.com> (Miles Bader's message of "Sun, 17 Feb 2008 10:08:39 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:101703 Archived-At: >> The standard convention when reading a value in the minibuffer is to put >> the default value in the prompt and make it available for editing by M-n. >> When the permission bits are retrieved in such notation from the default >> value then editing them is just like toggling that is convenient. > > Soooo, why not convert it to an appropriate "input form" for putting in > the prompt/default ? > > E.g., -rwxrwxrw- => "ug=rwx,o=rw" > > That has the advantage that such "input forms" are a bit more robust, > because they aren't fixed-width with position-senstive fields. They're > also somewhat more self-documenting. > > [Also, of course, it's more consistent with other programs, none of > which use the "ls forms" for input.] > > It shouldn't be very hard to do. It seems there was consensus on the notation proposed by Miles. The following patch implements it by adding the absolute mode form "=" to the minibuffer's default value in `read-file-modes' and `dired-do-chmod'. It requires adding a new arg `default' to `dired-mark-read-string' (similar to `dired-mark-read-file-name' that already has the last argument `default'). Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.987 diff -c -r1.987 files.el *** lisp/files.el 11 Jul 2008 23:08:07 -0000 1.987 --- lisp/files.el 29 Jul 2008 17:38:51 -0000 *************** *** 5786,5792 **** 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): ")))) (save-match-data (if (string-match "^[0-7]+" value) (string-to-number value 8) --- 5786,5804 ---- 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"))) ! (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) Index: lisp/dired-aux.el =================================================================== RCS file: /sources/emacs/emacs/lisp/dired-aux.el,v retrieving revision 1.175 diff -c -r1.175 dired-aux.el *** lisp/dired-aux.el 29 Jul 2008 16:36:42 -0000 1.175 --- lisp/dired-aux.el 29 Jul 2008 17:37:42 -0000 *************** *** 255,263 **** Symbolic modes like `g+w' are allowed." (interactive "P") (let* ((files (dired-get-marked-files t arg)) (modes (dired-mark-read-string "Change mode of %s to: " nil ! 'chmod arg files)) (num-modes (if (string-match "^[0-7]+" modes) (string-to-number modes 8)))) (dolist (file files) --- 255,274 ---- Symbolic modes like `g+w' are allowed." (interactive "P") (let* ((files (dired-get-marked-files t arg)) + (modestr (and (stringp (car files)) + (nth 8 (file-attributes (car files))))) + (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))))) (modes (dired-mark-read-string "Change mode of %s to: " nil ! 'chmod arg files default)) (num-modes (if (string-match "^[0-7]+" modes) (string-to-number modes 8)))) (dolist (file files) *************** *** 358,371 **** ;; 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) ! ;; PROMPT for a string, with INITIAL input. ;; 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)) ;;; Cleaning a directory: flagging some backups for deletion. --- 369,382 ---- ;; 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)) ;;; Cleaning a directory: flagging some backups for deletion. -- Juri Linkov http://www.jurta.org/emacs/