micro icon indicating copy to clipboard operation
micro copied to clipboard

Nondeterministic filetype detection (c, c++, objective-c) for *.h files

Open dmaluka opened this issue 4 years ago • 2 comments

The filetype of *.h files is detected nondeterministically: sometimes it's c, sometimes objective-c, which results in slightly different highlighting.

To work around this, I force it to c++ in my settings.json, overriding automatic detection for *.h files, so I have the same highlighting each time:

    "*.h": {
        "filetype": "c++"
    },

Commit hash: de8f4bf OS: any Terminal: any

dmaluka avatar Feb 23 '21 20:02 dmaluka

Perhaps a simple fix for this issue is just like my workaround: always set c++ filetype for a *.h file (i.e. have a rule for *.h in cpp.hdr only, remove it from c.hdr and objc.hdr, making it deterministic). That's how it works in Vim. It's a good tradeoff for C and C++ header files, since C++ syntax is mostly a superset of C. But I'm not familiar with Objective-C so I don't know if such solution would be ok for Objective-C header files.

dmaluka avatar Feb 23 '21 21:02 dmaluka

Duplicate of https://github.com/zyedidia/micro/issues/2166.

Calinou avatar May 05 '22 23:05 Calinou

I've noticed that in the newest Micro it is actually deterministic: C is always chosen over C++ and Objective-C for *.h files. The reason is that built-in syntax files are now sorted alphabetically (probably since the introduction of go:embed in #2195), so c comes before cpp and objc.

Which of course does not mean that there is no issue: the ambiguity between C, C++ and Objective-C for *.h files is still not properly resolved (C always takes precedence just by virtue of being alphabetically first).

dmaluka avatar Sep 08 '23 13:09 dmaluka