summaryrefslogtreecommitdiff
path: root/doc/ref
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2013-01-30 14:45:28 -0500
committerMark H Weaver <mhw@netris.org>2013-04-07 10:11:41 -0400
commit9a334eb3ab6bbb250d9c0f559b82d1c97f5eb21a (patch)
tree3a1e9076fdde272656c67e70303c08ed4dd95a5c /doc/ref
parentbc3901092dc777d832862862e606ae2ddeb6f2f8 (diff)
downloadguile-9a334eb3ab6bbb250d9c0f559b82d1c97f5eb21a.tar.gz
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.
Diffstat (limited to 'doc/ref')
-rw-r--r--doc/ref/api-io.texi24
1 files changed, 16 insertions, 8 deletions
diff --git a/doc/ref/api-io.texi b/doc/ref/api-io.texi
index 9c3e1fc27..e994cd74b 100644
--- a/doc/ref/api-io.texi
+++ b/doc/ref/api-io.texi
@@ -885,8 +885,8 @@ Use binary mode, ensuring that each byte in the file will be read as one
Scheme character.
To provide this property, the file will be opened with the 8-bit
-character encoding "ISO-8859-1", ignoring any coding declaration or port
-encoding. @xref{Ports}, for more information on port encodings.
+character encoding "ISO-8859-1", ignoring the default port encoding.
+@xref{Ports}, for more information on port encodings.
Note that while it is possible to read and write binary data as
characters or strings, it is usually better to treat bytes as octets,
@@ -903,12 +903,20 @@ 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!}.
+When the file is opened, its encoding is 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} procedure 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
In theory we could create read/write ports which were buffered
in one direction only. However this isn't included in the