summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/modules/skribilo/documentation/api.scm3
-rw-r--r--doc/user/src/outline.txt2
-rw-r--r--doc/user/syntax.skb7
-rw-r--r--doc/user/user.skb3
-rw-r--r--src/guile/skribilo.scm6
-rw-r--r--src/guile/skribilo/evaluator.scm12
-rw-r--r--src/guile/skribilo/source.scm4
-rw-r--r--src/guile/skribilo/utils/syntax.scm32
8 files changed, 36 insertions, 33 deletions
diff --git a/doc/modules/skribilo/documentation/api.scm b/doc/modules/skribilo/documentation/api.scm
index ab445a4..959211b 100644
--- a/doc/modules/skribilo/documentation/api.scm
+++ b/doc/modules/skribilo/documentation/api.scm
@@ -28,7 +28,7 @@
   :use-module (skribilo output)
   :use-module (skribilo lib) ;; `define-markup'
   :use-module (skribilo utils compat)
-  :use-module (skribilo utils syntax) ;; `skribilo-module-syntax'
+  :use-module (skribilo utils syntax)
 
   :use-module (skribilo package base)
   :use-module (skribilo documentation manual)
@@ -243,6 +243,7 @@
 			path)
 	  (with-input-from-file f
 	     (lambda ()
+                (set-correct-file-encoding!)
 		(let loop ((exp (read)))
 		   (if (eof-object? exp)
 		       (skribe-error 'api-search-definition
diff --git a/doc/user/src/outline.txt b/doc/user/src/outline.txt
index b00992a..4a8dd1e 100644
--- a/doc/user/src/outline.txt
+++ b/doc/user/src/outline.txt
@@ -1,7 +1,7 @@
 -*- mode: outline; coding: iso-8859-1; -*-
 
 Title: Demonstrating Skribilo's Outline Syntax
-Author: Ludovic Courtès
+Author: Ludovic Courtes
 Keywords: Skribilo outline Emacs
 
 This document aims to *demonstrate*
diff --git a/doc/user/syntax.skb b/doc/user/syntax.skb
index 730f78d..1442c39 100644
--- a/doc/user/syntax.skb
+++ b/doc/user/syntax.skb
@@ -190,6 +190,7 @@ to the native ,(tt [skribe]) syntax:])
 	      (flush :side 'left
 		(pre (with-input-from-file src
 			(lambda ()
+			  (set-correct-file-encoding!)
 			  (let loop ((line   (read-line))
 				     (result '()))
 			    (if (eof-object? line)
@@ -201,9 +202,9 @@ to the native ,(tt [skribe]) syntax:])
 	   (with-output-to-string
 	     (lambda ()
 	       (let* ((read  (make-reader 'outline))
-		      (input (open-input-file src))
-		      (sexp  (read input)))
-		 (pretty-print sexp :width 65)))))))
+		      (input (open-input-file src)))
+		 (set-correct-file-encoding! input)
+		 (pretty-print (read input) :width 65)))))))
       
       (p [The ,(tt [outline]) mode makes it possible to quickly create
 documents that can be output in variety of formats (see ,(numref :text
diff --git a/doc/user/user.skb b/doc/user/user.skb
index 86eda21..53b2e8a 100644
--- a/doc/user/user.skb
+++ b/doc/user/user.skb
@@ -50,7 +50,8 @@
 	     (skribilo evaluator)
 	     (skribilo config)
 	     (skribilo index)
-	     (skribilo lib))  ;; for `skribe-warning'
+	     (skribilo lib)   ;; for `skribe-warning'
+	     (skribilo utils syntax)) ;; `set-correct-file-encoding!'
 
 ;*---------------------------------------------------------------------*/
 ;*    SRFIs							       */
diff --git a/src/guile/skribilo.scm b/src/guile/skribilo.scm
index 7d066da..985e0cd 100644
--- a/src/guile/skribilo.scm
+++ b/src/guile/skribilo.scm
@@ -387,11 +387,7 @@ options."
         (if input-file
             (with-input-from-file input-file
               (lambda ()
-                (cond-expand (guile-2
-                              ;; Use the encoding specified by the `coding:'
-                              ;; comment.
-                              (let ((p (current-input-port)))
-                                (set-port-encoding! p (file-encoding p)))))
+                (set-correct-file-encoding!)
                 (doskribe user-module)))
             (doskribe user-module))
 
diff --git a/src/guile/skribilo/evaluator.scm b/src/guile/skribilo/evaluator.scm
index be223ca..07a578b 100644
--- a/src/guile/skribilo/evaluator.scm
+++ b/src/guile/skribilo/evaluator.scm
@@ -189,12 +189,7 @@
 	   ;; Load it
 	   (with-input-from-file filep
 	     (lambda ()
-               (cond-expand (guile-2
-                             ;; Use the encoding specified by the `coding:'
-                             ;; comment.
-                             (let ((p (current-input-port)))
-                               (set-port-encoding! p
-                                                   (file-encoding p)))))
+               (set-correct-file-encoding!)
 	       (evaluate-document-from-port (current-input-port) ei
                                             :module module
                                             :reader reader)))
@@ -222,10 +217,7 @@
 
     (with-input-from-file full-path
       (lambda ()
-        (cond-expand (guile-2
-                      ;; Use the encoding specified by the `coding:' comment.
-                      (let ((p (current-input-port)))
-                        (set-port-encoding! p (file-encoding p)))))
+        (set-correct-file-encoding!)
         (save-module-excursion
           (lambda ()
             (set-current-module module)
diff --git a/src/guile/skribilo/source.scm b/src/guile/skribilo/source.scm
index b0a2a7f..3d2c858 100644
--- a/src/guile/skribilo/source.scm
+++ b/src/guile/skribilo/source.scm
@@ -1,7 +1,7 @@
 ;;; source.scm	-- Highlighting source files.
 ;;; -*- coding: iso-8859-1 -*-
 ;;;
-;;; Copyright 2005, 2008, 2009  Ludovic Courtès <ludo@gnu.org>
+;;; Copyright 2005, 2008, 2009, 2010  Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright 2003, 2004  Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
 ;;;
 ;;;
@@ -110,6 +110,7 @@
 					      (path (*source-path*)))))
 	(with-input-from-file p
 	  (lambda ()
+            (set-correct-file-encoding!)
 	    (if (> (*verbose*) 0)
 		(format (current-error-port) "  [source file: ~S]\n" p))
 	    (let ((startl (if (string? start) (string-length start) -1))
@@ -194,6 +195,7 @@
 
 	 (else
 	  (let ((ip (open-input-file p)))
+             (set-correct-file-encoding! ip)
 	     (if (> (*verbose*) 0)
 		 (format (current-error-port) "  [source file: ~S]\n" p))
 	     (if (not (input-port? ip))
diff --git a/src/guile/skribilo/utils/syntax.scm b/src/guile/skribilo/utils/syntax.scm
index 4cb856f..5a42b09 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.
+;;; syntax.scm  --  Syntactic candy for Skribilo modules. -*- coding: utf-8 -*-
 ;;;
-;;; Copyright 2005, 2006, 2007, 2008, 2009  Ludovic Courtès <ludo@gnu.org>
+;;; Copyright 2005, 2006, 2007, 2008, 2009, 2010  Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;;
 ;;; This program is free software; you can redistribute it and/or modify
@@ -23,10 +23,11 @@
   :use-module (system reader compat) ;; make sure `current-reader' exists
   :use-module (system reader confinement)
   :export (%skribilo-module-reader skribilo-module-syntax
-           _ N_)
-  :export-syntax (unwind-protect unless when))
+           set-correct-file-encoding!
+           _ N_
+           unwind-protect unless when))
 
-;;; Author:  Ludovic Courtès
+;;; Author:  Ludovic Courtès
 ;;;
 ;;; Commentary:
 ;;;
@@ -83,6 +84,21 @@
             (car exprs)
             `(begin ,@exprs))))
 
+(cond-expand
+ (guile-2
+  (define-syntax set-correct-file-encoding!
+    (syntax-rules ()
+      ((_)
+       (set-correct-file-encoding! (current-input-port)))
+      ((_ port)
+       ;; Use the encoding specified by the `coding:' comment.
+       (let ((e (false-if-exception (file-encoding port))))
+         (and (string? e)
+              (set-port-encoding! port e)))))))
+ (else
+  (define-macro (set-correct-file-encoding! . p)
+    #f)))
+
 
 ;;;
 ;;; Gettext support.
@@ -98,10 +114,4 @@
 (define (N_ msg msgplural n)
   (ngettext msg msgplural n %skribilo-text-domain))
 
-
-;;; Local Variables:
-;;; mode: scheme
-;;; coding: latin-1
-;;; End:
-
 ;;; syntax.scm ends here