From 4e46e6722a7a6c5ce6f4158e93a6a29b56a0b526 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Fri, 26 Nov 2021 23:54:31 +0100 Subject: [PATCH 1/2] fixed calendar action's week (day) parameter calculation in T mode (:CalendarT command) --- autoload/calendar.vim | 14 ++++++- lua/calc.lua | 86 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 lua/calc.lua diff --git a/autoload/calendar.vim b/autoload/calendar.vim index fc78678..ebb14a1 100644 --- a/autoload/calendar.vim +++ b/autoload/calendar.vim @@ -175,7 +175,19 @@ function! calendar#action(...) elseif b:CalendarDir == 2 let dir = 'T' let cnr = 1 - let week = ((col(".")+1) / 3) - 1 + "let week = ((col(".")+1) / 3) - 1 + if !exists('b:CalendarDir') && !(bufname('%') == '' && &l:modified == 0) + let width = &columns + let height = &lines - 2 + else + let width = winwidth(0) + let height = winheight(0) + echo width height + endif + let rene_d = (width - 5) / 8 + let rene_r = (width - 7 * rene_d - 3) / 2 + let rene_l = rene_r + 3 + let week = (col(".") - rene_l) / rene_d endif let lnr = 1 let hdr = 1 diff --git a/lua/calc.lua b/lua/calc.lua new file mode 100644 index 0000000..2728161 --- /dev/null +++ b/lua/calc.lua @@ -0,0 +1,86 @@ +-- just some lua to reverse engineer and test the calendar layout + + +--[[ +--Calendar layouts: + +63 columns + left = 8 + right = 5 + delta = 7 + +------+------+------+------+------+------+------+ + | +8 | 9 |+10 |+11 |+12 |+13 |+14 | KW45! + +105 Columns: + left = 12 + right = 9 + delta = 12 + +-----------+-----------+-----------+-----------+-----------+-----------+-----------+ + |+22 |+23 |+24 |+25 |*26 | 27 | 28 | KW47 ! + + +100 columns: + left = 13 + right = 10 + delta = 11 + +----------+----------+----------+----------+----------+----------+----------+ + |+22 |+23 |+24 |+25 |*26 | 27 | 28 | KW47 ! + +190 columns: + left = 16 + right = 13 + delta = 23 + +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ + |+22 |+23 |+24 |+25 |*26 | 27 | 28 | KW47 ! +--]] + +local inspect = function(t) + for k, v in pairs(t) do + print(k .. ":" .. " " .. v) + end +end + +local layout_consts = function(winwidth, left, delta) + -- right + 3 + 7 * delta + right = winwidth + -- 2 * right = winwidth - 7*delta - 3 + -- right = (winwidth - 7*delta - 3) / 2 + -- left = right + 3 + local d = math.floor((winwidth - 5) / 8) + local right = math.floor((winwidth - 7 * d - 3) / 2) + local l = right + 3 + local ret = {} + ret.left = l + ret.delta = d + ret.right = right + return ret +end + +local weekday = function(winwidth, x) + local c = layout_consts(winwidth) + local ret = {} + ret.windwidth = winwidth + ret.cursor_x = x + ret.dayindex = math.floor((x - c.left) / c.delta) + print(inspect(ret)) + return ret +end + +-- layout_consts(63, 8, 7) +-- layout_consts(105, 12, 12) +-- layout_consts(100, 13, 11) +-- layout_consts(190, 16, 23) + +local foo = function() + print(weekday(63, 8).dayindex == 0, "\n") + print(weekday(63, 9).dayindex == 0, "\n") + print(weekday(63, 10).dayindex == 0, "\n") + print(weekday(63, 11).dayindex == 0, "\n") + print(weekday(63, 12).dayindex == 0, "\n") + print(weekday(63, 13).dayindex == 0, "\n") + print(weekday(63, 14).dayindex == 0, "\n") + print(weekday(63, 15).dayindex == 1, "\n") + print(weekday(63, 16).dayindex == 1, "\n") + print(weekday(63, 49).dayindex == 5, "\n") + print(weekday(63, 50).dayindex == 6, "\n") + print(weekday(63, 51).dayindex == 6, "\n") +end From 63ab86cc6f31eefdbbaa870b3ea159e5a00a1fb3 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Sat, 27 Nov 2021 00:10:11 +0100 Subject: [PATCH 2/2] removed test code --- lua/calc.lua | 86 ---------------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 lua/calc.lua diff --git a/lua/calc.lua b/lua/calc.lua deleted file mode 100644 index 2728161..0000000 --- a/lua/calc.lua +++ /dev/null @@ -1,86 +0,0 @@ --- just some lua to reverse engineer and test the calendar layout - - ---[[ ---Calendar layouts: - -63 columns - left = 8 - right = 5 - delta = 7 - +------+------+------+------+------+------+------+ - | +8 | 9 |+10 |+11 |+12 |+13 |+14 | KW45! - -105 Columns: - left = 12 - right = 9 - delta = 12 - +-----------+-----------+-----------+-----------+-----------+-----------+-----------+ - |+22 |+23 |+24 |+25 |*26 | 27 | 28 | KW47 ! - - -100 columns: - left = 13 - right = 10 - delta = 11 - +----------+----------+----------+----------+----------+----------+----------+ - |+22 |+23 |+24 |+25 |*26 | 27 | 28 | KW47 ! - -190 columns: - left = 16 - right = 13 - delta = 23 - +----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+----------------------+ - |+22 |+23 |+24 |+25 |*26 | 27 | 28 | KW47 ! ---]] - -local inspect = function(t) - for k, v in pairs(t) do - print(k .. ":" .. " " .. v) - end -end - -local layout_consts = function(winwidth, left, delta) - -- right + 3 + 7 * delta + right = winwidth - -- 2 * right = winwidth - 7*delta - 3 - -- right = (winwidth - 7*delta - 3) / 2 - -- left = right + 3 - local d = math.floor((winwidth - 5) / 8) - local right = math.floor((winwidth - 7 * d - 3) / 2) - local l = right + 3 - local ret = {} - ret.left = l - ret.delta = d - ret.right = right - return ret -end - -local weekday = function(winwidth, x) - local c = layout_consts(winwidth) - local ret = {} - ret.windwidth = winwidth - ret.cursor_x = x - ret.dayindex = math.floor((x - c.left) / c.delta) - print(inspect(ret)) - return ret -end - --- layout_consts(63, 8, 7) --- layout_consts(105, 12, 12) --- layout_consts(100, 13, 11) --- layout_consts(190, 16, 23) - -local foo = function() - print(weekday(63, 8).dayindex == 0, "\n") - print(weekday(63, 9).dayindex == 0, "\n") - print(weekday(63, 10).dayindex == 0, "\n") - print(weekday(63, 11).dayindex == 0, "\n") - print(weekday(63, 12).dayindex == 0, "\n") - print(weekday(63, 13).dayindex == 0, "\n") - print(weekday(63, 14).dayindex == 0, "\n") - print(weekday(63, 15).dayindex == 1, "\n") - print(weekday(63, 16).dayindex == 1, "\n") - print(weekday(63, 49).dayindex == 5, "\n") - print(weekday(63, 50).dayindex == 6, "\n") - print(weekday(63, 51).dayindex == 6, "\n") -end