added option parameter i to toggle_todo(opts) and insert_link(opts) to enter insert mode.

This commit is contained in:
Rene Schallner
2021-11-28 00:33:13 +01:00
parent c3ba6c5b59
commit d3710d8e50
4 changed files with 43 additions and 9 deletions

View File

@@ -3,6 +3,7 @@
- [ ] yt video
## Dones
- [x] added option parameter `i` to `toggle_todo(opts)` and `insert_link(opts)` to enter insert mode.
- [x] find_friends()
- [x] show_backlinks() : issue #3
- [x] replaced `vim.ui.input` by `vim.fn.input`, as the former was causing problems on nvim 0.5.x

View File

@@ -220,11 +220,17 @@ The plugin defines the following functions.
- `goto_thisweek()` : pops up a Telescope window with this week's weekly note pre-selected. This week's note can optionally be created if not present, using the configured template
- `search_notes()`: live grep for word under cursor in all notes (search in notes), via Telescope
- `insert_link()` : select a note by name, via Telescope, and place a `[[link]]` at the current cursor position
- **note**:
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#bind-it).
- example: `insert_link({ i=true })`
- `follow_link()`: take text between brackets (linked note) and open a Telescope file finder with it: selects note to open (incl. preview) - with optional note creation for non-existing notes, honoring the configured template
- `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 `- `.
- **note**:
- this function accepts a parameter `{i}`. If `true`, it will enter input mode by pressing the 'A' key. This is useful when being used in a simple `inoremap` key mapping like shown in [Bind it](#bind-it).
- example: `toggle_todo({ i=true })`
- `show_backlinks()` : opens a telescope search for notes that `[[link]]` back to the current note.
- `find_friends()` : opens a telescope search for notes that also `[[link]]` to the link under the cursor.
- `setup(opts)`: used for configuring paths, file extension, etc.
@@ -347,8 +353,8 @@ nnoremap <leader>zF :lua require('telekasten').find_friends()<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 <ESC>:lua require('telekasten').toggle_todo()<CR>
inoremap <leader>[ <ESC>:lua require('telekasten').insert_link({ i=true })<CR>
inoremap <leader>zt <ESC>:lua require('telekasten').toggle_todo({ i=true })<CR>
" ----- the following are for syntax-coloring [[links]] and ==highlighted text==
" ----- (see the section about coloring in README.md)

View File

@@ -374,10 +374,19 @@ telekasten.search_notes()~
under the cursor.
*telekasten.insert_link()*
telekasten.insert_link()~
telekasten.insert_link({opts})~
Select a note by title (file name), via Telescope, and place a `[[link]]` at
the current cursor position.
Valid keys for {opts}
i:~
If `true`, it will enter input mode by pressing the <A> key. This is useful
when being used in a simple `inoremap` key mapping like shown in
|telekasten.mappings|.
Default: `nil`
*telekasten.follow_link()*
telekasten.insert_link()~
Take the text between the brackets of a link, pointing to a linked note, and
@@ -405,10 +414,19 @@ telekasten.show_calendar()~
- |telekasten.calendar|
*telekasten.toggle_todo()*
telekasten.toggle_todo()~
telekasten.toggle_todo({opts})~
Turns a line into a `- [ ] ` todo line, or toggle between `- [ ]`, `- [x]`,
and `-` .
Valid keys for {opts}
i:~
If `true`, it will enter input mode by pressing the <A> key. This is useful
when being used in a simple `inoremap` key mapping like shown in
|telekasten.mappings|.
Default: `nil`
*telekasten.show_backlinks()*
telekasten.show_backlinks()~
Opens a telescope search for notes that `[[link]]` back to the current note.
@@ -551,8 +569,8 @@ However, here are some suggestions:
" 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 <ESC>:lua require('telekasten').toggle_todo()<CR>
inoremap <leader>[ <ESC>:lua require('telekasten').insert_link({ i=true })<CR>
inoremap <leader>zt <ESC>:lua require('telekasten').toggle_todo({ i=true })<CR>
" the following are for syntax-coloring [[links]] and ==highlighted text==
" (see the section about coloring in README.md)

View File

@@ -70,7 +70,7 @@ end
-- image stuff
local imgFromClipboard = function()
if vim.fn.executable("xclip") == 0 then
print("No xclip installed!")
vim.api.nvim_err_write("No xclip installed!\n")
return
end
@@ -303,7 +303,8 @@ end
--
-- Select from all notes and put a link in the current buffer
--
local InsertLink = function(_)
local InsertLink = function(opts)
opts = opts or {}
builtin.find_files({
prompt_title = "Insert link to note",
cwd = M.Cfg.home,
@@ -313,6 +314,9 @@ local InsertLink = function(_)
local selection = action_state.get_selected_entry()
local fn = path_to_linkname(selection.value)
vim.api.nvim_put({ "[[" .. fn .. "]]" }, "", false, true)
if opts.i then
vim.api.nvim_feedkeys("A", "m", false)
end
end)
return true
end,
@@ -657,12 +661,14 @@ local SetupCalendar = function(opts)
vim.cmd(cmd)
end
local ToggleTodo = function()
local ToggleTodo = function(opts)
-- replace
-- by -
-- - by - [ ]
-- - [ ] by - [x]
-- - [x] by -
-- enter insert mode if opts.i == true
opts = opts or {}
local linenr = vim.api.nvim_win_get_cursor(0)[1]
local curline = vim.api.nvim_buf_get_lines(0, linenr - 1, linenr, false)[1]
local stripped = vim.trim(curline)
@@ -681,6 +687,9 @@ local ToggleTodo = function()
end
end
vim.api.nvim_buf_set_lines(0, linenr - 1, linenr, false, { repline })
if opts.i then
vim.api.nvim_feedkeys("A", "m", false)
end
end
-- Setup(cfg)