I have a shell command I'm running from Emacs that has a Δ character in its output. How can I configure the *Shell Command Output* buffer to display UTF-8 by default?

edit: There could also be something else weird going on. It displays Î8 μs Î8 μs when it should be Δ15 μs

  • Running the command with C-x Return c utf-8 works, so it should be possible to write a wrapper. – choroba Jul 2 at 17:14
  • I'm running it via "Shell command on region" with M+| – Aido Jul 2 at 17:20
  • Yes, prefixing it with the encoding specifier works for me. – choroba Jul 2 at 17:30
  • Oh, do you just say utf-8 <cmd>? – Aido Jul 2 at 17:32
  • You say C-x RET c utf-8 <cmd>. – NickD Jul 3 at 18:24

You can use the per-command setting of the encoding that @choroba mentions in his comment (C-x RET c utf-8) which will only affect the next command, but you can also set UTF-8 to be the default encoding everywhere. Add

(set-language-environment "UTF-8")

to your init file and restart emacs. Or for the current session, click on "Options/Multilingual Environment/Set Language Environment" and select "UTF-8".

Unless you have very specific needs (CJK characters with special encodings, Microsoft Code Page stuff etc), I believe that UTF-8 is safe: I have never regretted setting it globally, but I cannot guarantee that you will not run into problems. IME, the problems tend to be few and far-between and have to do with the special encodings I mentioned (and in those cases, you can use the one-off setting of the encoding to deal with the problem).

But you might want to wait for other opinions before switching over wholesale, and in the meantime deal with the problem one case at a time, using the C-x RET c utf-8 method for each command.

| improve this answer | |
  • I'm worried that this will change how files are saved and mess up other programs. Am I just being paranoid? – Aido Jul 2 at 18:33
  • Please incorporate "the encoding that @choroba mentions in his comment" into your answer, instead of just referring to it. Comments can be deleted at any time. – Drew Jul 2 at 19:10

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.