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 ...
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-...
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 ...
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
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 ...
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-...
5
votes
Set default coding system = UTF-8
This does it for me:
(set-language-environment "UTF-8")
See here.
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-...
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 -*- ...
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
...
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 ...
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) (...
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.
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 ...
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 ...
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 ...
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 ...
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. ...
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 ...
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 ...
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 ...
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 ...
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 ...
Community wiki
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 "...
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-...
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 ...
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 ...
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 "...
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
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
character-encoding × 145unicode × 19
microsoft-windows × 12
utf-8 × 11
org-mode × 8
characters × 7
fonts × 6
input-method × 6
ess × 5
process × 5
magit × 4
copy-paste × 4
display × 4
init-file × 3
python × 3
osx × 3
shell × 3
terminal-emacs × 3
term × 3
emacsclient × 2
files × 2
mode-line × 2
email × 2
replace × 2
r × 2