4

I have a bunch of html files encoded as iso-8859-1-unix and a few encoded in utf-8-unix. What I want is to encode all of them in utf-8-unix. I have already tried (I think they are the same command, actually):

C-x C-m f utf-8-unix
C-x RET f utf-8-unix

the modeline changes from 1 to U, but after I close the file and reopen it, the modeline shows 1 again. It seems that I cannot make the change permanent no matter what I try and I don't understand why.

Following the suggestions below, I have created a new file with this content

<ul class="navbar">
  <li><a href="index.php">home</a></li>
  <li><a href="bio.php">bio</a></li>
  <li><a href="research.php">research</a></li>
  <li><a href="software.php">software</a></li>
  <li><a href="contacts.php">contacts</a></li>
</ul>

C-h v buffer-file-coding-system returns this:

Its value is utf-8-unix
Local in buffer new.htm; global value is the same.

so it looks okay. I save, kill the buffer, reopen the file and C-h v buffer-file-coding-system returns this:

Its value is undecided-unix
Local in buffer new.htm; global value is utf-8-unix

I am really confused.

EDIT: thanks everybody for helping making this clear!

11
  • Are you saving the file after changing the encoding? Commented Feb 25, 2016 at 17:03
  • @JordonBiondo yes I am.
    – point618
    Commented Feb 25, 2016 at 17:07
  • 1
    C-h v coding RET you must issue this command in that buffer. Maybe there is a special character forcing Emacs think the file has in a particular coding. Or maybe you have something in your init file.
    – giordano
    Commented Feb 25, 2016 at 17:49
  • 1
    Sorry, my fault, see buffer-file-coding-system variable
    – giordano
    Commented Feb 25, 2016 at 18:27
  • 4
    The example you gave in the question contains only ASCII characters. So its UTF-8 encoding and Latin-1 encoding will be identical. In particular, there is no way for emacs to tell the encodings apart when you open the file. Anyhow, if the <head> section of your HTML file contains <meta charset='utf-8'>, then html-mode should use that to decide the encoding when you open the file. No need to use file local variables in this case. Commented Feb 25, 2016 at 19:31

2 Answers 2

0

N.B.: Question answered in comments.

0

using M-x add-file-local-variable RET coding RET utf-8 RET did not work for me. What did was to add this to the topmost line, as e.g.

# -*- coding: utf-8; -*-

(org-mode comment is #)

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