Windows 10 with GNU Emacs 26.1 (build 1, x86_64-w64-mingw32).
To set the encoding of process buffers to UTF-8.
I would like to set the input and output encoding of process buffers, like shell or the R Console (iESS), to UTF-8. By default, the iESS buffer is encoded as
iso-latin-1-dos for output and
undecided-dos for input.
If I ask Emacs:
M-S-: (process-coding-system (get-buffer-process (current-buffer)))
(iso-latin-1-dos . undecided-dos)
As a result, special characters are mangled in the iESS output (although not in the input):
> print("Ä")  "Ã\204" >
What I've tried
I can change the encoding by invoking
M-S-: (set-buffer-process-coding-system 'utf-8 'utf-8)
as described in this thread. The problem goes away, but I would like a permanent solution. So I tried to create hooks for several process buffers in my
.emacs, like so:
; the hooks below should set the encoding of input to and output from a ; process buffer (like a shell, R console, or REPL) to UTF-8 ; but somehow they don't. (add-hook 'shell-mode-hook (lambda () (set-buffer-process-coding-system 'utf-8 'utf-8))) (add-hook 'eshell-mode-hook (lambda () (set-buffer-process-coding-system 'utf-8 'utf-8))) (add-hook 'iESS-mode-hook (lambda () (set-buffer-process-coding-system 'utf-8 'utf-8))) (add-hook 'inferior-python-mode-hook (lambda () (set-buffer-process-coding-system 'utf-8 'utf-8)))
Upon restarting Emacs, however, these settings have no effect. There is no error message, but the iESS and shell buffers still have the "wrong" encoding.
Ho can I fix the code above so it changes the encoding of the respective process buffer upon mode change? What would be a smarter way to achieve this? Is there a way to set all process buffers to utf-8 encoding without relying on individual hooks?