emacs shell命令输出不显示ANSI颜色但代码 [英] emacs shell command output not showing ANSI colors but the code

查看:150
本文介绍了emacs shell命令输出不显示ANSI颜色但代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

有没有办法使用颜色和UTF8?



同样的问题一直是在之前的答复中,但是结果不完全令人满意(解决方案是打开shell模式) 。我知道如何在一个shell中有颜色。我只想知道我可以用M做什么颜色! (shell命令)或者根本不可能。



当您只想快速显示某些东西并且不想移动到此缓冲区时,shell模式太侵扰,并且您希望自动消失,而不需要使用Cxk 。显然有些情况下shell缓冲区更方便,但另一个问题是我发现如何将颜色放在shell模式。



[note]使用emacs
GNU Emacs 21.4.1(x86_64-redhat-linux-gnu,X工具包,Xaw3d滚动条)2008-06-15 on builder6.centos.org

解决方案

ansi-color.el 包含处理ANSI颜色代码的功能。不幸的是,没有一个很好的方法将它挂钩到 shell-command 中。这是一个黑客,但它的作品:

 (需要'ansi-color)

(defadvice display-message-or-buffer(before ansi-color activate)
在shell输出中处理ANSI颜色代码
(let((buf(ad-get-arg 0)))
(和(bufferp buf)
(string =(buffer-name buf)* Shell命令输出*)
(with-current-buffer buf
(ansi-color-适用区域(point-min)(point-max))))))


When I do M-! in my emacs 21.4 the ANSI codes gets literal. Eg: ls --color

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

Is there a way of having it with color and UTF8?

The same question has been answered in SO before but with not totally satisfactory results (the solution given was to open a shell-mode). I know how to have colors in a shell. I only want to know how I can have color with M! (shell-command) or if it is not possible at all.

A shell mode is too intrusive when you want only to show something quick and don't want to move to this buffer and you would like to have it disappear automatically without C-x-k. Obviously there are situations where a shell buffer is more convenient but thanks to the other question I found how to put color to the shell-mode.

[note] emacs in use GNU Emacs 21.4.1 (x86_64-redhat-linux-gnu, X toolkit, Xaw3d scroll bars) of 2008-06-15 on builder6.centos.org

解决方案

ansi-color.el contains the functions to process ANSI color codes. Unfortunately, there's not really a good way to hook it into shell-command. This is something of a hack, but it works:

(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))))))

这篇关于emacs shell命令输出不显示ANSI颜色但代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆