guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCHES] Keyword args for file openers; coding scan off by default


From: Ludovic Courtès
Subject: Re: [PATCHES] Keyword args for file openers; coding scan off by default
Date: Sun, 07 Apr 2013 15:00:37 +0200
User-agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.3 (gnu/linux)

Mark H Weaver <address@hidden> skribis:

> From bb621dbbc0df691bcad541267a08c86c36d9062b Mon Sep 17 00:00:00 2001
> From: Mark H Weaver <address@hidden>
> Date: Wed, 30 Jan 2013 14:45:28 -0500
> Subject: [PATCH 1/3] Do not scan for coding declarations in open-file.
>
> * libguile/fports.c (scm_open_file): Do not scan for coding
>   declarations.  Replace 'use_encoding' local variable with
>   'binary'.  Update documentation string.
>
> * module/ice-9/psyntax.scm (include): Add the same file-encoding
>   logic that's used in compile-file and scm_primitive_load.
>
> * module/ice-9/psyntax-pp.scm: Regenerate.
>
> * doc/ref/api-io.texi (File Ports): Update docs.
>
> * test-suite/tests/ports.test: Change "open-file HONORS file coding
>   declarations" test to "open-file IGNORES file coding declaration".
>
> * test-suite/tests/coding.test (scan-coding): Use 'file-encoding' to
>   scan for the encoding, since 'open-input-file' no longer does so.

Perfect!

> @@ -903,13 +903,6 @@ because of its port encoding ramifications.
>  If a file cannot be opened with the access
>  requested, @code{open-file} throws an exception.
>  
> -When the file is opened, this procedure will scan for a coding
> -declaration (@pxref{Character Encoding of Source Files}). If a coding
> -declaration is found, it will be used to interpret the file.  Otherwise,
> -the port's encoding will be used.  To suppress this behavior, open the
> -file in binary mode and then set the port encoding explicitly using
> address@hidden

Can we change that to something like:

  When the file is opened, its encoding is inherited set to the current
  @code{%default-port-encoding}, unless the @code{b} flag was supplied.
  Sometimes it is desirable to honor Emacs-style coding declarations in
  address@hidden 2.0.0 to 2.0.7 would do this by default.  This
  behavior was deemed inappropriate and disabled starting from Guile
  2.0.8.}.  When that is the case, the @code{file-encoding} declaration
  can be used as follows (@pxref{Character Encoding of Source Files,
  @code{file-encoding}}):

  @example
  (let* ((port     (open-input-file file))
         (encoding (file-encoding port)))
    (set-port-encoding! port (or encoding (port-encoding port))))
  @end example

(I let you choose whether to also add it to the docstring or not.)

Ludo’.




reply via email to

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