Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get support for '✖' and the like in the Emacs shell buffer?

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?

like image 353
christopherbalz Avatar asked Jul 12 '11 17:07

christopherbalz


People also ask

How do I access Emacs shell?

You can start an interactive shell in Emacs by typing M-x shell . By default, this will start the standard Windows shell cmd.exe . Emacs uses the SHELL environment variable to determine which program to use as the shell.

How do I run a shell command in Emacs?

You can execute an external shell command from within Emacs using ` M-! ' ( 'shell-command' ). The output from the shell command is displayed in the minibuffer or in a separate buffer, depending on the output size.

What is Eshell Linux?

Eshell is a shell-like command interpreter implemented in Emacs Lisp. It invokes no external processes except for those requested by the user.

What is Eshell in Emacs?

Eshell is a shell written entirely in Emacs-Lisp, and it replicates most of the features and commands from GNU CoreUtils and the Bourne-like shells. So by re-writing common commands like ls and cp in Emacs-Lisp, Eshell will function identically on any environment Emacs itself runs on.


2 Answers

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.

like image 189
Sean Avatar answered Oct 14 '22 07:10

Sean


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)
like image 22
zev Avatar answered Oct 14 '22 06:10

zev