0

I'd like the :command of a flycheck checker to depend on the file extension of the input.

For example:

  • for .tex files run the command foo --format latex file.tex
  • for any other file extension run the command foo --format text file.txt

I've tried:

:command ("foo" "--format" `(if (string= "tex" (file-name-extension source-inplace)) "latex" "text") source-inplace)

Which returns:

flycheck-define-command-checker: Invalid command argument (\‘ (if (string= "tex" (file-name-extension source-inplace)) "latex" "text")) in syntax checker textlint

Which is thrown from flycheck when executing flycheck-command-argument-p.

Is it possible to achieve what I'm attempting? i.e the command string passed to :command being determined by the file extension of the file being checked by flycheck?

For context, the solution was required for implementing a textlint flycheck checker: https://www.macs.hw.ac.uk/~rs46/posts/2018-12-29-textlint-flycheck.html

1 Answer 1

0

The solution is to use eval (credit: flycheck gitter):

:command ("foo" "--format"
    (eval (if (string= "tex" (file-name-extension buffer-file-name))
                "latex"
               "text"))
    source-inplace)

Your Answer

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

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