3

I created a derived mode (using define-derived-mode) based on c++-mode to include new keywords, etc.

The mode is working great, but I'm having problems with other minor modes that stop working with my derived mode.

For example, flycheck and company-mode, the first stops telling me when there is broken code in the buffer, and the second will not complete (it will always say No completion found).

If I load the c++-mode in the buffer, all these minor modes start working again.

So, my question is how can I make these modes see my derived mode as if it was c++-mode.

Thanks!

6
  • As far as Flycheck is concerned, it has the major mode names hardcoded currently: github.com/flycheck/flycheck/blob/… You could open an issue for that.
    – Dmitry
    Commented Jan 1, 2016 at 23:28
  • @Dmitry Flycheck provides flycheck-add-mode to register syntax checkers for new major modes.
    – user227
    Commented Jan 2, 2016 at 12:09
  • @lunaryorn Good, but I don't think that's sufficient, see the lines highlighted in my URL.
    – Dmitry
    Commented Jan 2, 2016 at 12:50
  • @Dmitry Ah, yes, I forgot that, sorry.
    – user227
    Commented Jan 2, 2016 at 13:04
  • It's not a good situation that a user need to configure package after package to work with a derived mode. Instead, packages should treat derived modes exactly like the base mode. Technically, this mean that they should use mode-derived-p rather than (eq major-mode ...) whenever possible. Commented Jan 2, 2016 at 14:42

2 Answers 2

2

company-mode is just a framework. If you want completions from company-clang, try adding your major mode to company-clang-modes.

But if you only created a new major mode for minor reasons like new font-lock keywords, maybe you would be better served by moving that logic to a new minor mode instead (and adding it to c++-mode-hook).

1
  • Actually, company-clang suffers from the same problem as Flycheck (the set of major modes is more or less set in stone, for the purposes of determining the -x argument). So you might want to report that as well, and post the link to your major mode in the issue description.
    – Dmitry
    Commented Jan 2, 2016 at 17:02
1

Flycheck provides flycheck-add-mode to register syntax checkers for new major modes, e.g.

(dolist (checker '(c/c++-clang c/c++-gcc c/c++-cppcheck))
  (flycheck-add-mode checker 'my-derived-mode))

This will add your my-derived-mode to all C/C++ syntax checkers in Flycheck. After evaluating this expression, Flycheck will check buffers in your derived mode just like buffers in the default C and C++ modes.

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.