diff options
| author | Francesco Abbate <francesco.bbt@gmail.com> | 2021-09-01 18:29:49 +0200 |
|---|---|---|
| committer | Francesco Abbate <francesco.bbt@gmail.com> | 2021-09-01 18:29:49 +0200 |
| commit | 8a626cf7779726d77aff3dab4b6dd4f5681f1e86 (patch) | |
| tree | d78e16057c46b243d041cb3e49a4c16f91c46687 | |
| parent | f31312fd16b8d7d4f7b00b910d3ce1c1dde2e95f (diff) | |
| download | lite-xl-8a626cf7779726d77aff3dab4b6dd4f5681f1e86.tar.gz lite-xl-8a626cf7779726d77aff3dab4b6dd4f5681f1e86.zip | |
WIP: testing alternative detect indent algotesting-detect-indent-changes
| -rw-r--r-- | data/plugins/detectindent.lua | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/data/plugins/detectindent.lua b/data/plugins/detectindent.lua index 45ebaee6..e7b24c98 100644 --- a/data/plugins/detectindent.lua +++ b/data/plugins/detectindent.lua @@ -24,6 +24,30 @@ end local function optimal_indent_from_stat(stat) if #stat == 0 then return nil, 0 end local bins = {} + print(common.serialize(stat)) + for k = 1, #stat do + local indent = stat[k][1] + local penalty, score_max = 0, 0 + for i = 1, #stat do + local eval_indent, eval_count = unpack(stat[i]) + score_max = score_max + eval_count + if eval_indent < indent or (eval_indent > indent and eval_indent % indent ~= 0) then + penalty = penalty + eval_count + end + end + if k == 1 then print('SCORE MAX', score_max) end + bins[#bins + 1] = {indent, score_max - penalty} + end + print(common.serialize(bins)) + table.sort(bins, function(a, b) return a[2] > b[2] end) + return bins[1][1], bins[1][2] +end + +--[[ +local function optimal_indent_from_stat(stat) + if #stat == 0 then return nil, 0 end + local bins = {} + print(common.serialize(stat)) for k = 1, #stat do local indent = stat[k][1] local score = 0 @@ -41,10 +65,11 @@ local function optimal_indent_from_stat(stat) end bins[#bins + 1] = {indent, score} end + print(common.serialize(bins)) table.sort(bins, function(a, b) return a[2] > b[2] end) return bins[1][1], bins[1][2] end - +]] -- return nil if it is a comment or blank line or the initial part of the -- line otherwise. |
