Emacs failure in loading charset map when saving file with unicode
Asked Answered
M

3

5

I created an ordinary text file on Windows 7 64-bit using gnu emacs 23.3.1. I can edit the file with other programs such as LinqPad (the file happens to be a linqpad script, extension .linq). Everything is fine until I put a Unicode character in the file, a character such as the greek letter λ (lambda). I can input the letter in emacs and it displays correctly. However, emacs refuses to save the file, reporting the following error

Failure in loading charset map: 8859-7

If I input the λ in LinqPad, emacs will read and display them, but will not save the file.

I just noticed that Notepad++ has other unexpected behavior with this file: it does not display the λ's, but instead pairs of odd characters such as λ. That is fitting to an untuition (pun intended) that the unicode chars are being stored as pairs. So it looks like this is a kind of ambiguous situation (storing unicode in text files), but it also looks like linqPad and visual studio "do the obvious thing."

I want to use emacs because it's the only program that I have that reflows sequences of commented lines (lines after //, reflows them with Alt-Q), and I want to use greek characters in my comments because I'm describing a mathematical program.

I'll be grateful for advice and answers.

UPDATE: some advice in other questions said to try M-x describe-char, also bound to C-x = ; both of those give me the same failure message as above, so they're on the right track, just not answers.

Maines answered 28/8, 2011 at 23:56 Comment(0)
P
7

This once happened to me when I had upgraded all packages (including Emacs) without realising I still had an Emacs session open during the upgrade. Next time I asked it to save some Unicode, it tried to load 8859-7 and failed because the path was different in the upgraded version. I had to redo the edit after restarting Emacs.

Pompon answered 14/5, 2019 at 12:34 Comment(0)
T
2

I just noticed that Notepad++ has other unexpected behavior with this file: it does not display the λs, but instead pairs of odd characters such as λ.

λ is what you get when you interpret the byte sequence 0xCE, 0xBB using the encoding ISO-8859-1, or Windows code page 1252 (Western European). Code page 1252 is probably the default (‘ANSI’) code page on your machine.

0xCE, 0xBB is the UTF-8 encoding of the character λ (U+03BB Greek small letter lambda). So to display it correctly you need to tell your text editor that the file is saved in UTF-8 and not ANSI.

In Notepad++, choose UTF-8 from the menu bar ‘Encoding’ entry.

In Emacs, C-x C-m c utf-8-dos (or unix or whatever) as a prefix to opening or saving the file. Hopefully by saving in UTF-8 you'll avoid whatever the problem is with the ISO 8859-7 (Greek) map; you certainly don't want to be saving any files in 8859-7, or indeed anything but UTF-8, if you can help it.

Triumphant answered 29/8, 2011 at 13:51 Comment(5)
This is great info, and I'm getting closer -- C-x C-m on my emacs installation immediately executes "save-some-buffers-without-asking" and does not wait for me to put in "c" and the rest. I'm not sure what the original key binding to C-x C-m would be, nor how to find out. Searching "apropos" "utf-8-dos" uncovers nothing. I will next try a fresh, bare installation of emacs because this one is quite old with hundreds of customized elisp files that I acquired from a colleague.Maines
Hmm, C-X C-m c works for me on Linux (where it's utf-8-unix by default). I don't have a Windows Emacs to hand but I think the default binding should be the same...Triumphant
ok, bypassing all the old customizations freed up C-x C-m c and it does accept C-x C-m c utf-8-dos for the save command, but still barks about failure to load 8859-7. I wonder if I could input 0xCE 0xBB in the file directly, emacs might decide to save it when i specify utf-8-dos. The way I'm inputting the λ now is via Windows keyboard software (control-panel, regional), and the λ shows up literally as that glyph in the emacs window pane. Usually, C-q lets me key-in non-standard chars like other control chars, but I don't know how to key 0xCE 0xBB. Getting closer!Maines
Ok so after entering utf-8-unix I then says "Command to execute with utf-8-unix:" and is waiting for me to enter something. I thought maybe "save" but as soon as I hit the first character it inserted "^M" into my document and exited the mode, and nothing was saved. What am I supposed to do here?Nazarius
And btw, i'm not trying to enter Greek, I'm trying to save a file with the +/- character ("±")Nazarius
A
1

I just upgraded my system and hit this problem as well. My Emacs version was updated to 27.2 from 26.1. The quick fix (aka kluge) I used was to cd into /usr/share/emacs as root and run:

% ln -s  27.2  26.1

Now I could finish my editing session and save all my files before rebooting.

Alys answered 1/1 at 21:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.