1

I am having encoding issues with EMACS (ESS). Part of the problem is that many of my file paths contain a special character (ý). These characters keep getting converted to "ý" when I close and reopen the buffer.

C-h v buffer-file-coding-system RET used to give:

Its value is ‘iso-latin-1-unix’
Local in buffer file.r; global value is iso-latin-1-dos

I added (setq-default buffer-file-coding-system 'utf-8-unix) to my init.el file, and now C-h v buffer-file-coding-system RET gives:

Its value is ‘iso-latin-1-unix’
Local in buffer file.r; global value is utf-8-unix

If I correct the letters and use C-x RET r utf-8-unix RET they get re-written as \375.

I added the following lines to my init.el (setq-default buffer-file-coding-system 'utf-8-unix) (setq-default coding-system-for-read 'utf-8-unix) (prefer-coding-system 'utf-8-unix) And now C-h v buffer-file-coding-system RET gives:

Its value is ‘utf-8-unix’
Local in buffer file.r; global value is the same.

but R in EMACS ESS no longer works. Shift-enter to start the minor process and execute a line of R code causes EMACS to freeze and all I get is a spinning wheel until I force quit.

So I removed those lines from my init.el to restore R. When I start R there is a error message "Error: invalid multibyte character in parser at line 1" which has to do with setwd() as the file path has the character ý in it.

If I put file.r into a directory that does not have ý in the path, everything works correctly.

1
  • Don't put the answer in the question. Post it separately as an answer. You can accept your own answer.
    – Drew
    Dec 15, 2022 at 16:31

1 Answer 1

1

I solved it by adding these three lines to my init file:

(setq-default buffer-file-coding-system 'utf-8) <br/> 
(setq-default coding-system-for-read 'utf-8) <br/> 
(prefer-coding-system 'utf-8)
2
  • Jacob, this saves me a lot, thank you for posting it. Where did you find that these three were needed? (I'm looking for a canonical link in case I also run into other utf-based issues in emacs.) Thanks!
    – r2evans
    Feb 20 at 15:21
  • 1
    No specific place, just some various bits on this site and trial and error
    – Jacob
    Feb 21 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.