2

In compilation-mode (or some similar mode), how can I make the default py.test output be colourized?

I'm not talking about clickable links, but about just 'syntax' colouring the various parts of the output. Scare quotes because there are multiple syntaxes going on in the same buffer (python code snippets, various kinds of stack info, and other py.test output like the 'FAILURES' line), and because py.test's output perhaps isn't that standardized.

I'd be happy with just some of this structure highlighted, but the more the merrier.

1

I believe this accomplished by modifying compilation-mode-font-lock-keywords and compilation-error-regexp-alist(-alist)?. If py-test is running in a raw compilation-mode than the appropriate alists need to be added to the global font-lock-keywords & error-regexp-alists for compilation-mode.

However I believe when defining a compilation derived mode with define-compilation-mode, it automatically references a variable for deriving mode specific error and font-lock information. IE

(define-compilation-mode pytest-compilation-mode "Pytest Compilation" "docs.")

Automatically generates a references to variables like:

  • pytest-compilation-error-regexp-alist
  • pytest-compilation-error-regexp-alist-alist
  • pytest-compilation-mode-font-lock-keywords

I believe for this example it would be a pytest-compilation-mode-font-lock-keywords which would cover metadata about the buffer like number of errors, if it finished, the same as compilation-mode-font-lock-keywords does in the compile library. Similarly compilation-error-regexp-alist defines what errors look like (as well as hyperlink formatting, etc). Finally compilation-error-regexp-alist-alist defines how to map to lines referenced within a given error. I recommend reading through the documentation for compile using M-x locate-library compile for more details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.