unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: emacs-devel@gnu.org
Subject: Re: suggestion for set-file-modes
Date: Tue, 29 Jul 2008 20:43:50 +0300	[thread overview]
Message-ID: <87r69cfuw9.fsf@jurta.org> (raw)
In-Reply-To: <874pc8s82w.fsf@catnip.gol.com> (Miles Bader's message of "Sun, 17 Feb 2008 10:08:39 +0900")

>> 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))
  \f
  ;;; 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))
  \f
  ;;; Cleaning a directory: flagging some backups for deletion.

-- 
Juri Linkov
http://www.jurta.org/emacs/




  parent reply	other threads:[~2008-07-29 17:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200801201812.m0KICxYl009632@sallyv1.ics.uci.edu>
     [not found] ` <871w7jqiic.fsf@cadilhac.name>
     [not found]   ` <200802112200.m1BM0pke028675@sallyv1.ics.uci.edu>
2008-02-11 23:41     ` suggestion for set-file-modes Michaël Cadilhac
2008-02-16 19:19       ` Juri Linkov
2008-02-16 23:07         ` Michaël Cadilhac
2008-02-16 23:27           ` Juri Linkov
2008-02-17  0:14             ` Michaël Cadilhac
2008-02-17  0:48               ` Juri Linkov
2008-02-17  1:08                 ` Miles Bader
2008-02-17  1:31                   ` Juri Linkov
2008-02-17  2:04                     ` Michaël Cadilhac
2008-02-17  2:21                       ` Miles Bader
2008-02-17 21:54                       ` Juri Linkov
2008-07-29 17:43                   ` Juri Linkov [this message]
2008-02-17  1:39                 ` Michaël Cadilhac
2008-02-17 20:29                   ` Richard Stallman
2008-02-18  3:01                     ` Michaël Cadilhac
2008-02-17 21:57                       ` Juri Linkov
2008-02-17 21:55                   ` Juri Linkov
2008-02-17 22:18                     ` Miles Bader
2008-02-17 22:59                       ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r69cfuw9.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).