emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subsets of Unicode and coding systems


From: Kenichi Handa
Subject: Re: Subsets of Unicode and coding systems
Date: Thu, 08 Dec 2011 13:16:26 +0900

> Date: Tue, 6 Dec 2011 12:38:57 +0100
> From: Ulrich Mueller <address@hidden>
> 
> Sometimes I want to check if a file saved in UTF-8 encoding contains
> only characters from a certain subset of the Unicode character
> repertoire, like the MES-* [1] or WGL4 [2] subsets. (For example, for
> things published on the WWW one might rather avoid exotic characters
> for better compatibility.)
> 
> My idea was now to define a coding system e.g. for MES-2 and set the
> buffer-file-coding-system accordingly, so that Emacs would check it
> upon saving the file.
> 
> Now I have the following questions:
> 1. Is using coding systems for this purpose a reasonable approach
>    at all, or is there a better way to achieve this?
> 2. Where can I find documentation how to define a coding system?

I agree with Eli, defining proper categories provides more
flexible usage, but FYI, something like this defines the
coding system utf-8-mes-2.

(let ((repertory '((0 . #x017f) #x018f #x0192 #x01b4 
                   (#x01de . #x01ef) (#x01fa . #x01ff)
                   ;;; add more here
                   ))
      list)
  (dolist (elm repertory)
    (if (consp elm)
        (let ((from (car elm))
              (to (cdr elm)))
          (while (<= from to)
            (setq list (cons from (cons from list)))
            (setq from (1+ from))))
      (setq list (cons elm (cons elm list)))))
  (define-charset 'unicode-mes-2 "MES-2 subset of Unicode"
    :code-space [0 255 0 255]
    :ascii-compatible-p t
    :map (apply 'vector (nreverse list)))
  (define-coding-system 'utf-8-mes-2 "UTF-8 for MES-2 subset"
    :mnemonic ?M
    :coding-type 'utf-8
    :charset-list '(unicode-mes-2)
    :mime-charset 'utf-8))

See the docstring of define-charset and define-coding-system
to understand the code.

---
Kenichi Handa
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]