From d37d8f969b6609d2d9d7231282abba97ddfab531 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 19 Sep 2019 17:33:38 -0700 Subject: Replace ‘ansi-color’ with ‘xterm-color’ According to a tweet from Mickey Petersen[1], ‘xterm-color’ is faster and more accurate. [1]: https://twitter.com/mickeynp/status/1132236557308579840?s=09 --- oni-compilation.el | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'oni-compilation.el') diff --git a/oni-compilation.el b/oni-compilation.el index d11f395..c5c7444 100644 --- a/oni-compilation.el +++ b/oni-compilation.el @@ -4,8 +4,8 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2019.0908.172111 -;; Package-Requires: (oni-alert) +;; Version: 2019.0919.171849 +;; Package-Requires: (oni-alert xterm-color) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ (require 'compile) (require 'subr-x) +(require 'xterm-color) (setq compilation-scroll-output t) @@ -45,10 +46,6 @@ ALIST and PLIST contain extra information about the buffer." (unless (string= (string-trim status) "finished") (display-buffer buffer))) -(defun oni-compilation--ansi-color-for-compilation-filter () - "Apply ANSI terminal escape codes to compilation output." - (ansi-color-apply-on-region compilation-filter-start (point))) - (defun oni-compilation--compilation-finish-notify-function (buffer status) "Show an alert of the status of the compliation. @@ -59,21 +56,26 @@ status of the process." (alert "Compilation finished succesfully") (alert "Compilation finished with an error")))) +(defun oni-compilation--filter-xterm-colors (func proc string) + "Call FUNC with PROC and STRING filtered through ‘xterm-color-filter’." + (funcall func proc (xterm-color-filter string))) + +(setq compilation-environment '("TERM=xterm-256color")) + (add-to-list 'display-buffer-alist '("\\`\\*compilation\\*\\'" display-buffer-in-side-window (side . bottom) (slot . 0) (window-height . 0.33))) -(add-hook 'compilation-filter-hook - #'oni-compilation--ansi-color-for-compilation-filter) - (add-hook 'compilation-finish-functions #'oni-compilation--maybe-display-compilation-window) (add-hook 'compilation-finish-functions #'oni-compilation--compilation-finish-notify-function) +(advice-add 'compilation-filter :around #'oni-compilation--filter-xterm-colors) + ;;;###autoload(with-eval-after-load 'compile (require 'oni-compilation)) (provide 'oni-compilation) -- cgit v1.2.3-54-g00ecf