4

When I insert an — (em dash) into a text file, Emacs initially displays it fine. When I reload Emacs, all instances of — are displayed as \342\200\224.

How can I get Emacs to display the characters as it did initially? I'm using Windows 7 and Emacs 24.3.1. The major mode is "Text" and minor is "Fill".

Simon Morgan
  • 2,018
  • 5
  • 23
  • 36
  • What does the indicator in the modeline show? (at the very beginning it must be `U`, otherwise Emacs didn't recognize (or probably didn't even save) the file as some of Unicode variety. Try saving it as Unicode after you insert wide characters by doing `C-x C-m f` (select some Unicode encoding) `C-x C-s`. –  Jul 08 '13 at 20:41
  • C-x C-m puts me into a command line. – Simon Morgan Jul 08 '13 at 23:31
  • If by command line you mean minibufer, than that's the desired effect. You could then start typing "utf" and pres `TAB` to see possible completion options. If you have this binding altered, or your terminal interprets it differently, you could do `M-x set-buffer-file-coding-system` - which is the same thing. –  Jul 09 '13 at 05:58
  • Nope, it literally starts a command line inside an Emacs buffer. C-m seems to be an alias for RET by default from what I've read. Thanks for the function name. – Simon Morgan Jul 09 '13 at 11:33
  • Yup, more precisely, it's the other way around: `RET` is the alias for `C-m`. Our ancestors made a very strange use of their keyboards... Well, still, it should work whichever way you do it, `C-x C-m f` just seems easier because you don't need to release the control key / `m` is just behind your index finger. –  Jul 09 '13 at 12:41

1 Answers1

4

Try inserting this into your init file. It should make sure emacs saves files as Unicode (and reads them correctly afterwards).

;;;;;;;;;;;;;;;;;;;;
;;; set up unicode
(prefer-coding-system       'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)                      
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))

I'm fairly certain most of these options are unnecessary, but after inserting them I never had encoding problems again. Better safe than sorry. :-)

Malabarba
  • 4,473
  • 2
  • 30
  • 49