org-babel, ruby and encoding

905 views Asked by At

When I evaluate ruby code blocks inside org-mode I encounter utf-8 errors.

and indeed If i do

#+BEGIN_SRC ruby :exports both :results output
  puts RUBY_VERSION
  puts __ENCODING__
#+END_SRC

#+RESULTS:
: 2.1.1
: US-ASCII

and when i try to evaluate

#+BEGIN_SRC ruby
  'Aurélien'
#+END_SRC

I get this error in Org-Babel Error Output

-:3: invalid multibyte char (US-ASCII)
-:3: invalid multibyte char (US-ASCII)
-:3: syntax error, unexpected end-of-input, expecting keyword_end
'Aurélien'

If I start an inf-ruby buffer I can use utf-8, there is no problem. I think it is a problem with org-babel.

my configuration:

  • M-x emacs-version 24.4.1
  • M-x org-version 8.2.10
  • M-! ruby --version 2.1.1p76
  • from package list: inf-ruby 20141005.550 installed

In my init file I have

(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(setq buffer-file-coding-system 'utf-8)
(setq erc-server-coding-system '(utf-8 . utf-8))
(setq locale-coding-system 'utf-8)
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))

Is there a setting to change to have utf-8 by default for ruby code blocks and org-babel?

1

There are 1 answers

0
Aurélien Bottazini On BEST ANSWER

I found the problem.

On my mac, Emacs with a GUI default environment encoding is C.

In my init file, I specified an environment encoding with

(setenv "LANG" "fr_FR.UTF-8")
(setenv "LC_ALL" "fr_FR.UTF-8") 

and org-babel picks it up correctly