0

I am running Emacs 25 on Ubuntu 18.04. When I type accents, they display properly, but when I close and then reopen the file they appear like a backslash and then an octal number. This only happens with one particular file: all other files I process with Emacs on the same computer and same user account save and display accents fine. How is that possible? Whatever settings are contained in the .emacs config file would apply to all files? I've tried to set the coding system on the individual file that is causing problems, with the command set-buffer-file-coding-system and then selecting utf-8-unix, but I get the message: utf-8-unix cannot encode these: é

How can I fix the encoding of this file?

@DoMiNeLa10 Thanks for your reply. Nothing particular with file name, nor comments and the major mode is org-mode. What I suspect that has happened is that the problematic file has weird characters from copy/pastes from webpages. For instance, it contains the octal sequence \342\200\224 which on the original web page looks like a long dash. I suspect emacs doesn't know how to display it and then gets confused and gives up altogether trying to figure out the encoding; For instance, the file is full of the octal sequence \303\251 which is just accented é, that emacs should know how to display (as I said in my previous post I tried the command set-buffer-file-coding-system and then selected utf-8-unix, but it continues to display accents as octal sequences)

Is there a way to force emacs to use the utf-8-unix encoding to display accents correctly and just ignore the octal sequences that are not part of the encoding? I mean, I don't mind that the weird characters just remain octal sequences in the file, but I want to see the accents.

@Stefan: the output of checking: M-L buffer-file-coding-system RET

buffer-file-coding-system is a variable defined in ‘C source code’.
Its value is ‘no-conversion’
Local in buffer todo1.org; global value is utf-8-unix
Automatically becomes buffer-local when set.

I tried C-x RET r utf-8 RET as you suggested and it works well, displaying all accents correctly instead of backslash octal sequences and the buffer-file-coding-system value becomes utf-8, but if I close the file and then open again, the backslash octal mess reappears and the value reverts to 'no-conversion'.

@DoMiNeLa10 I ctrl-c to copy from firefox and ctrl-y to paste in emacs. Sometimes, I just select in firefox and then middle-click mouse button to paste. Maybe pasting with the middle-click mouse button is the cause of the problem?

  • What file is causing you trouble. Does it have any comments that could override Emacs settings? Is there anything particular with its name (such as trailing spaces). What major mode are you using to edit it? – DoMiNeLa10 Dec 22 '18 at 11:47
  • Are you using Emacs in a terminal? How are you pasting text into it? – DoMiNeLa10 Dec 23 '18 at 20:05
0

When you open the file what coding-system does Emacs use (you can see it at the leftmost part of the mode-line right before the char that indicates the EOL (typically a :)). If you don't know where that is try: M-: buffer-file-coding-system RET.

You can probably get Emacs to re-read the file correctly with C-x RET r utf-8 RET, but the above info might help us figure out how to get Emacs to choose utf-8 in the first place without you tell Emacs manually every time.

0

I had the same problem, randomly occurring with some LaTeX files. Seems to be the case that Emacs does not always recognize the encoding. For me, the solution was to have as a first line of the file (% is the comment character for LaTeX) the following:

% -*- coding: iso-8859-15 -*-

This informs Emacs of the encoding to use. I never again have had the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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