diff options
author | pommicket <pommicket@gmail.com> | 2022-11-03 12:16:38 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-11-03 12:16:38 -0400 |
commit | 609cdb6f0cc9f6f5d86366fbf60364f463cba551 (patch) | |
tree | ca5bd1765aecf1a9ca3560557fa37d1b61bcad26 /buffer.c | |
parent | 667284c3539546d269cee175cedd43671655499e (diff) |
multiline string highlighting for ted.cfg
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -253,8 +253,12 @@ Language buffer_language(TextBuffer *buffer) { return LANG_NONE; size_t filename_len = strlen(filename); + int match_score = 0; + Language match = LANG_NONE; + for (u16 l = 0; l < LANG_COUNT; ++l) { char const *extensions = settings->language_extensions[l]; + if (extensions) { // extensions is a string with commas separating each extension. size_t len = 0; @@ -262,14 +266,18 @@ Language buffer_language(TextBuffer *buffer) { if (*p == ',') ++p; // move past comma len = strcspn(p, ","); if (filename_len >= len && strncmp(&filename[filename_len - len], p, len) == 0) { - // found a match! - return (Language)l; + int score = (int)len; + if (score > match_score) { + // found a better match! + match_score = score; + match = l; + } } } } } - // no extensions matched - return LANG_NONE; + + return match; } // score is higher if context is closer match. |