From 440c615553e7318b4dcdf2dadc2ba150741d0b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Mon, 4 Sep 2023 01:20:45 +0200 Subject: [PATCH 01/16] feat: implement time picker To make it more convenient to scheduled dates with particular times extends the existing date picker with a time picker. - t adds a time and jumps to the time picker - j and k decrease or increase the time, counts are supported - h and l determine if the time is shifted about an hour, 10 minutes or 5 minutes - T clears the time - Esc leaves the time picker first and pressed secondly the date picker --- lua/orgmode/objects/calendar.lua | 214 ++++++++++++++++++++++++++++--- 1 file changed, 198 insertions(+), 16 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 963202f82..690f48227 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -7,20 +7,28 @@ local namespace = vim.api.nvim_create_namespace('org_calendar') ---@alias OrgCalendarOnRenderDayOpts { line: number, from: number, to: number, buf: number, namespace: number } ---@alias OrgCalendarOnRenderDay fun(day: OrgDate, opts: OrgCalendarOnRenderDayOpts) +-- // begin TODO still relevant? +local SelState = { DAY = 0, HOUR = 1, MIN_10 = 2, MIN_5 = 3 } +-- // end + ---@class OrgCalendar ----@field win number ----@field buf number +---@field win number? +---@field buf number? ---@field callback fun(date: OrgDate | nil, cleared?: boolean) ---@field namespace function ----@field date OrgDate +---@field date OrgDate? ---@field month OrgDate ---@field title? string ---@field on_day? OrgCalendarOnRenderDay - +---@field select_state integer +---@field clearable boolean local Calendar = { win = nil, buf = nil, date = nil, + month = Date.today():start_of('month'), + selected = nil, + select_state = SelState.DAY, clearable = false, } Calendar.__index = Calendar @@ -44,7 +52,7 @@ function Calendar.new(data) end local width = 36 -local height = 10 +local height = 13 local x_offset = 1 -- one border cell local y_offset = 2 -- one border cell and one padding cell @@ -121,12 +129,15 @@ function Calendar:open() return self:clear_date() end, map_opts) end - local search_day = Date.today():format('%d') - if self.date then - search_day = self.date:format('%d') + vim.keymap.set('n', 't', function() + self:set_time() + end, map_opts) + if self:has_time() then + vim.keymap.set('n', 'T', function() + self:clear_time() + end, map_opts) end - vim.fn.cursor(2, 1) - vim.fn.search(search_day, 'W') + self:jump_day() return Promise.new(function(resolve) self.callback = resolve end) @@ -175,6 +186,10 @@ function Calendar:render() -- put it all together table.insert(content, 1, ' ' .. table.concat(weekday_row, ' ')) table.insert(content, 1, title) + + table.insert(content, self:render_time()) + table.insert(content, '') + -- TODO: redundant, since it's static data table.insert(content, ' [<] - prev month [>] - next month') table.insert(content, ' [.] - today [Enter] - select day') @@ -183,14 +198,28 @@ function Calendar:render() else table.insert(content, ' [i] - enter date') end + if self:has_time() then + table.insert(content, ' [t] - enter time [T] - clear time') + else + table.insert(content, ' [t] - enter time') + end + --<<<<<<< HEAD vim.api.nvim_buf_set_lines(self.buf, 0, -1, true, content) vim.api.nvim_buf_clear_namespace(self.buf, namespace, 0, -1) if self.clearable then vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 3, 0, -1) end + -- + if not self:has_time() then + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 8, 0, -1) + end + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 4, 0, -1) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 3, 0, -1) + -- vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 2, 0, -1) vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 1, 0, -1) + -->>>>>>> 008d7dd (feat: implement time picker) for i, line in ipairs(content) do local from = 0 @@ -215,6 +244,7 @@ function Calendar:render() vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) end +--<<<<<<< HEAD ---@param day OrgDate ---@param opts { from: number, to: number, line: number} function Calendar:on_render_day(day, opts) @@ -233,6 +263,22 @@ function Calendar:on_render_day(day, opts) end end +function Calendar.left_pad(time_part) + return time_part < 10 and '0' .. time_part or time_part +end + +function Calendar:render_time() + local l_pad = ' ' + local r_pad = ' ' + local hour_str = self:has_time() and Calendar.left_pad(self.date.hour) or '--' + local min_str = self:has_time() and Calendar.left_pad(self.date.min) or '--' + return l_pad .. hour_str .. ':' .. min_str .. r_pad +end + +function Calendar:has_time() + return not self.date.date_only +end + function Calendar:forward() self.month = self.month:add({ month = vim.v.count1 }) self:render() @@ -248,7 +294,17 @@ function Calendar:backward() end function Calendar:cursor_right() - for i = 1, vim.v.count1 do + if self.select_state ~= SelState.DAY then + if self.select_state == SelState.HOUR then + self:set_sel_min10() + elseif self.select_state == SelState.MIN_10 then + self:set_sel_min5() + elseif self.select_state == SelState.MIN_5 then + self:set_sel_hour() + end + return + end + for _ = 1, vim.v.count1 do local line, col = vim.fn.line('.'), vim.fn.col('.') local curr_line = vim.fn.getline('.') local offset = curr_line:sub(col + 1, #curr_line):find('%d%d') @@ -259,7 +315,17 @@ function Calendar:cursor_right() end function Calendar:cursor_left() - for i = 1, vim.v.count1 do + if self.select_state ~= SelState.DAY then + if self.select_state == SelState.HOUR then + self:set_sel_min5() + elseif self.select_state == SelState.MIN_10 then + self:set_sel_hour() + elseif self.select_state == SelState.MIN_5 then + self:set_sel_min10() + end + return + end + for _ = 1, vim.v.count1 do local line, col = vim.fn.line('.'), vim.fn.col('.') local curr_line = vim.fn.getline('.') local _, offset = curr_line:sub(1, col - 1):find('.*%d%d') @@ -270,7 +336,23 @@ function Calendar:cursor_left() end function Calendar:cursor_up() - for i = 1, vim.v.count1 do + if self.select_state ~= SelState.DAY then + -- to avoid unexpectedly changing the day we cache it ... + local day = self.date.day + if self.select_state == SelState.HOUR then + self.date = self.date:subtract({ hour = vim.v.count1 }) + elseif self.select_state == SelState.MIN_10 then + self.date = self.date:subtract({ min = 10 * vim.v.count1 }) + elseif self.select_state == SelState.MIN_5 then + self.date = self.date:subtract({ min = 5 * vim.v.count1 }) + end + -- and restore the cached day after adjusting the time + self.date = self.date:set({ day = day }) + self:rerender_time() + return + end + + for _ = 1, vim.v.count1 do local line, col = vim.fn.line('.'), vim.fn.col('.') if line > 9 then vim.fn.cursor(line - 1, col) @@ -294,7 +376,22 @@ function Calendar:cursor_up() end function Calendar:cursor_down() - for i = 1, vim.v.count1 do + if self.select_state ~= SelState.DAY then + -- to avoid unexpectedly changing the day we cache it ... + local day = self.date.day + if self.select_state == SelState.HOUR then + self.date = self.date:add({ hour = 1 * vim.v.count1 }) + elseif self.select_state == SelState.MIN_10 then + self.date = self.date:add({ min = 10 * vim.v.count1 }) + elseif self.select_state == SelState.MIN_5 then + self.date = self.date:add({ min = 5 * vim.v.count1 }) + end + -- and restore the cached day after adjusting the time + self.date = self.date:set({ day = day }) + self:rerender_time() + return + end + for _ = 1, vim.v.count1 do local line, col = vim.fn.line('.'), vim.fn.col('.') if line <= 1 then vim.fn.cursor(line + 1, col) @@ -326,6 +423,9 @@ function Calendar:reset() end function Calendar:get_selected_date() + if self.select_state ~= SelState.DAY then + return self.date + end local col = vim.fn.col('.') local char = vim.fn.getline('.'):sub(col, col) local day = vim.trim(vim.fn.expand('')) @@ -334,18 +434,46 @@ function Calendar:get_selected_date() if line < 3 or not char:match('%d') then return utils.echo_warning('Please select valid day number.', nil, false) end - return self.month:set({ day = tonumber(day) }) + --return self.month:set({ day = tonumber(day) }) + -- day = tonumber(day) + return self.date:set({ + month = self.month.month, + day = day, + date_only = self.date.date_only, + }) end function Calendar:select() - local selected_date = self:get_selected_date() + local selected_date + if self.select_state == SelState.DAY then + selected_date = self:get_selected_date() + else + selected_date = self.date:set({ + day = self.date.day, + hour = self.date.hour, + min = self.date.min, + date_only = false, + }) + self.select_state = SelState.DAY + end local cb = self.callback self.callback = nil + vim.cmd([[echon]]) vim.api.nvim_win_close(0, true) return cb(selected_date) end +--======= +--function Calendar.abort() +-- if Calendar.select_state == SelState.DAY then +-- vim.cmd([[echon]]) +-- vim.api.nvim_win_close(0, true) +-- Calendar.dispose() +-- end +-- Calendar.set_sel_day() +--end +--<<<<<<< HEAD function Calendar:dispose() self.win = nil self.buf = nil @@ -381,4 +509,58 @@ function Calendar:read_date() end) end +function Calendar:set_time() + self.date = self:get_selected_date() + self.date = self.date:set({ date_only = false }) + self:rerender_time() + self:set_sel_hour() +end + +function Calendar:rerender_time() + vim.api.nvim_set_option_value('modifiable', true, { buf = self.buf }) + vim.api.nvim_buf_set_lines(self.buf, 8, 9, true, { self:render_time() }) + if self:has_time() then + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time [T] - clear time' }) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Normal', 8, 0, -1) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) + else + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time' }) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 8, 0, -1) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) + end + vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) +end + +function Calendar:clear_time() + self.date = self.date:set({ hour = 0, min = 0, date_only = true }) + self:rerender_time() + self:set_sel_day() +end + +function Calendar:set_sel_hour() + self.select_state = SelState.HOUR + vim.fn.cursor({ 9, 16 }) +end + +function Calendar:set_sel_day() + self.select_state = SelState.DAY + self:jump_day() +end + +function Calendar:set_sel_min10() + self.select_state = SelState.MIN_10 + vim.fn.cursor({ 9, 19 }) +end + +function Calendar:set_sel_min5() + self.select_state = SelState.MIN_5 + vim.fn.cursor({ 9, 20 }) +end + +function Calendar:jump_day() + local search_day = (self.date or Date.today()):format('%d') + vim.fn.cursor(2, 1) + vim.fn.search(search_day, 'W') +end + return Calendar From 6126f78424757d1998a1e557854359e075468bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sun, 22 Oct 2023 15:35:12 +0200 Subject: [PATCH 02/16] feat(date): add default to 'Enter date' When entering the date via direct input, provide the currently selected date as default value. --- lua/orgmode/objects/calendar.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 690f48227..40736078c 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -493,7 +493,8 @@ function Calendar:clear_date() end function Calendar:read_date() - vim.ui.input({ prompt = 'Enter date: ' }, function(result) + local default = self:get_selected_date():to_string() + vim.ui.input({ prompt = 'Enter date: ', default = default }, function(result) if result then local date = Date.from_string(result) if not date then From 60963a77e874da2f891a4b755280edc1d8d2516a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sat, 13 Jan 2024 20:25:16 +0100 Subject: [PATCH 03/16] chore: fix warnings in calendar --- lua/orgmode/objects/calendar.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 40736078c..cc120c65e 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -428,14 +428,12 @@ function Calendar:get_selected_date() end local col = vim.fn.col('.') local char = vim.fn.getline('.'):sub(col, col) - local day = vim.trim(vim.fn.expand('')) + local day = tonumber(vim.trim(vim.fn.expand(''))) local line = vim.fn.line('.') vim.cmd([[redraw!]]) if line < 3 or not char:match('%d') then return utils.echo_warning('Please select valid day number.', nil, false) end - --return self.month:set({ day = tonumber(day) }) - -- day = tonumber(day) return self.date:set({ month = self.month.month, day = day, From 5e0e9ca24582ca5f6edb7e575ad9177b82d3069a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sat, 13 Jan 2024 20:44:33 +0100 Subject: [PATCH 04/16] fix: jump to descrete 10 or 5 minute steps When adjusting an odd minute value, we first want to jump to the next flat 10 or 5 minute value. --- lua/orgmode/objects/calendar.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index cc120c65e..3d702b3bf 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -340,11 +340,11 @@ function Calendar:cursor_up() -- to avoid unexpectedly changing the day we cache it ... local day = self.date.day if self.select_state == SelState.HOUR then - self.date = self.date:subtract({ hour = vim.v.count1 }) + self.date = self.date:add({ hour = vim.v.count1 }) elseif self.select_state == SelState.MIN_10 then - self.date = self.date:subtract({ min = 10 * vim.v.count1 }) + self.date = self.date:add({ min = 10 * vim.v.count1 - self.date.min % 10 }) elseif self.select_state == SelState.MIN_5 then - self.date = self.date:subtract({ min = 5 * vim.v.count1 }) + self.date = self.date:add({ min = 5 * vim.v.count1 - self.date.min % 5 }) end -- and restore the cached day after adjusting the time self.date = self.date:set({ day = day }) @@ -380,11 +380,11 @@ function Calendar:cursor_down() -- to avoid unexpectedly changing the day we cache it ... local day = self.date.day if self.select_state == SelState.HOUR then - self.date = self.date:add({ hour = 1 * vim.v.count1 }) + self.date = self.date:subtract({ hour = 1 * vim.v.count1 }) elseif self.select_state == SelState.MIN_10 then - self.date = self.date:add({ min = 10 * vim.v.count1 }) + self.date = self.date:subtract({ min = 10 * vim.v.count1 + self.date.min % 10 }) elseif self.select_state == SelState.MIN_5 then - self.date = self.date:add({ min = 5 * vim.v.count1 }) + self.date = self.date:subtract({ min = 5 * vim.v.count1 + self.date.min % 5 }) end -- and restore the cached day after adjusting the time self.date = self.date:set({ day = day }) From 9b740963a041db5ac480873453050f78bf35587f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sat, 13 Jan 2024 21:18:51 +0100 Subject: [PATCH 05/16] feat: make minute steps configurable Because it's a matter of preference, in which steps the user want's to jump through minutes, we make it configurable. --- lua/orgmode/config/defaults.lua | 1 + lua/orgmode/objects/calendar.lua | 57 +++++++++++++++++++------------- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/lua/orgmode/config/defaults.lua b/lua/orgmode/config/defaults.lua index 6577a86ba..41a983d8a 100644 --- a/lua/orgmode/config/defaults.lua +++ b/lua/orgmode/config/defaults.lua @@ -41,6 +41,7 @@ local DefaultConfig = { org_startup_indented = false, org_indent_mode_turns_off_org_adapt_indentation = true, org_indent_mode_turns_on_hiding_stars = true, + org_time_stamp_rounding_min_big = 15, org_time_stamp_rounding_minutes = 5, org_blank_before_new_entry = { heading = true, diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 3d702b3bf..d18572ce5 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -7,9 +7,9 @@ local namespace = vim.api.nvim_create_namespace('org_calendar') ---@alias OrgCalendarOnRenderDayOpts { line: number, from: number, to: number, buf: number, namespace: number } ---@alias OrgCalendarOnRenderDay fun(day: OrgDate, opts: OrgCalendarOnRenderDayOpts) --- // begin TODO still relevant? -local SelState = { DAY = 0, HOUR = 1, MIN_10 = 2, MIN_5 = 3 } --- // end +local SelState = { DAY = 0, HOUR = 1, MIN_BIG = 2, MIN_SMALL = 3 } +local big_minute_step = config.org_time_stamp_rounding_min_big +local small_minute_step = config.org_time_stamp_rounding_minutes ---@class OrgCalendar ---@field win number? @@ -296,10 +296,10 @@ end function Calendar:cursor_right() if self.select_state ~= SelState.DAY then if self.select_state == SelState.HOUR then - self:set_sel_min10() - elseif self.select_state == SelState.MIN_10 then - self:set_sel_min5() - elseif self.select_state == SelState.MIN_5 then + self:set_min_big() + elseif self.select_state == SelState.MIN_BIG then + self:set_min_small() + elseif self.select_state == SelState.MIN_SMALL then self:set_sel_hour() end return @@ -317,11 +317,11 @@ end function Calendar:cursor_left() if self.select_state ~= SelState.DAY then if self.select_state == SelState.HOUR then - self:set_sel_min5() - elseif self.select_state == SelState.MIN_10 then + self:set_min_small() + elseif self.select_state == SelState.MIN_BIG then self:set_sel_hour() - elseif self.select_state == SelState.MIN_5 then - self:set_sel_min10() + elseif self.select_state == SelState.MIN_SMALL then + self:set_min_big() end return end @@ -335,16 +335,27 @@ function Calendar:cursor_left() end end +---@param direction string +---@param step_size number +---@param current number +---@param count number +local function step(direction, step_size, current, count) + local sign = direction == 'up' and -1 or 1 + local residual = current % step_size + local factor = (residual == 0 or direction == 'up') and count or count - 1 + return factor * step_size + sign * residual +end + function Calendar:cursor_up() if self.select_state ~= SelState.DAY then -- to avoid unexpectedly changing the day we cache it ... local day = self.date.day if self.select_state == SelState.HOUR then self.date = self.date:add({ hour = vim.v.count1 }) - elseif self.select_state == SelState.MIN_10 then - self.date = self.date:add({ min = 10 * vim.v.count1 - self.date.min % 10 }) - elseif self.select_state == SelState.MIN_5 then - self.date = self.date:add({ min = 5 * vim.v.count1 - self.date.min % 5 }) + elseif self.select_state == SelState.MIN_BIG then + self.date = self.date:add({ min = step('up', big_minute_step, self.date.min, vim.v.count1) }) + elseif self.select_state == SelState.MIN_SMALL then + self.date = self.date:add({ min = step('up', small_minute_step, self.date.min, vim.v.count1) }) end -- and restore the cached day after adjusting the time self.date = self.date:set({ day = day }) @@ -381,10 +392,10 @@ function Calendar:cursor_down() local day = self.date.day if self.select_state == SelState.HOUR then self.date = self.date:subtract({ hour = 1 * vim.v.count1 }) - elseif self.select_state == SelState.MIN_10 then - self.date = self.date:subtract({ min = 10 * vim.v.count1 + self.date.min % 10 }) - elseif self.select_state == SelState.MIN_5 then - self.date = self.date:subtract({ min = 5 * vim.v.count1 + self.date.min % 5 }) + elseif self.select_state == SelState.MIN_BIG then + self.date = self.date:subtract({ min = step('down', big_minute_step, self.date.min, vim.v.count1) }) + elseif self.select_state == SelState.MIN_SMALL then + self.date = self.date:subtract({ min = step('down', small_minute_step, self.date.min, vim.v.count1) }) end -- and restore the cached day after adjusting the time self.date = self.date:set({ day = day }) @@ -546,13 +557,13 @@ function Calendar:set_sel_day() self:jump_day() end -function Calendar:set_sel_min10() - self.select_state = SelState.MIN_10 +function Calendar:set_min_big() + self.select_state = SelState.MIN_BIG vim.fn.cursor({ 9, 19 }) end -function Calendar:set_sel_min5() - self.select_state = SelState.MIN_5 +function Calendar:set_min_small() + self.select_state = SelState.MIN_SMALL vim.fn.cursor({ 9, 20 }) end From 566b80904e6d84ac9507866ba34f70c8b0b81b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sat, 13 Jan 2024 21:45:31 +0100 Subject: [PATCH 06/16] feat: highlight currently selected date --- lua/orgmode/objects/calendar.lua | 37 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index d18572ce5..f47c7792e 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -20,6 +20,7 @@ local small_minute_step = config.org_time_stamp_rounding_minutes ---@field month OrgDate ---@field title? string ---@field on_day? OrgCalendarOnRenderDay +---@field selected OrgDate? ---@field select_state integer ---@field clearable boolean local Calendar = { @@ -34,6 +35,7 @@ local Calendar = { Calendar.__index = Calendar vim.cmd([[hi default OrgCalendarToday gui=reverse cterm=reverse]]) +vim.cmd([[hi default OrgCalendarSelected gui=underline cterm=underline]]) ---@param data { date?: OrgDate, clearable?: boolean, title?: string, on_day?: OrgCalendarOnRenderDay } function Calendar.new(data) @@ -204,22 +206,33 @@ function Calendar:render() table.insert(content, ' [t] - enter time') end - --<<<<<<< HEAD vim.api.nvim_buf_set_lines(self.buf, 0, -1, true, content) vim.api.nvim_buf_clear_namespace(self.buf, namespace, 0, -1) if self.clearable then vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 3, 0, -1) end - -- + if not self:has_time() then vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 8, 0, -1) end + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 4, 0, -1) vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 3, 0, -1) - -- vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 2, 0, -1) vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 1, 0, -1) - -->>>>>>> 008d7dd (feat: implement time picker) + + -- highlight selected day + local current_date = self.date + local is_selected_month = current_date ~= nil and current_date:is_same(self.month, 'month') + if is_selected_month then + local day_formatted = current_date and current_date:format('%d') + for i, line in ipairs(content) do + local from, to = line:find('%s' .. day_formatted .. '%s') + if from and to then + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'OrgCalendarSelected', i - 1, from - 1, to) + end + end + end for i, line in ipairs(content) do local from = 0 @@ -244,7 +257,6 @@ function Calendar:render() vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) end ---<<<<<<< HEAD ---@param day OrgDate ---@param opts { from: number, to: number, line: number} function Calendar:on_render_day(day, opts) @@ -261,6 +273,8 @@ function Calendar:on_render_day(day, opts) }) ) end + + vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) end function Calendar.left_pad(time_part) @@ -473,16 +487,6 @@ function Calendar:select() return cb(selected_date) end ---======= ---function Calendar.abort() --- if Calendar.select_state == SelState.DAY then --- vim.cmd([[echon]]) --- vim.api.nvim_win_close(0, true) --- Calendar.dispose() --- end --- Calendar.set_sel_day() ---end ---<<<<<<< HEAD function Calendar:dispose() self.win = nil self.buf = nil @@ -522,7 +526,8 @@ end function Calendar:set_time() self.date = self:get_selected_date() self.date = self.date:set({ date_only = false }) - self:rerender_time() + --self:rerender_time() + self:render() -- because we want to highlight the currently selected date, we have to render everything self:set_sel_hour() end From f522eb4bc058b92da1ae3f0e7ac03788c9711b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sun, 14 Jan 2024 00:38:27 +0100 Subject: [PATCH 07/16] refactor: extract date highlighting into function --- lua/orgmode/objects/calendar.lua | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index f47c7792e..63515af35 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -200,6 +200,8 @@ function Calendar:render() else table.insert(content, ' [i] - enter date') end + + -- FIXME this line is currently not shown because of a bug. if self:has_time() then table.insert(content, ' [t] - enter time [T] - clear time') else @@ -221,19 +223,12 @@ function Calendar:render() vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 2, 0, -1) vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 1, 0, -1) + -- highlight the cell of the current day + self:highlight_day(content, Date.today(), 'OrgCalendarToday') -- highlight selected day - local current_date = self.date - local is_selected_month = current_date ~= nil and current_date:is_same(self.month, 'month') - if is_selected_month then - local day_formatted = current_date and current_date:format('%d') - for i, line in ipairs(content) do - local from, to = line:find('%s' .. day_formatted .. '%s') - if from and to then - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'OrgCalendarSelected', i - 1, from - 1, to) - end - end - end + self:highlight_day(content, self.date, 'OrgCalendarSelected') + -- TODO this new loop (after Kristjans refactoring) is currently not fully understood. for i, line in ipairs(content) do local from = 0 local to, num @@ -277,6 +272,26 @@ function Calendar:on_render_day(day, opts) vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) end +---@param day OrgDate? +---@param hl_group string +function Calendar:highlight_day(content, day, hl_group) + if not day then + return + end + + if not day:is_same(self.month, 'month') then + return + end + + local day_formatted = day:format('%d') + for i, line in ipairs(content) do + local from, to = line:find('%s' .. day_formatted .. '%s') + if from and to then + vim.api.nvim_buf_add_highlight(self.buf, namespace, hl_group, i - 1, from - 1, to) + end + end +end + function Calendar.left_pad(time_part) return time_part < 10 and '0' .. time_part or time_part end From a81d5f6f41178d3c5186017cb8b59afb1908b3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sun, 14 Jan 2024 00:40:58 +0100 Subject: [PATCH 08/16] feat: update date selection regularly --- lua/orgmode/objects/calendar.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 63515af35..24d832e79 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -313,6 +313,7 @@ function Calendar:forward() self:render() vim.fn.cursor(2, 1) vim.fn.search('01') + Calendar.render() end function Calendar:backward() @@ -320,6 +321,7 @@ function Calendar:backward() self:render() vim.fn.cursor(vim.fn.line('$'), 0) vim.fn.search([[\d\d]], 'b') + Calendar.render() end function Calendar:cursor_right() @@ -341,6 +343,8 @@ function Calendar:cursor_right() vim.fn.cursor(line, col + offset) end end + Calendar.date = Calendar.get_selected_date() + Calendar.render() end function Calendar:cursor_left() @@ -362,6 +366,8 @@ function Calendar:cursor_left() vim.fn.cursor(line, offset) end end + Calendar.date = Calendar.get_selected_date() + Calendar.render() end ---@param direction string @@ -413,6 +419,8 @@ function Calendar:cursor_up() end vim.fn.cursor(line - 1, move_to) end + Calendar.date = Calendar.get_selected_date() + Calendar.render() end function Calendar:cursor_down() @@ -452,6 +460,8 @@ function Calendar:cursor_down() end vim.fn.cursor(line + 1, move_to) end + Calendar.date = Calendar.get_selected_date() + Calendar.render() end function Calendar:reset() From 74b91785bea59a497d20e29458c051d16ad50f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Sun, 14 Jan 2024 00:46:19 +0100 Subject: [PATCH 09/16] feat: round minutes on adjusting hours --- lua/orgmode/config/defaults.lua | 3 +- lua/orgmode/objects/calendar.lua | 57 +++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/lua/orgmode/config/defaults.lua b/lua/orgmode/config/defaults.lua index 41a983d8a..e455e30fd 100644 --- a/lua/orgmode/config/defaults.lua +++ b/lua/orgmode/config/defaults.lua @@ -41,7 +41,8 @@ local DefaultConfig = { org_startup_indented = false, org_indent_mode_turns_off_org_adapt_indentation = true, org_indent_mode_turns_on_hiding_stars = true, - org_time_stamp_rounding_min_big = 15, + org_time_picker_min_big = 15, + org_time_picker_round_min_with_hours = true, org_time_stamp_rounding_minutes = 5, org_blank_before_new_entry = { heading = true, diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 24d832e79..d87333eb5 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -8,7 +8,7 @@ local namespace = vim.api.nvim_create_namespace('org_calendar') ---@alias OrgCalendarOnRenderDay fun(day: OrgDate, opts: OrgCalendarOnRenderDayOpts) local SelState = { DAY = 0, HOUR = 1, MIN_BIG = 2, MIN_SMALL = 3 } -local big_minute_step = config.org_time_stamp_rounding_min_big +local big_minute_step = config.org_time_picker_min_big local small_minute_step = config.org_time_stamp_rounding_minutes ---@class OrgCalendar @@ -313,7 +313,7 @@ function Calendar:forward() self:render() vim.fn.cursor(2, 1) vim.fn.search('01') - Calendar.render() + self:render() end function Calendar:backward() @@ -321,7 +321,7 @@ function Calendar:backward() self:render() vim.fn.cursor(vim.fn.line('$'), 0) vim.fn.search([[\d\d]], 'b') - Calendar.render() + self:render() end function Calendar:cursor_right() @@ -343,8 +343,8 @@ function Calendar:cursor_right() vim.fn.cursor(line, col + offset) end end - Calendar.date = Calendar.get_selected_date() - Calendar.render() + self.date = self:get_selected_date() + self:render() end function Calendar:cursor_left() @@ -366,31 +366,51 @@ function Calendar:cursor_left() vim.fn.cursor(line, offset) end end - Calendar.date = Calendar.get_selected_date() - Calendar.render() + self.date = self:get_selected_date() + self:render() end ---@param direction string ---@param step_size number ---@param current number ---@param count number -local function step(direction, step_size, current, count) +local function step_minute(direction, step_size, current, count) local sign = direction == 'up' and -1 or 1 local residual = current % step_size local factor = (residual == 0 or direction == 'up') and count or count - 1 return factor * step_size + sign * residual end +--- Controls, how the hours are adjusted. The rounding the minutes can be disabled +--- by the user, so adjusting the hours just moves the time 1 our back or forth +---@param direction string +---@param current OrgDate +---@param count number +---@return table +local function step_hour(direction, current, count) + if not config.org_time_picker_round_min_with_hours or current.min % big_minute_step == 0 then + return { hour = count, min = 0 } + end + + -- if adjusting the mins would land on a full hour, we don't step a full hour, + -- otherwise we do and round the minutes + local sign = direction == 'up' and 1 or -1 + local min = step_minute(direction, big_minute_step, current.min, 1) + local min_new = current.min + sign * min + local hour = min_new % 60 ~= 0 and count or count - 1 + return { hour = hour, min = min } +end + function Calendar:cursor_up() if self.select_state ~= SelState.DAY then -- to avoid unexpectedly changing the day we cache it ... local day = self.date.day if self.select_state == SelState.HOUR then - self.date = self.date:add({ hour = vim.v.count1 }) + self.date = self.date:add(step_hour('up', self.date, vim.v.count1)) elseif self.select_state == SelState.MIN_BIG then - self.date = self.date:add({ min = step('up', big_minute_step, self.date.min, vim.v.count1) }) + self.date = self.date:add({ min = step_minute('up', big_minute_step, self.date.min, vim.v.count1) }) elseif self.select_state == SelState.MIN_SMALL then - self.date = self.date:add({ min = step('up', small_minute_step, self.date.min, vim.v.count1) }) + self.date = self.date:add({ min = step_minute('up', small_minute_step, self.date.min, vim.v.count1) }) end -- and restore the cached day after adjusting the time self.date = self.date:set({ day = day }) @@ -419,20 +439,19 @@ function Calendar:cursor_up() end vim.fn.cursor(line - 1, move_to) end - Calendar.date = Calendar.get_selected_date() - Calendar.render() + self.date = self:get_selected_date() + self:render() end function Calendar:cursor_down() if self.select_state ~= SelState.DAY then - -- to avoid unexpectedly changing the day we cache it ... local day = self.date.day if self.select_state == SelState.HOUR then - self.date = self.date:subtract({ hour = 1 * vim.v.count1 }) + self.date = self.date:subtract(step_hour('down', self.date, vim.v.count1)) elseif self.select_state == SelState.MIN_BIG then - self.date = self.date:subtract({ min = step('down', big_minute_step, self.date.min, vim.v.count1) }) + self.date = self.date:subtract({ min = step_minute('down', big_minute_step, self.date.min, vim.v.count1) }) elseif self.select_state == SelState.MIN_SMALL then - self.date = self.date:subtract({ min = step('down', small_minute_step, self.date.min, vim.v.count1) }) + self.date = self.date:subtract({ min = step_minute('down', small_minute_step, self.date.min, vim.v.count1) }) end -- and restore the cached day after adjusting the time self.date = self.date:set({ day = day }) @@ -460,8 +479,8 @@ function Calendar:cursor_down() end vim.fn.cursor(line + 1, move_to) end - Calendar.date = Calendar.get_selected_date() - Calendar.render() + self.date = self:get_selected_date() + self:render() end function Calendar:reset() From a52a268d7f3d68586db2254feb8ed61f922275d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Mon, 27 May 2024 23:31:51 +0200 Subject: [PATCH 10/16] fix: show time picker also when changing date --- lua/orgmode/objects/calendar.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index d87333eb5..1cbea5a37 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -54,7 +54,7 @@ function Calendar.new(data) end local width = 36 -local height = 13 +local height = 14 local x_offset = 1 -- one border cell local y_offset = 2 -- one border cell and one padding cell @@ -63,7 +63,7 @@ function Calendar:open() local opts = { relative = 'editor', width = width, - height = self.clearable and height + 1 or height, + height = height, style = 'minimal', border = config.win_border, row = vim.o.lines / 2 - (y_offset + height) / 2, From f4da11cd350a5dca14a93460a5c05f77590a914f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Mon, 27 May 2024 23:47:57 +0200 Subject: [PATCH 11/16] fix: enable clear time keymap consistently To be able to clear times if no timestamp was set when the picker was loaded, we need to set the clear-time keymapping during rerendering of time. --- lua/orgmode/objects/calendar.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 1cbea5a37..6b57cc28d 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -135,6 +135,7 @@ function Calendar:open() self:set_time() end, map_opts) if self:has_time() then + print('apply clear_time') vim.keymap.set('n', 'T', function() self:clear_time() end, map_opts) @@ -579,6 +580,9 @@ function Calendar:rerender_time() vim.api.nvim_set_option_value('modifiable', true, { buf = self.buf }) vim.api.nvim_buf_set_lines(self.buf, 8, 9, true, { self:render_time() }) if self:has_time() then + vim.keymap.set('n', 'T', function() + self:clear_time() + end, { buffer = self.buf, silent = true, nowait = true }) vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time [T] - clear time' }) vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Normal', 8, 0, -1) vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) From e483f6d773bda29574ed5c9e46259b9687babe29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Tue, 28 May 2024 07:35:38 +0200 Subject: [PATCH 12/16] refactor: integrate highlights into new function --- lua/orgmode/objects/calendar.lua | 32 ++++---------------------------- lua/orgmode/objects/date.lua | 8 +++++++- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 6b57cc28d..763716db1 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -224,12 +224,6 @@ function Calendar:render() vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 2, 0, -1) vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', #content - 1, 0, -1) - -- highlight the cell of the current day - self:highlight_day(content, Date.today(), 'OrgCalendarToday') - -- highlight selected day - self:highlight_day(content, self.date, 'OrgCalendarSelected') - - -- TODO this new loop (after Kristjans refactoring) is currently not fully understood. for i, line in ipairs(content) do local from = 0 local to, num @@ -256,10 +250,12 @@ end ---@param day OrgDate ---@param opts { from: number, to: number, line: number} function Calendar:on_render_day(day, opts) - local is_today = day:is_today() - if is_today then + if day:is_today() then vim.api.nvim_buf_add_highlight(self.buf, namespace, 'OrgCalendarToday', opts.line - 1, opts.from - 1, opts.to) end + if day:is_same_day(self.date) then + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'OrgCalendarSelected', opts.line - 1, opts.from - 1, opts.to) + end if self.on_day then self.on_day( day, @@ -273,26 +269,6 @@ function Calendar:on_render_day(day, opts) vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) end ----@param day OrgDate? ----@param hl_group string -function Calendar:highlight_day(content, day, hl_group) - if not day then - return - end - - if not day:is_same(self.month, 'month') then - return - end - - local day_formatted = day:format('%d') - for i, line in ipairs(content) do - local from, to = line:find('%s' .. day_formatted .. '%s') - if from and to then - vim.api.nvim_buf_add_highlight(self.buf, namespace, hl_group, i - 1, from - 1, to) - end - end -end - function Calendar.left_pad(time_part) return time_part < 10 and '0' .. time_part or time_part end diff --git a/lua/orgmode/objects/date.lua b/lua/orgmode/objects/date.lua index 6e9e147bd..6784f8444 100644 --- a/lua/orgmode/objects/date.lua +++ b/lua/orgmode/objects/date.lua @@ -29,6 +29,7 @@ local time_format = '%H:%M' ---@field related_date_range OrgDate ---@field dayname string ---@field adjustments string[] +---@private is_today_date boolean? local Date = { ---@type fun(this: OrgDate, other: OrgDate): boolean __eq = function(this, other) @@ -605,11 +606,16 @@ end function Date:is_today() if self.is_today_date == nil then local date = now() - self.is_today_date = date.year == self.year and date.month == self.month and date.day == self.day + self.is_today_date = self:is_same_day(date) end return self.is_today_date end +---@return boolean +function Date:is_same_day(date) + return date and date.year == self.year and date.month == self.month and date.day == self.day +end + ---@return boolean function Date:is_obsolete_range_end() return self.is_date_range_end and self.related_date_range:is_same(self, 'day') From 9db1d662dee42d51b549f17e43fde50cab3d74d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Tue, 28 May 2024 01:31:03 +0200 Subject: [PATCH 13/16] fix: allow to switch back to day selection --- lua/orgmode/objects/calendar.lua | 58 ++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index 763716db1..e34f1ecd0 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -202,9 +202,12 @@ function Calendar:render() table.insert(content, ' [i] - enter date') end - -- FIXME this line is currently not shown because of a bug. - if self:has_time() then - table.insert(content, ' [t] - enter time [T] - clear time') + if self:has_time() or self.select_state ~= SelState.DAY then + if self.select_state == SelState.DAY then + table.insert(content, ' [t] - enter time [T] - clear time') + else + table.insert(content, ' [d] - enter time [T] - clear time') + end else table.insert(content, ' [t] - enter time') end @@ -281,6 +284,32 @@ function Calendar:render_time() return l_pad .. hour_str .. ':' .. min_str .. r_pad end +function Calendar:rerender_time() + vim.api.nvim_set_option_value('modifiable', true, { buf = self.buf }) + vim.api.nvim_buf_set_lines(self.buf, 8, 9, true, { self:render_time() }) + if self:has_time() then + local map_opts = { buffer = self.buf, silent = true, nowait = true } + vim.keymap.set('n', 'T', function() + self:clear_time() + end, map_opts) + vim.keymap.set('n', 'd', function() + self:set_day() + end, map_opts) + if self.select_state == SelState.DAY then + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - select day [T] - clear time' }) + else + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [d] - select day [T] - clear time' }) + end + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Normal', 8, 0, -1) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) + else + vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time' }) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 8, 0, -1) + vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) + end + vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) +end + function Calendar:has_time() return not self.date.date_only end @@ -548,32 +577,19 @@ function Calendar:set_time() self.date = self:get_selected_date() self.date = self.date:set({ date_only = false }) --self:rerender_time() - self:render() -- because we want to highlight the currently selected date, we have to render everything self:set_sel_hour() + self:render() -- because we want to highlight the currently selected date, we have to render everything end -function Calendar:rerender_time() - vim.api.nvim_set_option_value('modifiable', true, { buf = self.buf }) - vim.api.nvim_buf_set_lines(self.buf, 8, 9, true, { self:render_time() }) - if self:has_time() then - vim.keymap.set('n', 'T', function() - self:clear_time() - end, { buffer = self.buf, silent = true, nowait = true }) - vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time [T] - clear time' }) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Normal', 8, 0, -1) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) - else - vim.api.nvim_buf_set_lines(self.buf, 13, 14, true, { ' [t] - enter time' }) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 8, 0, -1) - vim.api.nvim_buf_add_highlight(self.buf, namespace, 'Comment', 13, 0, -1) - end - vim.api.nvim_set_option_value('modifiable', false, { buf = self.buf }) +function Calendar:set_day() + self:set_sel_day() + self:rerender_time() end function Calendar:clear_time() self.date = self.date:set({ hour = 0, min = 0, date_only = true }) - self:rerender_time() self:set_sel_day() + self:rerender_time() end function Calendar:set_sel_hour() From 55195838d750d6c04dd5ee555cd3a1262336819f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Tue, 28 May 2024 09:05:01 +0200 Subject: [PATCH 14/16] feat: overhaul config options - wrap everything into calendar - cleanup names - use boolean "start_from_sunday" --- lua/orgmode/config/defaults.lua | 7 +++++-- lua/orgmode/objects/calendar.lua | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lua/orgmode/config/defaults.lua b/lua/orgmode/config/defaults.lua index e455e30fd..583d12284 100644 --- a/lua/orgmode/config/defaults.lua +++ b/lua/orgmode/config/defaults.lua @@ -1,6 +1,7 @@ ---@class OrgDefaultConfig ---@field org_id_method 'uuid' | 'ts' | 'org' ---@field org_agenda_span 'day' | 'week' | 'month' | 'year' | number +---@field calendar { round_min_with_hours: boolean, min_big_step: number, min_small_step: number? } local DefaultConfig = { org_agenda_files = '', org_default_notes_file = '', @@ -13,6 +14,10 @@ local DefaultConfig = { org_agenda_start_on_weekday = 1, org_agenda_start_day = nil, -- start from today + this modifier calendar_week_start_day = 1, + calendar = { + round_min_with_hours = true, + min_big_step = 15, + }, org_capture_templates = { t = { description = 'Task', @@ -41,8 +46,6 @@ local DefaultConfig = { org_startup_indented = false, org_indent_mode_turns_off_org_adapt_indentation = true, org_indent_mode_turns_on_hiding_stars = true, - org_time_picker_min_big = 15, - org_time_picker_round_min_with_hours = true, org_time_stamp_rounding_minutes = 5, org_blank_before_new_entry = { heading = true, diff --git a/lua/orgmode/objects/calendar.lua b/lua/orgmode/objects/calendar.lua index e34f1ecd0..25cb91774 100644 --- a/lua/orgmode/objects/calendar.lua +++ b/lua/orgmode/objects/calendar.lua @@ -8,8 +8,8 @@ local namespace = vim.api.nvim_create_namespace('org_calendar') ---@alias OrgCalendarOnRenderDay fun(day: OrgDate, opts: OrgCalendarOnRenderDayOpts) local SelState = { DAY = 0, HOUR = 1, MIN_BIG = 2, MIN_SMALL = 3 } -local big_minute_step = config.org_time_picker_min_big -local small_minute_step = config.org_time_stamp_rounding_minutes +local big_minute_step = config.calendar.min_big_step +local small_minute_step = config.calendar.min_small_step or config.org_time_stamp_rounding_minutes ---@class OrgCalendar ---@field win number? @@ -388,13 +388,13 @@ local function step_minute(direction, step_size, current, count) end --- Controls, how the hours are adjusted. The rounding the minutes can be disabled ---- by the user, so adjusting the hours just moves the time 1 our back or forth +--- by the user, so adjusting the hours would just move the time 1 hour back or forth ---@param direction string ---@param current OrgDate ---@param count number ---@return table local function step_hour(direction, current, count) - if not config.org_time_picker_round_min_with_hours or current.min % big_minute_step == 0 then + if not config.calendar.round_min_with_hours or current.min % big_minute_step == 0 then return { hour = count, min = 0 } end From eaffdfc73e27c966318df18cebbfc48e6da6fcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Tue, 28 May 2024 09:32:13 +0200 Subject: [PATCH 15/16] doc: add some docs for the config options --- DOCS.md | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/DOCS.md b/DOCS.md index 5c4bb3be1..6926a51c1 100644 --- a/DOCS.md +++ b/DOCS.md @@ -4,7 +4,8 @@ 2. [Settings](#settings) 1. [Global settings](#global-settings) 2. [Agenda settings](#agenda-settings) - 3. [Tags settings](#tags-settings) + 3. [Calendar settings](#calendar-settings) + 4. [Tags settings](#tags-settings) 3. [Mappings](#mappings) 1. [Global mappings](#global-mappings) 2. [Agenda mappings](#agenda-mappings) @@ -677,6 +678,28 @@ Additional files to search from agenda search prompt.
Currently it accepts only a single value: `agenda-archives`.
Example value: `{'agenda-archives'}` +### Calendar settings + +Adjust behavior of the calendar modal (ex: [changing the date under cursor](#org_change_date)). + +#### **calendar.round_min_with_hours** + +_type_: `boolean`
+_default_: `true`
+Should minutes be rounded, when the hour is changed. It behaves more fluently when changing the hours, especially when scheduling from the current time (which can be something odd). If set to false, the minutes are unchanged while changing the hours. + +#### **calendar.min_big_step** + +_type_: `number`
+_default_: `15`
+The step size for changing the minutes while the cursor is on the first digit. + +#### **calendar.min_small_step** + +_type_: `number`
+_default_: same as [](#org_time_stamp_rounding_minutes)
+The step size for changing the minutes while the cursor is on the second digit. + ### Tags settings #### **org_tags_column** From 6a64028501022e937d386dbf8f4b274c8acf7a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Fl=C3=BCgge?= Date: Tue, 28 May 2024 09:52:15 +0200 Subject: [PATCH 16/16] doc: fix typo --- DOCS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOCS.md b/DOCS.md index 6926a51c1..7de868637 100644 --- a/DOCS.md +++ b/DOCS.md @@ -1735,7 +1735,7 @@ This option is most optimized because it doesn't load plugins and your init.vim For **MacOS**, things should be very similar, but I wasn't able to test it. Any help on this is appreciated. ## Clocking -There is partial suport for [Clocking work time](https://orgmode.org/manual/Clocking-Work-Time.html).
+There is partial support for [Clocking work time](https://orgmode.org/manual/Clocking-Work-Time.html).
Supported actions: ##### Clock in Org file mapping: `oxi`