Skip to content

compilation: interpret ANSI color code. #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ Use idomenu (imenu with `ido-mode') for best mileage.")

(add-hook 'before-save-hook 'rust-before-save-hook nil t)
(add-hook 'after-save-hook 'rust-after-save-hook nil t)
;; NOTE: this one is not local
(add-hook 'compilation-finish-functions 'rust-restore-compilation-mode)

(setq-local rust-buffer-project nil)

Expand Down Expand Up @@ -1901,29 +1903,33 @@ Return the created process."
(interactive)
(setq-local rust-format-on-save nil))

(defun rust--compile (format-string &rest args)
(defun rust--compile (action)
(when (null rust-buffer-project)
(rust-update-buffer-project))
(let ((default-directory
(or (and rust-buffer-project
(file-name-directory rust-buffer-project))
default-directory)))
(compile (apply #'format format-string args))))
(rust-compilation-setup
(compile (format "%s %s --color always"
rust-cargo-bin
action)
t))))

(defun rust-compile ()
"Compile using `cargo build`"
(interactive)
(rust--compile "%s build" rust-cargo-bin))
(rust--compile "build"))

(defun rust-run ()
"Run using `cargo run`"
(interactive)
(rust--compile "%s run" rust-cargo-bin))
(rust--compile "run"))

(defun rust-test ()
"Test using `cargo test`"
(interactive)
(rust--compile "%s test" rust-cargo-bin))
(rust--compile "test"))

;;; Hooks

Expand Down Expand Up @@ -2016,6 +2022,25 @@ the compilation window until the top of the error is visible."
(add-to-list 'compilation-error-regexp-alist 'cargo)
(add-hook 'next-error-hook 'rustc-scroll-down-after-next-error)))

;;; color support for compilation-mode
(defun rust-restore-compilation-mode (buffer _status)
"Restore `compilation-mode' after process termination.

This function is designed for use in `compilation-finish-functions'.
Keep in sync with `rust-compilation-setup'."
(with-current-buffer buffer
(when (eq 'rust-mode (get-text-property (point-min) :mode))
(compilation-mode))))

(defun rust-compilation-setup (buf)
(with-current-buffer buf
(put-text-property (point-min)
(point-max)
:mode
'rust-mode
buf))
buf)

;;; Secondary Commands

(defun rust-playpen-region (begin end)
Expand Down