开发者

Unicode characters in emacs term-mode

开发者 https://www.devze.com 2023-03-23 07:02 出处:网络
I use ansi-term for my normal terminal sessions.I tend to use unicode characters in my prompt to do things like set the trailing character based on the type of开发者_JAVA技巧 source control I\'m using

I use ansi-term for my normal terminal sessions. I tend to use unicode characters in my prompt to do things like set the trailing character based on the type of开发者_JAVA技巧 source control I'm using.

I use the character "±" as my prompt for git repositories.

In Emacs' ansi-term, my prompt isn't rendered as unicode, and shows as "\302\261". Displaying the current coding system shows that it defaults to utf-8-unix for input to the process, but I get raw binary as the decoding output. I can hit C-c RET p to change the encoding and decoding coding systems. I'm drawing a blank as to how to set this automatically when I start a terminal? I've tried adding to term-mode-hook to set the buffer's coding system to no avail. I think I've found what I'm looking for in term.el, but I don't care to tweak the distribution elisp, and it appears the raw binary was added to fix a bug somewhere else.

EDIT: This was unclear originally. I'm having issues setting the default process coding system for ansi-term running under Cocoa-ized Emacs 23.3 on MacOS. Emacs itself isn't running in a terminal, my terminal is running in Emacs.


The following worked for me:

(add-hook 'term-exec-hook
          (function
           (lambda ()
             (set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))))

ansi-term seems to ignore the default-process-coding-system variable, so I had to set it buffer-locally after it executes my shell.


After getting a better understanding of term.el, the following works:

(defadvice ansi-term (after advise-ansi-term-coding-system)
    (set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))
(ad-activate 'ansi-term)

Trying this with term-mode-hook is broken because in term.el, term-mode-hook is called before switching to the terminal buffer, so set-buffer-process-coding-system breaks due to the lack of a process associated with the buffer.


Try

(set-terminal-coding-system 'utf-8-unix)

That's C-x RET t not C-x RET p.


So C-x RET p helps? Unless C-h v default-process-coding-system is (utf-8-unix . utf-8-unix) try

(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
0

精彩评论

暂无评论...
验证码 换一张
取 消