forked from nvim-orgmode/orgmode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add few org mappings for changing date.
- Loading branch information
1 parent
e81650a
commit 0e8990f
Showing
9 changed files
with
115 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
lua require('orgmode.config'):setup_mappings('org') | ||
inoreabbrev <buffer> :today: <<C-R>=luaeval("require('orgmode.objects.date').today():to_string()")<CR>> | ||
inoreabbrev <buffer> :now: <<C-R>=luaeval("require('orgmode.objects.date').now():to_string()")<CR>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
---@class OrgMappings | ||
---@field agenda Agenda | ||
local OrgMappings = {} | ||
local Date = require('orgmode.objects.date') | ||
local utils = require('orgmode.utils') | ||
|
||
---@param data table | ||
function OrgMappings:new(data) | ||
local opts = {} | ||
opts.agenda = data.agenda | ||
setmetatable(opts, self) | ||
self.__index = self | ||
return opts | ||
end | ||
|
||
function OrgMappings:adjust_date(adjustment, fallback) | ||
local line = vim.fn.getline('.') | ||
local last_col = vim.fn.col('$') | ||
local start = vim.fn.col('.') | ||
local finish = vim.fn.col('.') | ||
while start > 0 do | ||
local c = line:sub(start, start) | ||
if c == '<' or c == '[' then | ||
start = start + 1 | ||
break | ||
end | ||
start = start - 1 | ||
end | ||
|
||
while finish < last_col do | ||
local c = line:sub(finish, finish) | ||
if c == '>' or c == ']' then | ||
finish = finish - 1 | ||
break | ||
end | ||
finish = finish + 1 | ||
end | ||
|
||
if start == 0 or finish == last_col then | ||
return vim.api.nvim_feedkeys(utils.esc(fallback), 'n', true) | ||
end | ||
local selection = line:sub(start, finish) | ||
if not Date.is_valid_date(selection) then return end | ||
local date = Date.from_string(selection):adjust(adjustment):to_string() | ||
local view = vim.fn.winsaveview() | ||
vim.fn.setline(vim.fn.line('.'), string.format('%s%s%s', line:sub(1, start - 1), date, line:sub(finish + 1))) | ||
vim.fn.winrestview(view) | ||
end | ||
|
||
function OrgMappings:increase_date() | ||
return self:adjust_date('+1d', '<C-a>') | ||
end | ||
|
||
function OrgMappings:decrease_date() | ||
return self:adjust_date('-1d','<C-x>') | ||
end | ||
|
||
return OrgMappings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
lua require('orgmode.agenda.highlights').define_agenda_colors() | ||
syn match OrgAgendaDay /^\w\+\s\d\+\s\w\+\s\d\d\d\d$/ | ||
syn match OrgAgendaTags /:[^\s]*:$/ | ||
hi OrgBold gui=bold | ||
hi default link OrgAgendaDay Statement | ||
hi default link OrgAgendaTags OrgBold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters