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: Michaël Cadilhac
Subject: Re: suggestion for set-file-modes
Date: Mon, 11 Feb 2008 18:41:56 -0500
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

Dan Nicolaescu <address@hidden> writes:

> address@hidden (Michaël Cadilhac) writes:
>
>   > Dan Nicolaescu <address@hidden> writes:
>   > 
>   > > I think it would be good if set-file-modes would display the current
>   > > modes in symbolic form in the prompt for changing them.
>   > 
>   > Displaying the current modes is probably a good thing to do, but putting
>   > it in the prompt in order to be changed seems weird: when the modes are
>   > expressed in symbolic notation, they are used as a *mask* against the
>   > current modes, not a simple modification.

>   > Maybe a more intuitive thing we can do is to prompt the following :
>   > 
>   > "File modes, octal or symbolic (current: -r-xrw---):"
>
> This form is exactly what I had in mind. This format is familiar to
> people from "ls -l".  If users request something else, it can be changed
> later, but this should do for now.  Obviously, this is all IMHO...

Following that proposition, on which we agreed, here's a patch.

Index: files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.959
diff -b -u -w -r1.959 files.el
--- files.el    30 Jan 2008 21:25:08 -0000      1.959
+++ files.el    11 Feb 2008 23:38:35 -0000
@@ -5464,7 +5464,7 @@
          (t
           (apply operation arguments)))))

-;; Symbolic modes and read-file-modes.
+;; Symbolic modes, ls-type modes, and read-file-modes.
 
 (defun file-modes-char-to-who (char)
   "Convert CHAR to a who-mask from a symbolic mode notation.
@@ -5543,13 +5543,38 @@
          (error "Parse error in modes near `%s'" (substring modes 0))))
       num-modes)))
 
+(defun file-modes-number-to-ls (modes)
+  "Convert the numerical MODES into the `ls' notation."
+  (let (string)
+    (dotimes (i 3 string)
+      (let* ((is-executable (/= 0 (logand modes 1)))
+            (exec-bit
+             (or (cond ((and (= i 0) ;; Sticky.
+                             (/= 0 (logand modes #o1000)))
+                        (if is-executable "t" "T"))
+                       ((or (and (= i 1) ;; Set-gid.
+                                 (/= 0 (logand modes #o200)))
+                            (and (= i 2) ;; Set-uid.
+                                 (/= 0 (logand modes #o40))))
+                        (if is-executable "s" "S")))
+                 (if is-executable "x" "-"))))
+       (setq string (concat (if (/= 0 (logand modes 4)) "r" "-")
+                            (if (/= 0 (logand modes 2)) "w" "-")
+                            exec-bit string))
+       (setq modes (lsh modes -3))))))
+
 (defun read-file-modes (&optional prompt orig-file)
   "Read file modes in octal or symbolic notation.
-PROMPT is used as the prompt, default to `File modes (octal or symbolic): '.
-ORIG-FILE is the original file of which modes will be change."
+PROMPT is used as the prompt, default to `File modes, octal or symbolic'
+followed by the current modes of ORIG-FILE.
+ORIG-FILE is the file of which modes will be changed."
   (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): "))))
+        (ls-type-modes (when orig-file
+                         (concat " (current: " (file-modes-number-to-ls modes)
+                                 ")")))
+        (value (read-string (or prompt (concat "File modes, octal or symbolic"
+                                               ls-type-modes ": ")))))
     (save-match-data
       (if (string-match "^[0-7]+" value)
          (string-to-number value 8)


Diffs between working revision and workfile end here.
If there's no complain in a few days, I'll install it.

-- 
 |   Michaël `Micha' Cadilhac       |  Si j'étais sous-secrétaire d'État     |
 |   http://michael.cadilhac.name   |    aux choux farcis, vous entendriez   |
 |   JID/MSN:                       |  beaucoup parler des choux farcis !    |
 `----  address@hidden  |          -- Nicolas Sarkozy       -  --'

Attachment: pgpa3Sp40GdOq.pgp
Description: PGP signature


reply via email to

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