toggle todo lines!!! first try!

This commit is contained in:
Rene Schallner
2021-11-26 14:01:07 +01:00
parent e05450b676
commit 05b959b2af
3 changed files with 41 additions and 3 deletions

View File

@@ -211,6 +211,7 @@ The plugin defines the following functions.
- `yank_notelink()` : yank a link to the current note, ready to paste - `yank_notelink()` : yank a link to the current note, ready to paste
- `show_calendar()` : opens up the calendar in a properly-sized vertical split at the very right - `show_calendar()` : opens up the calendar in a properly-sized vertical split at the very right
- `paste_img_and_link()` : pastes an image from the clipboard into a file under `image_subdir` and inserts a link to it at the current cursor position - `paste_img_and_link()` : pastes an image from the clipboard into a file under `image_subdir` and inserts a link to it at the current cursor position
- `toggle_todo()` : turn a line into a `- [ ] ` line, or toggle between `- [ ]`, `- [x]`, and `- `.
- `setup(opts)`: used for configuring paths, file extension, etc. - `setup(opts)`: used for configuring paths, file extension, etc.
To use one of the functions above, just run them with the `:lua ...` command. To use one of the functions above, just run them with the `:lua ...` command.
@@ -317,12 +318,13 @@ nnoremap <leader>zN :lua require('telekasten').new_templated_note()<CR>
nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR> nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR>
nnoremap <leader>zc :lua require('telekasten').show_calendar()<CR> nnoremap <leader>zc :lua require('telekasten').show_calendar()<CR>
nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR> nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR>
nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
" we could define [[ in **insert mode** to call insert link " we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR> " inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
" alternatively: leader [ " alternatively: leader [
inoremap <leader>[ <ESC>:lua require('telekasten').insert_link()<CR> inoremap <leader>[ <ESC>:lua require('telekasten').insert_link()<CR>
inoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
" ----- the following are for syntax-coloring [[links]] and ==highlighted text== " ----- the following are for syntax-coloring [[links]] and ==highlighted text==
" ----- (see the section about coloring in README.md) " ----- (see the section about coloring in README.md)

View File

@@ -404,6 +404,11 @@ telekasten.show_calendar()~
See also:~ See also:~
- |telekasten.calendar| - |telekasten.calendar|
*telekasten.toggle_todo()*
telekasten.toggle_todo()~
Turns a line into a `- [ ] ` todo line, or toggle between `- [ ]`, `- [x]`,
and `-` .
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
Section 3.1: Templates *telekasten.templates* Section 3.1: Templates *telekasten.templates*
@@ -428,7 +433,7 @@ The specific templates and settings used are:
See also |telekasten.template_files| below for more on the specific templates. See also |telekasten.template_files| below for more on the specific templates.
The following table shows you what action creates what kind of non-existing The folloet ing table shows you what action creates what kind of non-existing
note: note:
+----------------------------------+--------------------------------+ +----------------------------------+--------------------------------+
@@ -520,12 +525,13 @@ However, here are some suggestions:
nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR> nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR>
nnoremap <leader>zc :lua require('telekasten').show_calendar()<CR> nnoremap <leader>zc :lua require('telekasten').show_calendar()<CR>
nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR> nnoremap <leader>zi :lua require('telekasten').paste_img_and_link()<CR>
nnoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
" we could define [[ in **insert mode** to call insert link " we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR> " inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
" alternatively: leader [ " alternatively: leader [
inoremap <leader>[ <ESC>:lua require('telekasten').insert_link()<CR> inoremap <leader>[ <ESC>:lua require('telekasten').insert_link()<CR>
inoremap <leader>zt :lua require('telekasten').toggle_todo()<CR>
" the following are for syntax-coloring [[links]] and ==highlighted text== " the following are for syntax-coloring [[links]] and ==highlighted text==
" (see the section about coloring in README.md) " (see the section about coloring in README.md)

View File

@@ -608,6 +608,35 @@ local SetupCalendar = function(opts)
vim.cmd(cmd) vim.cmd(cmd)
end end
local ToggleTodo = function()
-- replace
-- by -
-- - by - [ ]
-- - [ ] by - [x]
-- - [x] by -
local linenr = vim.api.nvim_win_get_cursor(0)[1]
local curline = vim.api.nvim_buf_get_lines(0, linenr - 1, linenr, false)[1]
-- if curline.strip().startswith('- ') and not curline.strip.startswith('- [')...
-- print('cur: ' .. curline)
local stripped = vim.trim(curline)
local repline
if vim.startswith(stripped, "- ") and not vim.startswith(stripped, "- [") then
repline = curline:gsub("- ", "- [ ] ", 1)
else
if vim.startswith(stripped, "- [ ]") then
repline = curline:gsub("- %[ %]", "- [x]", 1)
else
if vim.startswith(stripped, "- [x]") then
repline = curline:gsub("- %[x%]", "-", 1)
else
repline = curline:gsub("(%S)", "- [ ] %1", 1)
end
end
end
vim.api.nvim_buf_set_lines(0, linenr - 1, linenr, false, repline)
-- print('rep: ' .. repl)
end
-- Setup(cfg) -- Setup(cfg)
-- --
-- Overrides config with elements from cfg. See top of file for defaults. -- Overrides config with elements from cfg. See top of file for defaults.
@@ -664,5 +693,6 @@ local M = {
CalendarSignDay = CalendarSignDay, CalendarSignDay = CalendarSignDay,
CalendarAction = CalendarAction, CalendarAction = CalendarAction,
paste_img_and_link = imgFromClipboard, paste_img_and_link = imgFromClipboard,
toggle_todo = ToggleTodo,
} }
return M return M