From 65f2f4532fb0f04292d8207b801d128fa5e226d1 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 10 Mar 2011 18:57:41 +0100 Subject: Set `%default-port-encoding' to "UTF-8". * src/guile/skribilo/utils/syntax.scm (default-to-utf-8): New macro. * src/guile/skribilo.scm (skribilo): Use it around `(doskribe)'. --- src/guile/skribilo.scm | 41 ++++++++++++++++++++----------------- src/guile/skribilo/utils/syntax.scm | 15 +++++++++++--- 2 files changed, 34 insertions(+), 22 deletions(-) (limited to 'src/guile') diff --git a/src/guile/skribilo.scm b/src/guile/skribilo.scm index 985e0cd..8bd3b9a 100644 --- a/src/guile/skribilo.scm +++ b/src/guile/skribilo.scm @@ -1,6 +1,6 @@ ;;; skribilo.scm -- The Skribilo document processor. ;;; -;;; Copyright 2005, 2006, 2007, 2008, 2009 Ludovic Courtès +;;; Copyright 2005, 2006, 2007, 2008, 2009, 2011 Ludovic Courtès ;;; Copyright 2003, 2004 Erick Gallesio - I3S-CNRS/ESSI ;;; ;;; @@ -375,24 +375,27 @@ options." (if (and output-file (file-exists? output-file)) (delete-file output-file)) - (parameterize ((*destination-file* output-file) - (*source-file* input-file) - (*skribilo-output-port* - (if (string? output-file) - (open-output-file output-file) - (current-output-port)))) - - (setvbuf (*skribilo-output-port*) _IOFBF 16384) - - (if input-file - (with-input-from-file input-file - (lambda () - (set-correct-file-encoding!) - (doskribe user-module))) - (doskribe user-module)) - - ;; Make sure the output port is flushed before we leave. - (force-output (*skribilo-output-port*)))))) + ;; Choose UTF-8 as the default encoding so that string ports will + ;; accept all of Unicode. + (default-to-utf-8 + (parameterize ((*destination-file* output-file) + (*source-file* input-file) + (*skribilo-output-port* + (if (string? output-file) + (open-output-file output-file) + (current-output-port)))) + + (setvbuf (*skribilo-output-port*) _IOFBF 16384) + + (if input-file + (with-input-from-file input-file + (lambda () + (set-correct-file-encoding!) + (doskribe user-module))) + (doskribe user-module)) + + ;; Make sure the output port is flushed before we leave. + (force-output (*skribilo-output-port*))))))) ;;; Local Variables: diff --git a/src/guile/skribilo/utils/syntax.scm b/src/guile/skribilo/utils/syntax.scm index 5a42b09..471ea14 100644 --- a/src/guile/skribilo/utils/syntax.scm +++ b/src/guile/skribilo/utils/syntax.scm @@ -1,6 +1,6 @@ ;;; syntax.scm -- Syntactic candy for Skribilo modules. -*- coding: utf-8 -*- ;;; -;;; Copyright 2005, 2006, 2007, 2008, 2009, 2010 Ludovic Courtès +;;; Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011 Ludovic Courtès ;;; ;;; ;;; This program is free software; you can redistribute it and/or modify @@ -24,6 +24,7 @@ :use-module (system reader confinement) :export (%skribilo-module-reader skribilo-module-syntax set-correct-file-encoding! + default-to-utf-8 _ N_ unwind-protect unless when)) @@ -94,10 +95,18 @@ ;; Use the encoding specified by the `coding:' comment. (let ((e (false-if-exception (file-encoding port)))) (and (string? e) - (set-port-encoding! port e))))))) + (set-port-encoding! port e)))))) + + (define-syntax default-to-utf-8 + (syntax-rules () + ((_ body ...) + (with-fluids ((%default-port-encoding "UTF-8")) + body ...))))) (else (define-macro (set-correct-file-encoding! . p) - #f))) + #f) + + (define-macro (default-to-utf-8 . rest) #t))) ;;; -- cgit v1.2.3