summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-11-02 13:02:38 -0400
committerpommicket <pommicket@gmail.com>2022-11-02 13:02:38 -0400
commit26d34216da04a2b91e65a0eeee9200ad808d48ce (patch)
treee9781ff976f16f1f5249ca679aa2c941a35eb03c /buffer.c
parentb63bd066bf06317e6637aa03369a75c018c1939f (diff)
(insufficiently tested) per-path settings
also fixed memory bug in path_full, yet again
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;
}