diff options
| author | Thomas Schmucker <ts@its1.de> | 2026-03-06 12:37:08 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2026-03-06 12:37:08 +0100 |
| commit | cd8bf02c387bc0b2a0142bd368dea1e586a51949 (patch) | |
| tree | 71f96f6e6334f52ce09b338ea3447676666b5127 /nvim/lua | |
| parent | 0b97925fb8e916e14635c6ece5138a3008e7f8d3 (diff) | |
| download | dotfiles-cd8bf02c387bc0b2a0142bd368dea1e586a51949.tar.gz dotfiles-cd8bf02c387bc0b2a0142bd368dea1e586a51949.tar.bz2 dotfiles-cd8bf02c387bc0b2a0142bd368dea1e586a51949.zip | |
neovim: reine Lua funktion
Diffstat (limited to 'nvim/lua')
| -rw-r--r-- | nvim/lua/plugins/ui.lua | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/nvim/lua/plugins/ui.lua b/nvim/lua/plugins/ui.lua index 22c0c3a..70140d8 100644 --- a/nvim/lua/plugins/ui.lua +++ b/nvim/lua/plugins/ui.lua | |||
| @@ -63,43 +63,39 @@ return { | |||
| 63 | { | 63 | { |
| 64 | "mattn/calendar-vim", | 64 | "mattn/calendar-vim", |
| 65 | config = function() | 65 | config = function() |
| 66 | vim.cmd([[ | 66 | function _G.CalendarInsertDate(day, month, year) |
| 67 | function! CalendarInsertDate(day, month, year, week, dir) | 67 | local date = string.format("%04d-%02d-%02d", year, month, day) |
| 68 | let date = printf("%04d-%02d-%02d", a:year, a:month, a:day) | ||
| 69 | 68 | ||
| 70 | " Kalenderfenster schließen und zum vorherigen Fenster zurück | 69 | vim.cmd("wincmd q") |
| 71 | wincmd q | 70 | vim.cmd("wincmd p") |
| 72 | wincmd p | ||
| 73 | 71 | ||
| 74 | let pattern = '\v\d{4}-\d{2}-\d{2}' | 72 | local line = vim.api.nvim_get_current_line() |
| 75 | let line = getline('.') | 73 | local col = vim.api.nvim_win_get_cursor(0)[2] + 1 |
| 76 | let col = col('.') | ||
| 77 | 74 | ||
| 78 | " Prüfen ob Cursor innerhalb eines Datums steht | 75 | local start = 1 |
| 79 | let start = match(line, pattern) | 76 | while true do |
| 77 | local s, e = string.find(line, "%d%d%d%d%-%d%d%-%d%d", start) | ||
| 78 | if not s then break end | ||
| 80 | 79 | ||
| 81 | while start >= 0 | 80 | if col >= s and col <= e then |
| 82 | let end = start + strlen(matchstr(line[start:], pattern)) | 81 | local new = line:sub(1, s - 1) .. date .. line:sub(e + 1) |
| 83 | if col >= start + 1 && col <= end | 82 | vim.api.nvim_set_current_line(new) |
| 84 | " Datum ersetzen | 83 | vim.api.nvim_win_set_cursor(0, { vim.fn.line("."), s + #date - 1 }) |
| 85 | call setline('.', line[:start-1] . date . line[end:]) | 84 | return |
| 86 | call cursor('.', start + strlen(date)) | 85 | end |
| 87 | return | ||
| 88 | endif | ||
| 89 | let start = match(line, pattern, end) | ||
| 90 | endwhile | ||
| 91 | 86 | ||
| 92 | " Kein Datum unter Cursor → wie bisher einfügen | 87 | start = e + 1 |
| 93 | execute "normal! a" . date | 88 | end |
| 94 | endfunction | ||
| 95 | 89 | ||
| 96 | let calendar_action = 'CalendarInsertDate' | 90 | vim.api.nvim_put({ date }, "c", true, true) |
| 91 | end | ||
| 97 | 92 | ||
| 98 | let g:calendar_monday = 1 | 93 | vim.g.calendar_action = "v:lua.CalendarInsertDate" |
| 99 | let g:calendar_wruler = 'So Mo Di Mi Do Fr Sa' | 94 | |
| 100 | let g:calendar_mruler = 'Jan,Feb,Mär,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez' | 95 | vim.g.calendar_monday = 1 |
| 101 | let g:calendar_weeknm = 4 | 96 | vim.g.calendar_wruler = "So Mo Di Mi Do Fr Sa" |
| 102 | ]]) | 97 | vim.g.calendar_mruler = "Jan,Feb,Mär,Apr,Mai,Jun,Jul,Aug,Sep,Okt,Nov,Dez" |
| 98 | vim.g.calendar_weeknm = 4 | ||
| 103 | end, | 99 | end, |
| 104 | }, | 100 | }, |
| 105 | } | 101 | } |
