From 86de6d9453a9d747bddadd20fce67e58c4dbe8c7 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Mon, 8 Mar 2010 00:27:57 +0100 Subject: Factorize encoding twiddling in `set-correct-file-encoding!'. * doc/modules/skribilo/documentation/api.scm (api-search-definition): Call `set-correct-file-encoding!'. * doc/user/src/outline.txt (Author): Remove accent from last name, as a temporary hack. * doc/user/syntax.skb: Call `set-correct-file-encoding!' in the `outline' syntax example. * doc/user/user.skb: Use `(skribilo utils syntax)'. * src/guile/skribilo.scm (skribilo): Replace encoding twiddling with `set-correct-file-encoding!' call. * src/guile/skribilo/evaluator.scm (load-document, include-document): Likewise. * src/guile/skribilo/source.scm (source-read-lines): Call `set-correct-file-encoding!'. (source-read-definition): Likewise. * src/guile/skribilo/utils/syntax.scm (set-correct-file-encoding!): New macro. --- src/guile/skribilo.scm | 6 +----- src/guile/skribilo/evaluator.scm | 12 ++---------- src/guile/skribilo/source.scm | 4 +++- src/guile/skribilo/utils/syntax.scm | 32 +++++++++++++++++++++----------- 4 files changed, 27 insertions(+), 27 deletions(-) (limited to 'src/guile') 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 +;;; Copyright 2005, 2008, 2009, 2010 Ludovic Courtès ;;; Copyright 2003, 2004 Erick Gallesio - I3S-CNRS/ESSI ;;; ;;; @@ -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 +;;; Copyright 2005, 2006, 2007, 2008, 2009, 2010 Ludovic Courtès ;;; ;;; ;;; 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 -- cgit v1.2.3