diff --git a/README b/README index f4ff21124922e48a845320d741fe70eacec052e9..a43913a74b2e7f5d916ec8d9f23e2298cbd0cea3 100644 --- a/README +++ b/README @@ -2,12 +2,13 @@ ASDF-ENCODINGS This library allows you to use ASDF with Lisp source files that use an encoding different from either ASCII or UTF-8. -It depends on ASDF 2.21 or later (actually 2.20.7 or later). +It depends on ASDF 2.21 or later (actually 2.20.18 or later). TODO: (1) actually support more implementations. (2) Add a test suite. (3) Test it. +(4) Add more corner cases. ==== Exported Functionality ==== @@ -30,3 +31,24 @@ function ENCODING-EXTERNAL-FORMAT (ENCODING &KEY (ON-ERROR *ON-UNSUPPORTED-ENCOD the current implementation's CL:OPEN, CL:LOAD or CL:COMPILE-FILE functions. If the encoding is not supported on this implementation, the ON-ERROR argument, which is one of :ERROR, :WARN, NIL, specifies what to do. + +variable *ON-UNSUPPORTED-ENCODING* + One of :error, :warn or nil, + specifies what to do when passed an unsupported encoding. + Defaults to :error. + +function DETECT-FILE-ENCODING (PATHNAME) + This function takes a pathname designator, + and returns a portable encoding as detected by the file contents, + either an emacs-style -*- coding: foo -*- declaration, + or something deduced from the octet patterns in the file. + +function NORMALIZE-ENCODING (ENCODING) + Given a portable encoding keyword, returns the normalized keyword + describing that encoding on the current implementations, if any, + or NIL if the encoding is not present on the implementation + (or not recognized by asdf-encodings). + +function FIND-IMPLEMENTATION-ENCODING (ENCODING) + Given a normalized encoding keyword, returns + an external-format suitable for use on the current implementation, if any. diff --git a/asdf-support.lisp b/asdf-support.lisp index ecc09cb180a246e95067432b8bcd106a27ca68b8..bf1e920e2bb3ed7b72c1542f2044440d2d973547 100644 --- a/asdf-support.lisp +++ b/asdf-support.lisp @@ -2,6 +2,9 @@ (in-package :asdf-encodings) +(defvar *on-unsupported-encoding* :error + "One of :error, :warn or nil, specifies what to do when passed an unsupported encoding.") + (defun encoding-external-format (encoding &key (on-error *on-unsupported-encoding*)) (or (and (eq encoding :default) :default) (find-implementation-encoding (or (normalize-encoding encoding) encoding)) @@ -13,5 +16,5 @@ (defun register-asdf-encodings () (setf asdf:*encoding-external-format-hook* 'encoding-external-format - asdf:*encoding-detection-hook* 'detect-encoding) + asdf:*encoding-detection-hook* 'detect-file-encoding) (values)) diff --git a/autodetect.lisp b/autodetect.lisp index 8aa0c7651284dde62a29fb239ed0aa0c1a33fb96..08ef091ddcd536767fc2755c61e76583396d2a9c 100644 --- a/autodetect.lisp +++ b/autodetect.lisp @@ -153,7 +153,7 @@ ((cdr (assoc "encoding" options :test 'equalp))) ((cdr (assoc "coding" options :test 'equalp))))))) -;;; Examine the 'file to determine the encoding. +;;; Examine the file to determine the encoding. ;;; In some cases the encoding can be determined ;;; from the coding of the file itself, ;;; otherwise it may be specified in a file options line @@ -162,7 +162,7 @@ ;;; but is valid UTF-8 using then UTF-8 specific characters ;;; then :utf-8 is returned, otherwise :latin1 is returned. -(defun detect-encoding (file) +(defun detect-file-encoding (file) (let ((initial-encoding nil) (declared-encoding nil)) (with-open-file (s file :element-type '(unsigned-byte 8) diff --git a/encodings.lisp b/encodings.lisp index 1f543940be01be95720ad8681fcadbf0e08e25cb..ece9cd42759d3626814a7457499a1b80396c2248 100644 --- a/encodings.lisp +++ b/encodings.lisp @@ -4,9 +4,6 @@ (in-package :asdf-encodings) -(defvar *on-unsupported-encoding* :error - "One of :error, :warn or nil, specifies what to do when passed an unsupported encoding.") - (defparameter *encodings* ;; Define valid names for an encoding. ;; We prefer the main name in Wikipedia, diff --git a/pkgdcl.lisp b/pkgdcl.lisp index ca4c295aa33d58cadc67c5a7480ae79cb69f0ca0..df7a42cbacc2e6e4c0eb44b6856be288614f6f9e 100644 --- a/pkgdcl.lisp +++ b/pkgdcl.lisp @@ -6,6 +6,7 @@ (:use :cl) (:export #:encoding-external-format + #:*on-unsupported-encoding* + #:detect-file-encoding #:normalize-encoding - #:find-implementation-encoding - #:*on-unsupported-encoding*)) + #:find-implementation-encoding))