James Farwell 6 years ago • updated 6 years ago 0
Guessing language by the file extension alone or by the first line is often not enough. For example, the ".h" extension is shared by C, C++, Objective-C, and Objective-C++ (and more). The user can choose which language to open ".h" files as by default, but if they are working in a mixed codebase (e.g. it is likely if they are working with Objective-C++ there will also be Objective-C and C .h files laying around too) then this isn't enough. It would be pretty nice if there were keyword matching on the whole file to be able to guess the language.

For example, for ".h" files:

contains["@interface", "@end", "#import"] -> Objective-C
contains["class", "namespace", "::"] -> C++
contains[Objective-C AND C++] -> Objective-C++
default -> C

Another solution might be able to allow the user to assign the language based on directory... e.g. all ".h" files in "foo/bar/objc" are Objective-C but "foo/bar/cpp" are C++.