From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCHES] Keyword args for file openers; coding scan off by default Date: Sun, 07 Apr 2013 15:24:04 +0200 Message-ID: <87d2u6v5hn.fsf@gnu.org> References: <878v4uu92d.fsf@tines.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1365341065 21916 80.91.229.3 (7 Apr 2013 13:24:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Apr 2013 13:24:25 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Apr 07 15:24:29 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UOpa7-0007rb-9M for guile-devel@m.gmane.org; Sun, 07 Apr 2013 15:24:27 +0200 Original-Received: from localhost ([::1]:47963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOpa6-0000Hj-Qf for guile-devel@m.gmane.org; Sun, 07 Apr 2013 09:24:26 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:46120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOpa1-0000HQ-7K for guile-devel@gnu.org; Sun, 07 Apr 2013 09:24:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UOpZz-0004ge-QT for guile-devel@gnu.org; Sun, 07 Apr 2013 09:24:21 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:60600) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UOpZz-0004ga-HL for guile-devel@gnu.org; Sun, 07 Apr 2013 09:24:19 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UOpZv-0007bb-Ja for guile-devel@gnu.org; Sun, 07 Apr 2013 15:24:15 +0200 Original-Received: from reverse-83.fdn.fr ([80.67.176.83]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 07 Apr 2013 15:24:15 +0200 Original-Received: from ludo by reverse-83.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 07 Apr 2013 15:24:15 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 99 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: reverse-83.fdn.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 18 Germinal an 221 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:mMWkKz+L+mcCRhWRU99msuUcxGk= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16188 Archived-At: Mark H Weaver skribis: > From 951b9d224d84bfec271b51615bc095013d153694 Mon Sep 17 00:00:00 2001 > From: Mark H Weaver > Date: Sat, 6 Apr 2013 23:19:55 -0400 > Subject: [PATCH 3/3] Add keyword arguments to file opening procedures. > > * libguile/fports.c (scm_open_file_with_encoding): New API function, > containing the code previously found in 'scm_open_file', but modified > to accept the new 'guess_encoding' and 'encoding' arguments. > > (scm_open_file): Now just a simple wrapper that calls > 'scm_open_file_with_encoding'. > > (scm_i_open_file): New implementation of 'open-file' that accepts > keyword arguments '#:guess-encoding' and '#:encoding', and calls > 'scm_open_file_with_encoding'. > > (scm_init_fports_keywords): New initialization function that gets > called after keywords are initialized. > > * libguile/fports.h (scm_open_file_with_encoding, > scm_init_fports_keywords): Add prototypes. > > * libguile/init.c (scm_i_init_guile): Call 'scm_init_fports_keywords'. > > * module/ice-9/boot-9.scm: Add enhanced versions of 'open-input-file', > 'open-output-file', 'call-with-input-file', 'call-with-output-file', > 'with-input-from-file', 'with-output-to-file', and > 'with-error-to-file', that accept keyword arguments '#:binary', > '#:encoding', and (for input port constructors) '#:guess-encoding'. > > * doc/ref/api-io.texi (File Ports): Update documentation. > > * test-suite/tests/ports.test ("keyword arguments for file openers"): > Add tests. Looks good. Minor comments: > +@deffn {Scheme Procedure} open-file filename mode @ > + [#:guess-encoding=#f] [#:encoding=#f] > +@deffnx {C Function} scm_open_file_with_encoding @ > + (filename, mode, guess_encoding, encoding) > @deffnx {C Function} scm_open_file (filename, mode) > Open the file whose name is @var{filename}, and return a port > representing that file. The attributes of the port are > @@ -900,8 +903,17 @@ to the underlying @code{open} call. Still, the flag is generally useful > because of its port encoding ramifications. > @end table > > -If a file cannot be opened with the access > -requested, @code{open-file} throws an exception. > +Unless binary mode is requested, the character encoding of the new port > +is determined as follows: First, if @var{guess-encoding} is true, > +heuristics will be used to guess the encoding of the file. If it is “heuristics” is vague. I’d prefer “the ‘file-encoding’ procedure is called to check for Emacs-style coding declarations (@pxref{Character Encoding of Source Files})”. Should BOMs also be mentioned? > +/* scm_open_file_with_encoding > * Return a new port open on a given file. > * > + * Use heuristics to guess the encoding is GUESS_ENCODING > + * is true, else use ENCODING if not false, else use the > + * default port encoding. Likewise. And you’re welcome to remove the leading stars also. :-) > +SCM k_guess_encoding = SCM_UNDEFINED; > +SCM k_encoding = SCM_UNDEFINED; Add ‘static’. > + scm_c_bind_keyword_arguments (FUNC_NAME, keyword_args, 0, > + k_guess_encoding, &guess_encoding, > + k_encoding, &encoding, > + SCM_UNDEFINED); Comes in handy. ;-) > +(define* (open-input-file > + str #:key (binary #f) (encoding #f) (guess-encoding #f)) > + "Takes a string naming an existing file and returns an input port > +capable of delivering characters from the file. If the file > +cannot be opened, an error is signalled." It’s a detail, for these procedures, I would s/str/file/, and in docstrings s/file STR/FILE/. The test suite looks comprehensive, that’s great. Thanks! Ludo’.