Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

syntax highlight error when language-c treat a C++ .h file as a C .h file #125

Closed
skywind3000 opened this issue Mar 17, 2016 · 2 comments
Closed

Comments

@skywind3000
Copy link

most header file of C++ has the '.h' suffix, which is treated as a C header file. As a consequence of this, many C++ keywords (class, public, private, template) in the .h file get a wrong highlight.

In a ordinary .cpp file, everything in color is alright:
48f9d1bb-57d3-4d60-a602-bbc2c8d315be

After putting same piece of code to the .h file, color got issues:
97dad0f3-50c3-48a4-a5a0-e0125578e204

Using ctrl-shift-L to change grammar, I found .h file has been recognized as a C file by default. After changing the grammar to C++, it still has a problem around 'class':
606650e7-c7d0-4d30-98bb-3e1f796bb7c5

Every C++ keywords in .h files is supposed to be recognized,
it seems there are two issues here:

  1. The .h file hasn't been treated as a cpp header file by default.
  2. Keywords in .h files can not be recognized after changing the file grammar to C++.

It's very werid syntax highlight: keyword 'class' hasn't be recognized:
f2e2b923-4b60-4cf6-8fa8-63943eeeb957

everything get alright if a single simicolon is added after 'NAMESPACE_BEGIN' in line 1.
a2e93c4d-9107-44ba-952d-2ddb4686bb70

After removing the simicolon and add the definition of NAMESPACE_BEGIN/END, I find syntax highlight error in '#endif' of line 3 but 'class' seems correct now !
3d81f931-4717-4870-bd31-b8476e3bb404

@oulrich1
Copy link

oulrich1 commented Apr 4, 2016

This problem was mentioned here.

I am using one of the workarounds from here. At the very bottom: "Customizing Language Recognition"

The workaround is to correctly update your config.cson under Atom > Config with:

"*":
  core:
    customFileTypes:
      "source.cpp": [
        "h"
      ]

@thomasjo
Copy link
Contributor

thomasjo commented Apr 5, 2016

Duplicate of #89. Can also be resolved using the customFileTypes feature, as described by @oulrich1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants