unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: michael@cadilhac.name (Michaël Cadilhac)
To: Dan Nicolaescu <dann@ics.uci.edu>
Cc: emacs-devel@gnu.org
Subject: Re: suggestion for set-file-modes
Date: Mon, 11 Feb 2008 18:41:56 -0500	[thread overview]
Message-ID: <87r6fjoybf.fsf@cadilhac.name> (raw)
In-Reply-To: <200802112200.m1BM0pke028675@sallyv1.ics.uci.edu> (Dan Nicolaescu's message of "Mon, 11 Feb 2008 14:00:51 -0800")


[-- Attachment #1.1: Type: text/plain, Size: 1028 bytes --]

Dan Nicolaescu <dann@ics.uci.edu> writes:

> michael@cadilhac.name (Michaël Cadilhac) writes:
>
>   > Dan Nicolaescu <dann@ics.uci.edu> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: files.patch --]
[-- Type: text/x-patch, Size: 2372 bytes --]

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)))))
 \f
-;; 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.

[-- Attachment #1.3: Type: text/plain, Size: 385 bytes --]


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 !    |
 `----  michael.cadilhac@gmail.com  |          -- Nicolas Sarkozy       -  --'

[-- Attachment #2: Type: application/pgp-signature, Size: 188 bytes --]

       reply	other threads:[~2008-02-11 23:41 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     ` Michaël Cadilhac [this message]
2008-02-16 19:19       ` suggestion for set-file-modes 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
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=87r6fjoybf.fsf@cadilhac.name \
    --to=michael@cadilhac.name \
    --cc=dann@ics.uci.edu \
    --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).