summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-11-03 12:16:38 -0400
committerpommicket <pommicket@gmail.com>2022-11-03 12:16:38 -0400
commit609cdb6f0cc9f6f5d86366fbf60364f463cba551 (patch)
treeca5bd1765aecf1a9ca3560557fa37d1b61bcad26 /buffer.c
parent667284c3539546d269cee175cedd43671655499e (diff)
multiline string highlighting for ted.cfg
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/buffer.c b/buffer.c
index 4a54ff8..6e7ba7e 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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.