DEV Community

Tomohiko Himura
Tomohiko Himura

Posted on • Edited on

2 2

Remove ANSI color on Emacs

When the command is executed on Emacs, escape sequences for coloring may be added.
I wont to erase this.

コマンドの実行結果をEmacsのバッファーに出力すると、色をつけるためのエスケープシーケンスが付与されてしまうことがある。
邪魔なので、削除したい。

if you can rewrite the buffer, you can use ansi-color-filter-region in ansi-color.el.
A simple example follows.

バッファーの内容を書き換えてしまいたいのであれば、ansi-color.elのansi-color-filter-regionが使える。雑にバッファー全体に適用する関数はこんな感じ。

(defun remove-ansi-color ()
  (interactive)
  (save-excursion
   (mark-whole-buffer)
   (ansi-color-filter-region (region-beginning) (region-end))))

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay