6

I'm running a process that, on failing error, outputs the character '✖'(as defined in Unicode). However, I don't see the error at all if running the process in an Emacs shell buffer (Aquamacs distro of GNU Emacs).

Using: GNU Emacs 23.3.1 (i386-apple-darwin9.8.0, NS apple-appkit-949.54) of 2011-03-18 on braeburn.aquamacs.org - Aquamacs Distribution 2.2

How to get the Emacs shell buffer to support such unicode characters?

christopherbalz
  • 722
  • 1
  • 8
  • 22

3 Answers3

7

To tell an individual shell buffer to treat the output from the shell as UTF-8, issue the command C-x RET p, and type "utf-8" when asked "Coding system for output from the process: ". When then asked "Coding-system for input to the process: ", I just type RET; I never provide UTF-8 input directly to the shell.

Alternately, to get this behavior automatically, put (prefer-coding-system 'utf8) in your .emacs file. Actually, that will cause UTF-8 to be used in some other contexts as well, which is what most people would probably want.

Sean
  • 29,130
  • 4
  • 80
  • 105
  • hmm, what if I want to apply specific coding to the shell? is (prefer-coding-system 'utf8 ) still appropriate? or better narrow it down ? – zinking Nov 06 '13 at 14:57
4

You could call a function like the following one to create a shell that supports utf-8:

(defun utf8-shell ()
  "Create Shell that supports UTF-8."
  (interactive)
  (set-default-coding-systems 'utf-8)
  (shell))

This sets both input and output to UTF-8 so you can do (for example) the following:

~ $ echo "✖"
✖

If you want to make shell always open with utf-8 support, you can do the following instead:

(defadvice shell (before advice-utf-shell activate)
  (set-default-coding-systems 'utf-8))

(ad-activate 'shell)
zev
  • 3,480
  • 18
  • 13
  • Thanks everyone. The only change that fixed my issue was the utf8-shell 'defun'. I'd like that function to be named just plain old 'shell', but this results in an error when I try to run it. For now I settled on 'u-shell'. – christopherbalz Jul 15 '11 at 01:08
  • If you're not opposed to having this behaviour every time you call the shell function, you can advise the shell function. I've modified my answer to include defadvice example code that does this. – zev Jul 15 '11 at 16:44
0

Have a look to this EmacsForMacOS wiki page.

xevincent
  • 3,674
  • 18
  • 20
  • Thanks - I put those in too. They didn't seem to alter much for me, but I will, for now, take the wiki's word for it. They join the file utf-8 statement I've had for a while now: (set-buffer-file-coding-system 'utf-8-unix t) – christopherbalz Jul 15 '11 at 01:13