1

I'm working on fulfilling a feature request for my package ten-hundred-mode - specifically, that it provide a "permissive" option where it merely highlights impermissible words, rather than immediately removing them in the fashion of Cleartext. I thought Flycheck would be a good method of doing this highlighting, and indeed it didn't take much effort to write a checker. But then I ran into some trouble.

Specifically, it is not clear to me that a method exists of enabling this checker while not affecting whatever other checkers the user currently has active. That's important because I want to fulfill the same use case as flyspell-prog-mode, and provide a minor mode which can identify and operate on only comments, strings, and docstrings in source code. To do that with a Flycheck checker, I need to be able to activate it without in any way modifying whatever collection of checkers, or none, the user has configured for herself.

I can see several ways of activating my checker when someone activates my minor mode. I haven't been able to find one which I'm certain will do so without potentially breaking the user's configuration. No doubt many people here know more than I do about Flycheck's internals. (That's not a high bar to clear.) If a way exists, perhaps such a person will point me in its direction.

1

Add your syntax checker to the end of flycheck-checkers to make it available for Flycheck's automatic syntax checker discovery and selection. Flycheck will then automatically pick your checker if its executable is present and if the major mode matches.

For more fine-grained control add a custom :predicate function to your syntax checker, for instance:

(flycheck-define-checker …
   :predicate (lambda () (bound-and-true-p ten-hundred-mode)))

Flycheck looks at this predicate before trying to use a checker. This predicate tells Flycheck that it may only use the syntax checker if ten-hundred-mode is loaded and enabled. If the user disables the syntax checker Flycheck will silently skip it.

If you use a custom predicate function please also add a custom :verify function to tell the user why the syntax checker is disabled when they use M-x flycheck-verify-setup.

Take a look at Flycheck's source for examples, for instance in the go vet syntax checker.

  • That'll work nicely for major modes, but ten-hundred-mode is currently a minor mode and will continue to offer one, even if I do end up promoting it to a major mode (which I have other reasons for thinking about doing). The minor mode case is really the one I'm more concerned about here. – Aaron Miller Apr 14 '16 at 16:36
  • @AaronMiller Ah, so your problem is rather what :modes to use, because your minor mode is supposed to support arbitrary major modes? – lunaryorn Apr 18 '16 at 11:18
  • Exactly. On the other hand, given your comment on my other question, it looks like I'll be finding a non-Flycheck-based solution in any case, so... – Aaron Miller Apr 19 '16 at 13:29
  • @AaronMiller Well, we don't support inherited modes for syntax checkers currently, but that'd be relatively easy to add. It's just that none needed that hitherto so it's not there yet. – lunaryorn Apr 19 '16 at 13:31
  • 1
    No worries on that score - the Flycheck source has disabused me of any inclination to imagine it's a simple task. On the other hand, all I actually need to do is highlight words which aren't (or whose stems aren't) on a defined list already bound to an Emacs Lisp symbol, so I'd be making use of only a little of Flycheck's power in any case. – Aaron Miller Apr 19 '16 at 16:15

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.