emacs shell command output not showing ANSI colors but the code

淺唱寂寞╮ 提交于 2019-12-04 06:12:28

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

About UTF-8:

To specify a coding system for converting non-ASCII characters in the shell command output, use C-x RET c before this command.

Noninteractive callers can specify coding systems by binding coding-system-for-read' and coding-system-for-write'.

This is from the documentation of shell-command.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!