emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: suggestion for set-file-modes


From: Juri Linkov
Subject: Re: suggestion for set-file-modes
Date: Tue, 29 Jul 2008 20:43:50 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

>> 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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]