unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: [PATCHES] Keyword args for file openers; coding scan off by default
Date: Sun, 07 Apr 2013 15:00:37 +0200	[thread overview]
Message-ID: <87y5cuv6kq.fsf@gnu.org> (raw)
In-Reply-To: 878v4uu92d.fsf@tines.lan

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

> From bb621dbbc0df691bcad541267a08c86c36d9062b Mon Sep 17 00:00:00 2001
> From: Mark H Weaver <mhw@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	other threads:[~2013-04-07 13:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07  6:52 [PATCHES] Keyword args for file openers; coding scan off by default Mark H Weaver
2013-04-07 13:00 ` Ludovic Courtès [this message]
2013-04-07 13:09 ` Ludovic Courtès
2013-04-07 13:24 ` Ludovic Courtès
2013-04-07 16:33   ` Mark H Weaver
2013-04-07 19:18     ` Ludovic Courtès

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/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y5cuv6kq.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-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.
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).