mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
toggle todo lines!!! first try!
This commit is contained in:
@@ -211,6 +211,7 @@ The plugin defines the following functions.
|
||||
- `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
|
||||
- `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.
|
||||
|
||||
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>zc :lua require('telekasten').show_calendar()<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
|
||||
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
|
||||
" alternatively: leader [
|
||||
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==
|
||||
" ----- (see the section about coloring in README.md)
|
||||
|
||||
@@ -404,6 +404,11 @@ telekasten.show_calendar()~
|
||||
See also:~
|
||||
- |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*
|
||||
|
||||
@@ -428,7 +433,7 @@ The specific templates and settings used are:
|
||||
|
||||
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:
|
||||
|
||||
+----------------------------------+--------------------------------+
|
||||
@@ -520,12 +525,13 @@ However, here are some suggestions:
|
||||
nnoremap <leader>zy :lua require('telekasten').yank_notelink()<CR>
|
||||
nnoremap <leader>zc :lua require('telekasten').show_calendar()<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
|
||||
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>
|
||||
" alternatively: leader [
|
||||
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==
|
||||
" (see the section about coloring in README.md)
|
||||
|
||||
@@ -608,6 +608,35 @@ local SetupCalendar = function(opts)
|
||||
vim.cmd(cmd)
|
||||
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)
|
||||
--
|
||||
-- Overrides config with elements from cfg. See top of file for defaults.
|
||||
@@ -664,5 +693,6 @@ local M = {
|
||||
CalendarSignDay = CalendarSignDay,
|
||||
CalendarAction = CalendarAction,
|
||||
paste_img_and_link = imgFromClipboard,
|
||||
toggle_todo = ToggleTodo,
|
||||
}
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user