summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index be0c07e..a91257e 100644
--- a/buffer.c
+++ b/buffer.c
@@ -272,9 +272,37 @@ Language buffer_language(TextBuffer *buffer) {
return LANG_NONE;
}
+// score is higher if buffer more closely matches context.
+static long buffer_context_score(TextBuffer *buffer, const SettingsContext *context) {
+ long score = 0;
+
+ if (buffer_language(buffer) == context->language) {
+ score += 100000;
+ }
+
+ if (context->path) {
+ int i;
+ for (i = 0; i < TED_PATH_MAX && buffer->filename[i] == context->path[i]; ++i);
+ score += i;
+ }
+
+ return score;
+}
+
// Get the settings used for this buffer.
Settings *buffer_settings(TextBuffer *buffer) {
- return &buffer->ted->settings_by_language[buffer_language(buffer)];
+ Ted *ted = buffer->ted;
+ long best_score = 0;
+ Settings *settings = ted->settings;
+
+ arr_foreach_ptr(ted->all_settings, Settings, s) {
+ long score = buffer_context_score(buffer, &s->context);
+ if (score > best_score) {
+ best_score = score;
+ settings = s;
+ }
+ }
+ return settings;
}