3

I'm trying to open the edict2.gz file from http://www.edrdg.org/jmdict/edict_doc.html which is a japanese->english dictionary so first I changed the extension to .txt. Currently there are many characters represented as \217\264\321 for example instead of the actually kanji character.

Next I try M-x revert-buffer-with-coding-system and different coding systems such as utf-8 (doesn't help at all), japanese-shift-jis-2004 (helps but there are still a few characters left as \362 etc, so I think this is out of date, and japanese-iso-8bit works! (is this the right one to use?)

How can I always open this file with the proper coding system so that I don't have to run the M-x revert-buffer-with-coding-system each time? Is there a special file ending (.jp or something) that will automatically invoke that coding system? I plan to parse it later similar to how Josh does it in his presentation here https://www.youtube.com/watch?v=uraPXeLfWcM

1 Answer 1

5

If you can edit the file, you can specify the pseudo-variable coding as a file-local variable.

e.g.: -*- coding: japanese-iso-8bit; -*-

If you can't (or don't want to) edit the file, but this is only needed for yourself, then the "Using Directory Local Variable classes for individual files" trick described on that same page would be an option; but using file-coding-system-alist is probably a better one.

e.g.:

(push (cons (regexp-quote (expand-file-name "/path/to/file"))
            'japanese-iso-8bit)
      file-coding-system-alist)

See C-hv file-coding-system-alist RET for details.

1
  • 1
    I went onto the emacs irc channel and found a few alternate solutions also. M-x revert-buffer-with-coding-system RET japanese-iso-8bit RET M-x set-buffer-file-coding-system RET utf-8 RET will save the file as utf-8 so you can have a copy that is readable outside of emacs as well. (It turns out on their ftp server there was this utf-8 version already but required more digging to find (as someone on reddit showed me)
    – irregular
    May 18, 2016 at 3:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.