From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: michael@cadilhac.name (=?iso-8859-1?Q?Micha=EBl?= Cadilhac) Newsgroups: gmane.emacs.devel Subject: Re: Interactive specs of C functions. Date: Mon, 10 Sep 2007 00:34:48 +0200 Organization: Epita/LRDE Message-ID: <87bqcbqxh3.fsf@cadilhac.name> References: <87sl5qr093.fsf@cadilhac.name> <87ps0tttkt.fsf@cadilhac.name> <87fy1nr2ht.fsf@cadilhac.name> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1449985284==" X-Trace: sea.gmane.org 1189379482 26285 80.91.229.12 (9 Sep 2007 23:11:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 9 Sep 2007 23:11:22 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 10 09:11:09 2007 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 1IUctt-0004Qa-PJ for ged-emacs-devel@m.gmane.org; Mon, 10 Sep 2007 08:37:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IUVPX-0007rc-8r for ged-emacs-devel@m.gmane.org; Sun, 09 Sep 2007 18:37:47 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IUVPT-0007rA-21 for emacs-devel@gnu.org; Sun, 09 Sep 2007 18:37:43 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IUVPR-0007qg-Hj for emacs-devel@gnu.org; Sun, 09 Sep 2007 18:37:42 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IUVPR-0007qb-EU for emacs-devel@gnu.org; Sun, 09 Sep 2007 18:37:41 -0400 Original-Received: from smtp3-g19.free.fr ([212.27.42.29]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IUVPN-0000EB-2y; Sun, 09 Sep 2007 18:37:37 -0400 Original-Received: from smtp3-g19.free.fr (localhost.localdomain [127.0.0.1]) by smtp3-g19.free.fr (Postfix) with ESMTP id 83EA381C2; Mon, 10 Sep 2007 00:37:36 +0200 (CEST) Original-Received: from localhost (ivr94-6-82-230-255-91.fbx.proxad.net [82.230.255.91]) by smtp3-g19.free.fr (Postfix) with ESMTP id 973A681C0; Mon, 10 Sep 2007 00:37:35 +0200 (CEST) X-Website: http://michael.cadilhac.name Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAElBMVEVWPh+Tai+5r5YKBAEU CQQzGAtiq7gjAAACR0lEQVQ4jW2UzW7lIAyFzVW8BzTZX5DmCZLuU2H2pMXv/ypzbK7aSh2kRCRf /HNsE0q7Sg+RQ7JFKaqtrRNAl5AIIKe6D5DBqgbmUAe5hBI1wIRFAHjeM0RKtZi7XVVEpb0BSNfA IddChChT5DildSLWOWhY5IEItMnncZgFcUAc/5jjwCMsDosRNdfKPDTFEdVBW8C+RebDb4N5Orio RhM1+11IJyx0ng2+LryFHBMPDQDYHrY6IfGuU3ouiXTQNE8LIJDKOWpNxERTFrggQwRPd7USUsTW fJ0XbR3bdj5KgBYy4SACpxDeUYEUAzLmtJ1iIrD2gczPq8Qomjhsh/RjGIgKIO8p7NITjwlx7WID nsnQe5NeuTvoBpi8LX6vLLOh5icjOHqBypgnuSp7M+RE1agbQKHQr5E2z1WObhYW4gMqeGQL7joM jCf2DxSk5ApADSYHfFF4igNfJZL1z0GKP0FN02s4XiDXr7V5P94W6I9v8MfBOQDmfwAaVYt+x8Da v4DJvX8BAdin3Knm5yMZYAO4ABDkDniZLLfi4P40gP1F0TPGZOu0CGwA1lcowxwlGy6A9705mD0V jHCxwVZT/hYdRJVUGZNlx6l7ScQBTluof6Wj6bsPYlvpwoTvXFD9gHPn2TZPF3ntI2ecxVrW5MrV XiCie5EeNa7BlWu/HNSkprDUva163PHxAv5jyGV7gVzyAghSKOTnat85UIYFICXbD2NV9rRiv0BS tKQsg6OHH4A15F1WW+UHKHHa32h6aPnAm3/pUcWp+WYnTQAAAABJRU5ErkJggg== In-Reply-To: (Stefan Monnier's message of "Sun, 09 Sep 2007 17:19:29 -0400") User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux) X-Detected-Kernel: Linux 2.4-2.6 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:78363 Archived-At: --===============1449985284== Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Stefan Monnier writes: >> ! if (XSUBR (fun)->prompt) >> ! return list2 (Qinteractive, build_string (XSUBR (fun)->prompt)); > This doesn't look right. It should do the Fread_from_string thingy as > well. Indeed, you're right! >> + (defun char-to-who (char) >> + (defun char-to-right (char &optional from) >> + (defun right-string-to-number (rights who-mask &optional from) > These names are too generic compared to the job they do. I'd add > a "file-modes" prefix or somesuch. Thanks again=A0:-) The two first patches (the modifications to dired-aux are the same): --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=callint.patch Content-Transfer-Encoding: quoted-printable Index: src/lisp.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/src/lisp.h,v retrieving revision 1.583 diff -c -B -w -r1.583 lisp.h *** src/lisp.h 29 Aug 2007 21:50:08 -0000 1.583 =2D-- src/lisp.h 9 Sep 2007 22:34:00 -0000 *************** *** 891,897 **** Lisp_Object (*function) (); short min_args, max_args; char *symbol_name; ! char *prompt; char *doc; }; =20=20 =2D-- 891,897 ---- Lisp_Object (*function) (); short min_args, max_args; char *symbol_name; ! char *intspec; char *doc; }; =20=20 *************** *** 1669,1698 **** followed by the address of a vector of Lisp_Objects which contains the argument values. UNEVALLED means pass the list of unevaluated arguments ! `prompt' says how to read arguments for an interactive call. ! See the doc string for `interactive'. A null string means call interactively with no arguments. `doc' is documentation for the user. */ =20=20 #if (!defined (__STDC__) && !defined (PROTOTYPES)) \ || defined (USE_NONANSI_DEFUN) =20=20 ! #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \ Lisp_Object fnname (); \ DECL_ALIGN (struct Lisp_Subr, sname) =3D \ { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ ! fnname, minargs, maxargs, lname, prompt, 0}; \ Lisp_Object fnname =20=20 #else =20=20 /* This version of DEFUN declares a function prototype with the right arguments, so we can catch errors with maxargs at compile-time. */ ! #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \ Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ DECL_ALIGN (struct Lisp_Subr, sname) =3D \ { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ ! fnname, minargs, maxargs, lname, prompt, 0}; \ Lisp_Object fnname =20=20 /* Note that the weird token-substitution semantics of ANSI C makes =2D-- 1669,1701 ---- followed by the address of a vector of Lisp_Objects which contains the argument values. UNEVALLED means pass the list of unevaluated arguments ! `intspec' says how interactive arguments are to be fetched. ! If the string starts with a `(', `intspec' is evaluated and the resul= ting ! list is the list of arguments. ! If it's a string that doesn't start with `(', the value should follow ! the one of the doc string for `interactive'. A null string means call interactively with no arguments. `doc' is documentation for the user. */ =20=20 #if (!defined (__STDC__) && !defined (PROTOTYPES)) \ || defined (USE_NONANSI_DEFUN) =20=20 ! #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ Lisp_Object fnname (); \ DECL_ALIGN (struct Lisp_Subr, sname) =3D \ { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ ! fnname, minargs, maxargs, lname, intspec, 0}; \ Lisp_Object fnname =20=20 #else =20=20 /* This version of DEFUN declares a function prototype with the right arguments, so we can catch errors with maxargs at compile-time. */ ! #define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ Lisp_Object fnname DEFUN_ARGS_ ## maxargs ; \ DECL_ALIGN (struct Lisp_Subr, sname) =3D \ { PVEC_SUBR | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)), \ ! fnname, minargs, maxargs, lname, intspec, 0}; \ Lisp_Object fnname =20=20 /* Note that the weird token-substitution semantics of ANSI C makes Index: src/callint.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/src/callint.c,v retrieving revision 1.154 diff -c -B -w -r1.154 callint.c *** src/callint.c 29 Aug 2007 05:27:56 -0000 1.154 =2D-- src/callint.c 9 Sep 2007 22:34:00 -0000 *************** *** 334,345 **** =20=20 if (SUBRP (fun)) { ! string =3D (unsigned char *) XSUBR (fun)->prompt; if (!string) { lose: wrong_type_argument (Qcommandp, function); } } else if (COMPILEDP (fun)) { =2D-- 334,351 ---- =20=20 if (SUBRP (fun)) { ! string =3D (unsigned char *) XSUBR (fun)->intspec; if (!string) { lose: wrong_type_argument (Qcommandp, function); } + /* The function has an interactive spec to evaluate. */ + if (*string =3D=3D '(') + { + specs =3D Fcar (Fread_from_string (build_string (string), Qnil, Qnil)); + string =3D 0; + } } else if (COMPILEDP (fun)) { Index: src/data.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/src/data.c,v retrieving revision 1.277 diff -c -B -w -r1.277 data.c *** src/data.c 29 Aug 2007 05:27:58 -0000 1.277 =2D-- src/data.c 9 Sep 2007 22:34:01 -0000 *************** *** 770,777 **** =20=20 if (SUBRP (fun)) { ! if (XSUBR (fun)->prompt) ! return list2 (Qinteractive, build_string (XSUBR (fun)->prompt)); } else if (COMPILEDP (fun)) { =2D-- 770,780 ---- =20=20 if (SUBRP (fun)) { ! char *spec =3D XSUBR (fun)->intspec; ! if (spec) ! return list2 (Qinteractive, ! (*spec !=3D '(') ? build_string (spec) : ! Fcar (Fread_from_string (build_string (spec), Qnil, Qnil))); } else if (COMPILEDP (fun)) { Index: src/eval.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/src/eval.c,v retrieving revision 1.287 diff -c -B -w -r1.287 eval.c *** src/eval.c 29 Aug 2007 05:27:57 -0000 1.287 =2D-- src/eval.c 9 Sep 2007 22:34:03 -0000 *************** *** 2078,2084 **** /* Emacs primitives are interactive if their DEFUN specifies an interactive spec. */ if (SUBRP (fun)) ! return XSUBR (fun)->prompt ? Qt : if_prop; =20=20 /* Bytecode objects are interactive if they are long enough to have an element whose index is COMPILED_INTERACTIVE, which is =2D-- 2078,2084 ---- /* Emacs primitives are interactive if their DEFUN specifies an interactive spec. */ if (SUBRP (fun)) ! return XSUBR (fun)->intspec ? Qt : if_prop; =20=20 /* Bytecode objects are interactive if they are long enough to have an element whose index is COMPILED_INTERACTIVE, which is --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=chmod.patch Content-Transfer-Encoding: quoted-printable Index: lisp/files.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.927 diff -c -B -w -r1.927 files.el *** lisp/files.el 31 Aug 2007 13:29:34 -0000 1.927 =2D-- lisp/files.el 9 Sep 2007 22:23:28 -0000 *************** *** 5407,5412 **** =2D-- 5407,5505 ---- (t (apply operation arguments))))) =20=20 + + ;; Symbolic modes and read-file-modes. +=20 + (defun file-modes-char-to-who (char) + "Convert CHAR to a who-mask from a symbolic mode notation. + CHAR is in [ugoa] and represents the users on which rights are applied." + (cond ((=3D char ?u) #o4700) + ((=3D char ?g) #o2070) + ((=3D char ?o) #o1007) + ((=3D char ?a) #o7777) + (t (error "%c: bad `who' character" char)))) +=20 + (defun file-modes-char-to-right (char &optional from) + "Convert CHAR to a right-mask from a symbolic mode notation. + CHAR is in [rwxXstugo] and represents a right. + If CHAR is in [Xugo], the value is extracted from FROM (or 0 if nil)." + (or from (setq from 0)) + (cond ((=3D char ?r) #o0444) + ((=3D char ?w) #o0222) + ((=3D char ?x) #o0111) + ((=3D char ?s) #o1000) + ((=3D char ?t) #o6000) + ;; Rights relative to the previous file modes. + ((=3D char ?X) (if (=3D (logand from #o111) 0) 0 #o0111)) + ((=3D char ?u) (let ((uright (logand #o4700 from))) + (+ uright (/ uright #o10) (/ uright #o100)))) + ((=3D char ?g) (let ((gright (logand #o2070 from))) + (+ gright (/ gright #o10) (* gright #o10)))) + ((=3D char ?o) (let ((oright (logand #o1007 from))) + (+ oright (* oright #o10) (* oright #o100)))) + (t (error "%c: bad right character" char)))) +=20 + (defun file-modes-rights-to-number (rights who-mask &optional from) + "Convert a right string to a right-mask from a symbolic modes notation. + RIGHTS is the right string, it should match \"([+=3D-][rwxXstugo]+)+\". + WHO-MASK is the mask number of the users on which the rights are to be ap= plied. + FROM (or 0 if nil) is the orginal modes of the file to be chmod'ed." + (let* ((num-rights (or from 0)) + (list-rights (string-to-list rights)) + (op (pop list-rights))) + (while (memq op '(?+ ?- ?=3D)) + (let ((num-right 0) + char-right) + (while (memq (setq char-right (pop list-rights)) + '(?r ?w ?x ?X ?s ?t ?u ?g ?o)) + (setq num-right + (logior num-right + (file-modes-char-to-right char-right num-rights)))) + (setq num-right (logand who-mask num-right) + num-rights + (cond ((=3D op ?+) (logior num-rights num-right)) + ((=3D op ?-) (logand num-rights (lognot num-right))) + (t (logior (logand num-rights (lognot who-mask)) num-right))) + op char-right))) + num-rights)) +=20 + (defun symbolic-file-modes-to-number (modes &optional from) + "Convert symbolic file modes to numeric file modes. + MODES is the string to convert, it should match + \"[ugoa]*([+-=3D][rwxXstugo]+)+,...\". + See (info \"(coreutils)File permissions\") for more information on this + notation. + FROM (or 0 if nil) is the orginal modes of the file to be chmod'ed." + (save-match-data + (let ((case-fold-search nil) + (num-modes (or from 0))) + (while (/=3D (string-to-char modes) 0) + (if (string-match "^\\([ugoa]*\\)\\([+=3D-][rwxXstugo]+\\)+\\(,\\|\\)" m= odes) + (let ((num-who (apply 'logior 0 + (mapcar 'file-modes-char-to-who + (match-string 1 modes))))) + (when (=3D num-who 0) + (setq num-who (default-file-modes))) + (setq num-modes + (file-modes-rights-to-number (substring modes (match-end 1)) + num-who num-modes) + modes (substring modes (match-end 3)))) + (error "Parse error in modes near `%s'" (substring modes 0)))) + num-modes))) +=20 + (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." + (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) + (symbolic-file-modes-to-number value modes))))) +=20 + (define-key ctl-x-map "\C-f" 'find-file) (define-key ctl-x-map "\C-r" 'find-file-read-only) (define-key ctl-x-map "\C-v" 'find-alternate-file) Index: src/fileio.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /sources/emacs/emacs/src/fileio.c,v retrieving revision 1.590 diff -c -B -w -r1.590 fileio.c *** src/fileio.c 29 Aug 2007 05:27:58 -0000 1.590 =2D-- src/fileio.c 9 Sep 2007 22:23:30 -0000 *************** *** 3435,3441 **** return make_number (st.st_mode & 07777); } =20=20 ! DEFUN ("set-file-modes", Fset_file_modes, Sset_file_modes, 2, 2, 0, doc: /* Set mode bits of file named FILENAME to MODE (an integer). Only the 12 low bits of MODE are used. */) (filename, mode) =2D-- 3435,3443 ---- return make_number (st.st_mode & 07777); } =20=20 ! DEFUN ("set-file-modes", Fset_file_modes, Sset_file_modes, 2, 2, ! "(let ((file (read-file-name \"File: \"))) \ ! (list file (read-file-modes nil file)))", doc: /* Set mode bits of file named FILENAME to MODE (an integer). Only the 12 low bits of MODE are used. */) (filename, mode) --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable =2D-=20 | Micha=EBl `Micha' Cadilhac | =ABTu aimeras ton prochain.=BB = | | http://michael.cadilhac.name | D'abord, Dieu ou pas, = | | JID/MSN: | j'ai horreur qu'on me tutoie. = | `---- michael.cadilhac@gmail.com | -- P. Desproges - = --' --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.2 (GNU/Linux) iD8DBQFG5HULUJhDmOfFA3URAnt+AJ0b49nR248yvQrxBGii8D52Ffq3gwCfZVzt 3LeuYyffRz/vJg6IUpoQmfw= =3DOK -----END PGP SIGNATURE----- --==-=-=-- --===============1449985284== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --===============1449985284==--