Skip to main content
11 votes

How convert txt file to UTF-8 from Windows-1251?

One should use the command set-buffer-file-coding-system (C-x RET f), set the encoding, and then save the file. Note that you may want to first revert-buffer-with-coding-system (C-x RET r) before ...
xji's user avatar
  • 2,685
9 votes

How to get rid of BOM (byte order mark)

Check out the file encoding with C-h C RET. If there is a byte order mark in the file, you may see something like this in the *Help* buffer: Coding system for saving this buffer: U -- utf-8-with-...
Harald Hanche-Olsen's user avatar
8 votes
Accepted

Getting no-conversion (nil) encoding each time when opening a file (which should be in utf-8)

As mentioned in comments, NUL bytes in the files seem to have caused it, though I have no idea how they got in. The following sed command gets rid of them: sed -i s/"\x0"// file.org The next time ...
xji's user avatar
  • 2,685
7 votes
Accepted

How to open a file which looks like unicode in emacs

It's a file encoded in utf-16 little endian format without the byte order mark. You have to specify the endianness selecting utf-16-le when you use revert-buffer-with-coding-system
matteol's user avatar
  • 2,088
6 votes
Accepted

How to query/set the character encoding?

From chapter "Choosing Coding Systems for Output" of emacs manual: Once Emacs has chosen a coding system for a buffer, it stores that coding system in ‘buffer-file-coding-system’. That makes it ...
JeanPierre's user avatar
  • 7,515
6 votes
Accepted

Encoding issue for French text

This is the MacRoman encoding, a legacy encoding from the pre-OSX days of Mac OS. It is available in Emacs as mac-roman. C-x RET r mac-roman RET yes RET You may need to select mac-roman-mac, mac-...
Gilles 'SO- stop being evil''s user avatar
5 votes

Set default coding system = UTF-8

This does it for me: (set-language-environment "UTF-8") See here.
ceving's user avatar
  • 1,388
5 votes

Key bound to string does not handle some chars in string correctly

global-set-key is just a thin wrapper around define-key, ignoring some error checking it is (defun global-set-key (key def) (define-key (current-global-map) key def)) The documentation for define-...
icarus's user avatar
  • 1,934
5 votes
Accepted

Strange encodings in ORG mode with German umlaute

Your problem is not one of encoding but one of decoding. Try C-x RET r utf-8 RET, which should re-decode your file as utf-8 rather than that which was used by default. I recommend you add a -*- ...
Stefan's user avatar
  • 26.7k
5 votes
Accepted

Make `re-search-forward` return string with Korean characters

In order to handle non-ASCII characters, you need turn on multibyte via (set-buffer-multibyte t) (see also (elisp) Selecting a Representation), e.g., (with-current-buffer (url-retrieve-synchronously ...
xuchunyang's user avatar
  • 14.8k
4 votes

How many bytes are in the region?

While Drew's answer will work correctly in many cases (where utf-8 is pervasive and if you don't use DOS-style EOLs), if you want to make it work reliably for "all" buffers, you could do something ...
Stefan's user avatar
  • 26.7k
4 votes
Accepted

How many bytes are in the region?

Sounds like you are asking for something like this: (defun region-bytes () (interactive) (let ((strg (if (use-region-p) (buffer-substring-no-properties (region-beginning) (...
Drew's user avatar
  • 79.1k
4 votes

How to get rid of BOM (byte order mark)

M-x set-buffer-file-coding-system, hit TAB to get a completion list, select encoding you desire (one without BOM), then save the file.
Willy Lee's user avatar
  • 480
4 votes
Accepted

Key bound to string does not handle some chars in string correctly

What is going on is that string in Emacs have historically been used in this context for 2 different purposes: sequence of characters. sequence of events. In your case, you're writing what you think ...
Stefan's user avatar
  • 26.7k
4 votes
Accepted

How encode to UTF-8 content of buffer?

Emacs decodes a text file with an appropriate coding system when you open it with find-file. If you have to tell emacs for some reason what coding system it should use for decoding the file you should ...
Tobias's user avatar
  • 33.7k
4 votes

Replace certain multibyte characters

Most likely your file is actually not using latin-1, yet your Emacs tries to decode it as if it were using latin-1. Try C-x RET r windows-1252 RET to see if it fixes your problem. If it does, you'll ...
Stefan's user avatar
  • 26.7k
4 votes
Accepted

Display only the buffer coding systems but not keyboard or terminal coding system in mode line

The last of the three mule-info characters corresponds to the buffer coding system in Emacs 28.1. So I give a solution for that case. It is right that the replacement for "%z" is hard-coded ...
Tobias's user avatar
  • 33.7k
4 votes

Nordic characters rendered incorrectly in non-file buffers

The fact that you could paste the characters in to your question and have them show up exactly the same as in your screenshot shows us exactly what is going on. Unicode has two diaeresis characters. ...
db48x's user avatar
  • 19.1k
3 votes

How encode to UTF-8 content of buffer?

Your problem has nothing to do with utf-8. Your screenshot of Notepad++ indicates Windows-1251 encoding for that file as you can see at the right end of the status line of Notepad++. Therefore you ...
Tobias's user avatar
  • 33.7k
3 votes

Set default coding system = UTF-8

I do not know if this can be of help, but I will mention it anyway. When working (mainly in source LaTeX files) with my colleagues who use a different coding system, nothing I did could persuade ...
F. Tusell's user avatar
  • 211
3 votes

File names encoding when running shell-command on Windows XP

For windows in ru environment I have the following: (setq default-process-coding-system '(utf-8-dos . cp1251-dos)) It let's me process files in russian from emacs using external shell invocations ...
Maxim Kim's user avatar
  • 1,816
3 votes
Accepted

Encoding in buffers not associated with files

Emacs decides how to decode output from subprocesses (like git) based on the value of default-process-coding-alist (and others, see (elisp) Default Coding Systems). The default value for this ...
npostavs's user avatar
  • 9,253
3 votes

How to get rid of BOM (byte order mark)

A comment by SabreWolfy really should be provided as an answer: As explained in a blog post by Bojan Nikolic, the BOM (which really is the Unicode character U+FEFF ZERO WIDTH NON-BREAKING SPACE placed ...
3 votes

UnicodeEncodeError executing python in Emacs - not in Terminal

A solution that I found over on Stackoverflow was the following proposed here for a UnicodeDecodingError, which did work for me: (setenv "LANG" "en_US.UTF-8") (setenv "LC_ALL" "en_US.UTF-8") (setenv "...
n1k31t4's user avatar
  • 689
3 votes

How can I save UTF-8 files with a Byte Order Mark?

Pityingly I can only give an answer to the second question "How can I fix this". Let emacs guess the file encoding after finding the file via html-mode-hook and use it for saving the file via save-...
Tobias's user avatar
  • 33.7k
3 votes

How can I view accent characters natively?

I guess the encoding of your file is not properly detected. Typing C-x RET r windows-1252 RET should display your file properly as it forces Emacs to interpret the file as windows-1252 and not utf-8 ...
Damien Cassou's user avatar
3 votes

How can I find non-displayable unicode characters in a buffer?

Robert Pluim proposed already a solution. The credit for describe-char-display belongs to him. Here I detail what I meant in my comment to his answer. I've got the impression that this solution is ...
Tobias's user avatar
  • 33.7k
3 votes

How to delete ^M in the diffs of Magit?

Do I need to make Magit aware of my file system encoding. If so, how? By configuring Git accordingly using core.eol and related variables described in git-config(1). By asking a search engine about "...
tarsius's user avatar
  • 26.3k
3 votes
Accepted

Emacs converts character to raw-byte when inserting

Here's an experiment you can try: (let ((str "foo")) (aset str 2 ?¶) str) "fo\266" (let ((str (string-to-multibyte "foo"))) (aset str 2 ?¶) str) "fo¶" If I do ...
NickD's user avatar
  • 33.6k

Only top scored, non community-wiki answers of a minimum length are eligible