summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
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.