Skip to content

Instantly share code, notes, and snippets.

@nurse
Last active January 24, 2017 05:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nurse/555963 to your computer and use it in GitHub Desktop.
Save nurse/555963 to your computer and use it in GitHub Desktop.
JIS8 charset for emacs

IRC 等で用いられるいわゆる半角カナを含む ISO-2022-JP variant の emacs 用設定

文字セット

reg#  character set       ESC sequence  designated to
------------------------------------------------------
  6   US-ASCII            ESC ( B       G0
 13   JIS X 0201-Katakana ESC ( I       G0
 14   JIS X 0201-Roman    ESC ( J       G0
 42   JIS X 0208-1978     ESC $ @       G0
 87   JIS X 0208-1983     ESC $ B       G0
159   JIS X 0212          ESC $ D       G0
 13   JIS X 0201-Katakana ESC ) I       G1
reg#  character set       shift in with designated to
------------------------------------------------------
6     US-ASCII            SI            G0
13    JIS X 0201-Katakana SO            G0

  • G1は常に JIS X 0201-Katakana固定
  • JIS X 0201-Katakanaの出力はG1を用いる

データ例

  • ruby -e'puts"coding:jis8\n\e$B$"$$$&\e(J\xB1\xB2\xB3\e(Babc\e$B4A;z\e(B"'>j1.txt
  • ruby -e'puts"coding:jis8\n\e$B$"$$$&\e(Babc\e$B4A;z\e(B"'>j2.txt

設定

;;JIS8
(require 'cp5022x)
(define-coding-system 'jis8
  "JIS8"
  :coding-type 'iso-2022
  :mnemonic ?J
  :designation [(ascii japanese-jisx0208-1978 japanese-jisx0208 japanese-jisx0212
                       latin-jisx0201)
                 katakana-jisx0201 nil nil]
  :flags '(short ascii-at-eol ascii-at-cntl designation)
  :charset-list '(ascii japanese-jisx0208 japanese-jisx0212
                        japanese-jisx0208-1978 latin-jisx0201
                        katakana-jisx0201)
  :decode-translation-table '(cp51932-decode japanese-ucs-jis-to-cp932-map)
  :encode-translation-table '(cp51932-encode japanese-ucs-cp932-to-jis-map))

emacs 23.2.1 における問題

  • 入力にG1なカタカナが混ざるとそこ以外が化ける。
  • 保存時にいわゆる半角カナを混ぜるとUTF-8で保存される

j1.txt coding:jis8 ^[$B$"$$$&^[(Jアイウ^[(Babc^[$B4A;z^[(B

j2.txt coding:jis8 あいうabc漢字

coding:jis8 あいうabc漢字

links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment