Skip to content

Commit dfa5792

Browse files
Tweak calendar to jump to first/last day when going forward/backward and remove pipes. Fixes nvim-orgmode#98.
1 parent 345c2f0 commit dfa5792

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

Diff for: lua/orgmode/objects/calendar.lua

+11-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function Calendar.render()
9393
end
9494
end
9595
local value = vim.tbl_map(function(item)
96-
return ' ' .. table.concat(item, ' | ')
96+
return ' ' .. table.concat(item, ' ') .. ' '
9797
end, content)
9898
first_row = ' ' .. table.concat(first_row, ' ')
9999
table.insert(value, 1, first_row)
@@ -121,11 +121,15 @@ end
121121
function Calendar.forward()
122122
Calendar.month = Calendar.month:add({ month = 1 })
123123
Calendar.render()
124+
vim.fn.cursor(2, 0)
125+
vim.fn.search('01')
124126
end
125127

126128
function Calendar.backward()
127129
Calendar.month = Calendar.month:subtract({ month = 1 })
128130
Calendar.render()
131+
vim.fn.cursor('$', 0)
132+
vim.fn.search([[\d\d]], 'b')
129133
end
130134

131135
function Calendar.reset()
@@ -137,14 +141,18 @@ function Calendar.reset()
137141
end
138142

139143
function Calendar:select()
144+
local col = vim.fn.col('.')
145+
local char = vim.fn.getline('.'):sub(col, col)
140146
local day = vim.trim(vim.fn.expand('<cword>'))
141147
local line = vim.fn.line('.')
142-
if line < 3 or not day:match('%d+') then
143-
return utils.echo_warning('Please select valid day number.')
148+
vim.cmd([[redraw!]])
149+
if line < 3 or not char:match('%d') then
150+
return utils.echo_warning('Please select valid day number.', nil, false)
144151
end
145152
day = tonumber(day)
146153
local selected_date = Calendar.month:set({ day = day })
147154
local cb = Calendar.callback
155+
vim.cmd([[echon]])
148156
vim.cmd([[bw!]])
149157
if type(cb) == 'function' then
150158
cb(selected_date)

Diff for: lua/orgmode/utils.lua

+15-8
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,27 @@ end
4545

4646
---@param msg string
4747
---@param additional_msg table
48-
function utils.echo_warning(msg, additional_msg)
49-
return utils._echo(msg, 'WarningMsg', additional_msg)
48+
---@param store_in_history boolean
49+
function utils.echo_warning(msg, additional_msg, store_in_history)
50+
return utils._echo(msg, 'WarningMsg', additional_msg, store_in_history)
5051
end
5152

5253
---@param msg string
5354
---@param additional_msg table
54-
function utils.echo_error(msg, additional_msg)
55-
return utils._echo(msg, 'ErrorMsg', additional_msg)
55+
---@param store_in_history boolean
56+
function utils.echo_error(msg, additional_msg, store_in_history)
57+
return utils._echo(msg, 'ErrorMsg', additional_msg, store_in_history)
5658
end
5759

5860
---@param msg string
5961
---@param additional_msg table
60-
function utils.echo_info(msg, additional_msg)
61-
return utils._echo(msg, nil, additional_msg)
62+
---@param store_in_history boolean
63+
function utils.echo_info(msg, additional_msg, store_in_history)
64+
return utils._echo(msg, nil, additional_msg, store_in_history)
6265
end
6366

6467
---@private
65-
function utils._echo(msg, hl, additional_msg)
68+
function utils._echo(msg, hl, additional_msg, store_in_history)
6669
vim.cmd([[redraw!]])
6770
local msg_item = { string.format('[orgmode] %s', msg) }
6871
if hl then
@@ -72,7 +75,11 @@ function utils._echo(msg, hl, additional_msg)
7275
if additional_msg then
7376
msg_list = utils.concat(msg_list, additional_msg)
7477
end
75-
return vim.api.nvim_echo(msg_list, true, {})
78+
local store = true
79+
if type(store_in_history) == 'boolean' then
80+
store = store_in_history
81+
end
82+
return vim.api.nvim_echo(msg_list, store, {})
7683
end
7784

7885
---@param word string

0 commit comments

Comments
 (0)