7

当我做 M-!在我的 emacs 21.4 中,ANSI 代码是文字的。例如:ls --color

^[[0m^[[0m05420273.pdf^[[0m
^[[0m100829_Baño1.pdf^[[0m 

有没有办法让它带有颜色和 UTF8?

之前在 SO中已经回答了同样的问题,但结果并不完全令人满意(给出的解决方案是打开 shell 模式)。我知道如何在外壳中添加颜色。我只想知道我怎么能有M的颜色!(shell-command) 或者根本不可能。

当您只想快速显示某些内容并且不想移动到此缓冲区并且您希望它在没有 Cxk 的情况下自动消失时,shell 模式过于侵入。显然,在某些情况下,shell 缓冲区更方便,但由于另一个问题,我发现了如何将颜色放入 shell 模式。

[注意] 2008 年 6 月 15 日在 builder6.centos.org 上使用的 emacs GNU Emacs 21.4.1 (x86_64-redhat-linux-gnu, X toolkit, Xaw3d 滚动条)

4

2 回答 2

20

ansi-color.el包含处理 ANSI 颜色代码的函数。不幸的是,没有真正的好方法可以将它挂接到shell-command. 这有点像黑客,但它有效:

(require 'ansi-color)

(defadvice display-message-or-buffer (before ansi-color activate)
  "Process ANSI color codes in shell output."
  (let ((buf (ad-get-arg 0)))
    (and (bufferp buf)
         (string= (buffer-name buf) "*Shell Command Output*")
         (with-current-buffer buf
           (ansi-color-apply-on-region (point-min) (point-max))))))
于 2011-04-28T16:09:07.400 回答
1

关于 UTF-8:

要在 shell 命令输出中指定用于转换非 ASCII 字符的编码系统,请在此命令之前使用 Cx RET c。

非交互式调用者可以通过绑定 coding-system-for-read' and coding-system-for-write' 来指定编码系统。

这是来自 的文档shell-command

于 2011-04-28T19:55:41.520 回答