diff options
author | pommicket <pommicket@gmail.com> | 2022-11-02 13:02:38 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-11-02 13:02:38 -0400 |
commit | 26d34216da04a2b91e65a0eeee9200ad808d48ce (patch) | |
tree | e9781ff976f16f1f5249ca679aa2c941a35eb03c /buffer.c | |
parent | b63bd066bf06317e6637aa03369a75c018c1939f (diff) |
(insufficiently tested) per-path settings
also fixed memory bug in path_full, yet again
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -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; } |