0

How do you get compilation mode to properly detect and underline the file:line pattern of a given tool, to be able to click to directly get to them?

1 Answer 1

2

After trying various examples around the web that simply didn't work (with my emacs 29.1), here's what ended up working. To add a tool (ansible-lint), I added this to my .emacs:

;;; ansible-lint
; Compile regex for ansible-lint
(require 'compile)
(add-to-list 'compilation-error-regexp-alist
             'yaml)
(add-to-list 'compilation-error-regexp-alist-alist
             '(yaml "^\\(.*?\\):\\([0-9]+\\)" 1 2)
             )

where "^\\(.*?\\):\\([0-9]+\\)" is my custom regex (for more details on the format, see here).

To complete the description, I also added this to call ansible-lint when running compile from yaml-mode:

; Replace make -k with ansible-lint, with an UTF-8 locale to avoid crashes
(defun ansible-lint-errors ()
  (make-local-variable 'compile-command)
  (let ((ansiblelint_command "ansible-lint ") (loc "LANG=C.UTF-8 "))
    (setq compile-command (concat loc ansiblelint_command buffer-file-name)))
)
(add-hook 'yaml-mode-hook 'ansible-lint-errors)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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