all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kenichi Handa <handa@m17n.org>
To: emacs-devel@gnu.org
Cc: ulm@gentoo.org
Subject: Re: Subsets of Unicode and coding systems
Date: Thu, 08 Dec 2011 13:16:26 +0900	[thread overview]
Message-ID: <tl7wra77l5x.fsf@m17n.org> (raw)

> Date: Tue, 6 Dec 2011 12:38:57 +0100
> From: Ulrich Mueller <ulm@gentoo.org>
> 
> 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
handa@m17n.org



             reply	other threads:[~2011-12-08  4:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-08  4:16 Kenichi Handa [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-12-06 11:38 Subsets of Unicode and coding systems Ulrich Mueller
2011-12-06 12:08 ` Eli Zaretskii
2011-12-06 12:24   ` Werner LEMBERG

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tl7wra77l5x.fsf@m17n.org \
    --to=handa@m17n.org \
    --cc=emacs-devel@gnu.org \
    --cc=ulm@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.