3

我知道以前有人问过这个问题的变体......但我一定遇到了不同的问题,因为解决方案对我不起作用。我有一个使用 ANSI 代码的文本文件,当我cat将文件发送到终端时,它可以很好地显示。但是,当我对文件进行 emacs 23.2.1 时,我看到如下内容:

^[[36mText^[[0m

如果重要的话,^[那一行中的两个都是红色的(emacs 将其视为一个字符),而该文本的其余部分是黑色的。我希望该行在 emacs 编辑器中为浅蓝色。提到我正在使用 python 代码制作这个文件可能会有所帮助

python
>>> myfile = open("test.txt","w")
>>> myfile.write("\033[36mText\033[0m\n")
>>> myfile.close()

生成该文本。环顾四周,我尝试了几种解决方案:

(require 'ansi-color)                                                                                                                                                                                              
;(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)                                                                                                                                                      

(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)                                                                                                                                                         

;(setq ansi-term-color-vector [unspecified "#3f3f3f" "#cc9393" "#7f9f7f" "#f0dfaf"  "#8cd0d3" "#dc8cc3" "#93e0e3" "#dcdccc"]) 

;(defun colorize-compilation-buffer ()                                                                                                                                                                             
;  (toggle-read-only)                                                                                                                                                                                              
;  (ansi-color-apply-on-region (point-min) (point-max))                                                                                                                                                            
;  (toggle-read-only))                                                                                                                                                                                             
;(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)                                                                                                                                                  

;(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/lisp 专家......所以我在这里很无助。我还尝试清除.emacs文件中的所有其他内容,以防万一发生冲突。

关于我可以尝试什么的任何其他想法?

4

0 回答 0