I have this in my init.el

(defvar dropbox-d "C:/Dropbox")
(defvar dropbox-emacs-d (expand-file-name "emacs" dropbox-d))
(org-babel-load-file (expand-file-name "config.org" dropbox-emacs-d))

In config.org I have, among other things:

#+BEGIN_SRC emacs-lisp
(use-package perspective :load-path "packages/perspective"
  :bind-keymap ("C-ä" . perspective-map)

When config.org is converted to config.el, config.el contains this:

(use-package perspective :load-path "packages/perspective"
  :bind-keymap ("C-ä" . perspective-map)

Does anyone know why this character conversion happen? Both init.el and config.org are saved in utf-8 format. I have also tried adding the code below before loading config.org, and I have tried it with both the org-mode version shipped with emacs and the latest org-mode version.

(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
  • When you open config.el in Emacs, what coding system does Emacs use to read it? Check the value of buffer-file-coding-system in that buffer.
    – legoscia
    Oct 1 '15 at 10:54
  • @legoscia Emacs says: Its value is utf-8-dos Local in buffer config.el; global value is utf-8 Oct 1 '15 at 12:57
  • Just to double-check, what does it say about config.org?
    – legoscia
    Oct 1 '15 at 14:36
  • @legoscia I think I've tried to change the encoding of the files (after I got the first error), however it says: Its value is utf-8-unix Local in buffer config.org; global value is utf-8 Oct 1 '15 at 15:30

Not sure if I should post this as an answer or not, but anyway here it goes:

Adding (prefer-coding-system 'utf-8) before calling org-babel-load-file was actually the solution. The problem was that org-babel-load-file doesn't convert the .org-file unless there has been changes to the .org-file. Thus the previous version of the converted .el-file (in my case config.el) was run, and this version already had the bad characters written to it.

Since I only made changes to my init.el while tinkering with this problem, config.org wasn't modified. By removing config.el (or making a change in config.org), a new version of config.el was generated, and (prefer-coding-system 'utf-8) made sure that the ÅÄÖ characters worked.

  • Definitely solved my problem. I even encoded my .org file to utf-8 and deleted the .el file, but Emacs was still creating the .el file in non-UTF-8.
    – Beetle B.
    May 20 '20 at 16:53

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.