|
37 | 37 | #include <sstream> |
38 | 38 | #include <srchilite/sourcehighlight.h> |
39 | 39 | #include <srchilite/langmap.h> |
| 40 | +#include <srchilite/settings.h> |
40 | 41 | #endif |
41 | 42 |
|
42 | 43 | /* The number of source files we'll cache. */ |
@@ -205,22 +206,35 @@ try_source_highlight (std::string &contents ATTRIBUTE_UNUSED, |
205 | 206 | return false; |
206 | 207 |
|
207 | 208 | const char *lang_name = get_language_name (lang); |
208 | | - if (lang_name == nullptr) |
209 | | - return false; |
210 | 209 |
|
211 | 210 | /* The global source highlight object, or null if one was |
212 | 211 | never constructed. This is stored here rather than in |
213 | 212 | the class so that we don't need to include anything or do |
214 | 213 | conditional compilation in source-cache.h. */ |
215 | 214 | static srchilite::SourceHighlight *highlighter; |
216 | 215 |
|
| 216 | + /* The global source highlight language map object. */ |
| 217 | + static srchilite::LangMap *langmap; |
| 218 | + |
217 | 219 | bool styled = false; |
218 | 220 | try |
219 | 221 | { |
220 | 222 | if (highlighter == nullptr) |
221 | 223 | { |
222 | 224 | highlighter = new srchilite::SourceHighlight ("esc.outlang"); |
223 | 225 | highlighter->setStyleFile ("esc.style"); |
| 226 | + |
| 227 | + const std::string &datadir = srchilite::Settings::retrieveDataDir (); |
| 228 | + langmap = new srchilite::LangMap (datadir, "lang.map"); |
| 229 | + } |
| 230 | + |
| 231 | + std::string detected_lang; |
| 232 | + if (lang_name == nullptr) |
| 233 | + { |
| 234 | + detected_lang = langmap->getMappedFileNameFromFileName (fullname); |
| 235 | + if (detected_lang.empty ()) |
| 236 | + return false; |
| 237 | + lang_name = detected_lang.c_str (); |
224 | 238 | } |
225 | 239 |
|
226 | 240 | std::istringstream input (contents); |
|
0 commit comments