如何在emacs中显示任何模式的ANSI颜色代码? [英] How do I display ANSI color codes in emacs for any mode?

查看:152
本文介绍了如何在emacs中显示任何模式的ANSI颜色代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日志文件,使用ANSI转义色码来格式化文本。模式是基本的。还有其他回答的问题解决这个问题,但我不知道如何将它应用于此模式或任何其他模式。我知道解决方案与某些方式配置 ansi-color 有关。




解决方案

您可以使用

下的代码

 (require'ansi-color)
defun display-ansi-colors()
(interactive)
(ansi-color-apply-on-region(point-min)(point-max)))

然后,您可以通过Mx通过键绑定执行 display-ansi-colors 或者通过某些编程条件(也许您的日志文件有一个扩展名或匹配某些正则表达式的名称)



如果你想做这可以使用只读缓冲区(日志文件,grep结果),您可以使用 prohib-read-only ,因此该功能将是:

 (defun display-ansi-colors()
(interactive)
(let((prohib-read-only t))
(ansi-color-apply-on-region(point-min)(point-max))))


I have a log file that uses ANSI escape color codes to format the text. The mode is fundamental. There are other answered questions that address this issue but I'm not sure how to apply it to this mode or any other mode. I know the solution has something to do with configuring ansi-color in some way.

解决方案

You could use code below

(require 'ansi-color)
(defun display-ansi-colors ()
  (interactive)
  (ansi-color-apply-on-region (point-min) (point-max)))

Then you can execute display-ansi-colors via M-x, via a key-binding of your choosing, or via some programmatic condition (maybe your log files have a extension or name that matches some regexp)

If you want to do this with read-only buffers (log files, grep results), you may use inhibit-read-only, so the function will be:

(defun display-ansi-colors ()
  (interactive)
  (let ((inhibit-read-only t))
    (ansi-color-apply-on-region (point-min) (point-max))))

这篇关于如何在emacs中显示任何模式的ANSI颜色代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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