org-babel, ruby and encoding - emacs

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?

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

Related

One-shot command to knit and latexmk under Emacs + AUCtex

I want to knit AND latexmk Knitr documents using one AUCtex command.
I don't know how to code in lisp, and web search didn't turn up anything like this.
I have something close. The extension of the file needs to be changed for latexmk.
Any help will be appreciated.
Following line is for my .emacs file.
(add-hook 'LaTeX-mode-hook (lambda () (push '
("KnitrLaTeX" "Rscript -e \"library(knitr)\; knit('%s')\" && latexmk -pdf %s"
TeX-run-TeX nil t :help "Run knitr and latexmk on file")
TeX-command-list)))
When I run C-c C-c (KnitrLaTeX), emacs runs the following command:
Running `KnitrLaTeX' on `slides.Rnw' with ``Rscript -e "library(knitr); knit('slides.Rnw')" && latexmk -pdf slides.Rnw''
Which is wrong. It should read "... && latexmk -pdf slides.tex"
Thanks in advance.
It appears that you are having trouble with how the second usage of %s is being interpreted at the tail end of your compile command -- i.e., you want the second usage of %s to mean slides.tex instead of slides.Rnw.
Although I am not familiar with knit, I am familiar with creating custom variables for use with AUCTeX. Set forth below are some examples of how to create custom variables and add them to the TeX-expand-list.
Rather than of using %s for a second time (i.e., at the tail end of your compilation command), perhaps consider using %(tex-file-name) instead. This assumes that your *.tex file is open in the buffer with focus when you begin your compilation command -- i.e., the full file name will be inserted into your compilation command.
If you have a file with a different extension that is open in the buffer with focus when you run your compilation command, and if you want the base name to be the same (but with a different extension), then you would do something similar to the example of %(pdf-file-name) -- i.e., remove whatever extension is there and replace it with the new one.
(eval-after-load "tex" '(progn
(add-to-list 'TeX-expand-list '("%(tex-file-name)" (lambda ()
(concat "\"" (buffer-file-name) "\""))))
(add-to-list 'TeX-expand-list '("%(pdf-file-name)" (lambda ()
(concat
"\"" (car (split-string (buffer-file-name) "\\.tex"))
".pdf" "\""))))
(add-to-list 'TeX-expand-list '("%(line-number)" (lambda ()
(format "%d" (line-number-at-pos))))) ))

write mail with mutt using emacs

I am using both mutt and emacs to write mail.
I use, until recent time, this code into my .emacs :
; corrector
(add-hook 'mail-mode-hook 'flyspell-mode)
; Do not cut words
(global-visual-line-mode t)
; open mail-mode when emacs is invoked by mutt
(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
; wrap email body
(add-hook 'mail-mode-hook 'turn-on-auto-fill)
(add-hook 'mail-mode-hook 'turn-on-filladapt-mode)
But it is not working anymore. When I write a email with emacs I have no flyspell enable and the mail-mode does not wrap the text.
When I try to launch the mail-mode manually, I have a error :
File mode specification error: (void-function turn-on-filladapt-mode)
Making completion list... [2 times]
run-hooks: Symbol's function definition is void: turn-on-filladapt-mode
The problem was caused by the missing package emacs-goodies.el (in debian sid) which include filladapt.

Emacs Auctex compile error: "Use M-x make-directory RET RET to create the directory and its parents"

I am running emacs 23.3.1 on ubuntu 12.04 with auctex 11.86. Whenever I go to compile a latex document (using C-c C-c), if there are no errors, everything compiles just fine. However, if there are any errors it will tell me to use C-` to view errors, if I do so, I get this error message
Use M-x make-directory RET RET to create the directory and its parents
and it goes away after a couple seconds. Then it takes me to another screen that explains the error in the latex code. However, now I cannot simply do C-x 1 to get back to the latex code. I have to C-x C-c and restart emacs.
This is my .emacs file
(setq backup-by-copying t
backup-directory-alist '(("." . "~/.emacsBkups"))
delete-old-versions t
kept-new-versions 5
kept-old-versions 2
version-control t)
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq TeX-PDF-mode t)
;;(require 'ess-site)
;;(ess-toggle-underscore nil)
(require 'whitespace)
(setq whitespace-style '(lines-tail face))
(add-hook 'c-mode-hook 'whitespace-mode)
(add-hook 'c++-mode-hook 'whitespace-mode)
(add-hook 'python-mode-hook 'whitespace-mode)
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
(c-set-offset (quote cpp-macro) 0 nil)
(setq TeX-view-program-list '(("Evince" "evince --page-index=%(outpage) %o")))
(setq TeX-view-program-selection '((output-pdf "Evince")))
Sometimes AUCTeX gets confused parsing the log of (La)TeX compilation and isn't able to guess the correct line raising the error. In some cases AUCTeX issues an obscure message "Error occured after last TeX file closed", when there are unbalanced parentheses, in your case it suggests you to create a new directory. To help AUCTeX finding the correct line raising the error you can add the -file-line-error option to latex or pdflatex by customizing the variable LaTeX-command-style. To do this add the following code to your .emacs:
(setq LaTeX-command-style '(("" "%(PDF)%(latex) -file-line-error %S%(PDFout)")))
See also the AUCTeX FAQ:
8. Why does TeX-next-error (C-c `) fail?
When writing the log file, TeX puts information related to a file,
including error messages, between a pair of parentheses. AUCTeX
determines the file where the error happened by parsing the log file
and counting the parentheses. This can fail when there are other,
unbalanced parentheses present.
As a workaround you can activate so-called file:line:error messages
for the log file. (Those are are easier to parse, but may lack some
details.) Either you do this in the configuration of your TeX system
(consult its manual to see where this is) or you add a command line
switch to the (la)tex call, e.g. by customizing LaTeX-command-style or
TeX-command-list.

Space character inside an argument (emacs lisp)

In windows, I set the variable inferior-lisp-program to be (shell-quote-argument "D:/Program Files/ccl/wx86cl.exe").
But when I run inferior lisp with the command run-lisp, emacs responds:
Searching for program: no such file or directory, "D:/Program
It seemed that emacs treats "D:/Program Files/ccl/wx86cl.exe" as two arguments "D:/Program and Files/ccl/wx86cl.exe" separated by a space character.
How can I make emacs treat "D:/Program Files/ccl/wx86cl.exe" as a whole?
Try using the old "Progra~1" compatibility name for "Program Files". So,
(setq inferior-lisp-program "D:/Progra~1/ccl/wx86cl.exe")

How to fix aHg output encoding?

Here is what I use:
- MacOS X 10.6.7
- GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
- Mercurial Distributed SCM (version 1.7.2+20101201)
- GNU Emacs 24.0.50 (build from git repo with --cocoa flag)
- aHg v0.99
Here is my emacs settings:
(set-default-coding-systems 'utf-8)
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-language-environment 'UTF-8)
And here if what i got after C-c h g s:
parent: 2512:6252abcd7368 tip
JavaScript: ???????? ???????????? ????? ? ???????.
branch: default
commit: 3 modified, 6 unknown
update: (current)
Running hg log under M-x term gives me a correct result I can read (? is a russian chars...). So... How can I fix this in Emacs in aHg output?
First thing, that should be checked here - which LANG is set when Emacs was started)? (what is returned when you execute M-: (getenv "LANG")? As I remember, Mac OS X set LANG to "C" on the start of launchpad... setting of language environment don't modify LANG...
You can explicitly set the LANG environment from Emacs using (setenv "LANG" "ru_RU.UTF-8") or use "en_EN.UTF-8" if it preferable.
P.S. I just checked ahg with different LANG settings, and see question marks when I set LANG to "C", and see Russian letters when I run ahg-log in repository
It could be that the default font that is being used for output when you do C-c h g s doesn't support Cyrillic characters. You can see what font is being used by placing the point on one of the Russian characters that isn't being displayed properly and pressing C-u C-x =. To ensure that Russian is always displayed properly in Emacs, you can specify that all Russian characters will be displayed in a particular font. Since the Cyrillic characters are in the Unicode range U+0400 – U+04FF and the Arial font seems to display these characters ok, you could try the following in your Emacs init file:
(set-fontset-font "fontset-default"
'(#x400 . #x4ff)
"Arial")