Mark H Weaver <m...@netris.org> skribis:

> From bb621dbbc0df691bcad541267a08c86c36d9062b Mon Sep 17 00:00:00 2001
> From: Mark H Weaver <m...@netris.org>
> 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
> -@code{set-port-encoding!}.

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
  files@footnote{Guile 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