browse_media() and picker actions

This commit is contained in:
Rene Schallner
2021-12-03 16:38:57 +01:00
parent b868cb4d71
commit 309eefe16b
4 changed files with 364 additions and 22 deletions

View File

@@ -6,12 +6,12 @@
- these buffers / this buffer should keep its size even when resizing other
splits (like the calendar)
- [ ] really good support for special links: inserting, yanking, ...
- can we add image pre-viewing capabilities from `telescope-media-files` to the standard previewer or a self-written
pre-viewer (config)?
- [ ] yt video
## Dones
- [x] browse_media()
- [x] action mappings for notes: yanking and link inserting
- [x] document and suggest colors for Calendar nav buttons, they look weird in gruvbox
- [x] initial support for special links
- links to headings

View File

@@ -84,6 +84,7 @@ of being able to edit it.
* [2.1 Note templates](#21-note-templates)
* [2.1.1 Template files](#211-template-files)
* [2.2 Using the calendar](#22-using-the-calendar)
* [2.3 Using the telescope pickers](#23-using-the-telescope-pickers)
* [3. Bind it](#3-bind-it)
* [4. The hardcoded stuff](#4-the-hardcoded-stuff)
@@ -219,7 +220,12 @@ require('telekasten').setup({
calendar_monday = 1,
-- calendar mark: where to put mark for marked days: 'left', 'right', 'left-fit'
calendar_mark = 'left-fit',
}
},
-- telescope actions behavior
close_after_yanking = false,
insert_after_inserting = true,
})
END
```
@@ -246,6 +252,8 @@ END
| | set to `nil` if you want none | |
| `plug_into_calendar` | activate calendar support if true (needs calendar-vim plugin) | true |
| `calendar_opts` | options for calendar, see below | see below |
| `close_after_yanking` | close telescope preview after yanking via <ctrl><y>| false |
| `insert_after_inserting` | enter insert mode after inserting a link from a telescope picker via <ctrl><i>| true |
**Please note:** If you do not want to use a template, set its associated option to `nil` or remove it from your config.
```lua
@@ -363,6 +371,8 @@ The plugin defines the following functions:
- `preview_img()` : uses the `telescope-media-files.nvim` extension to preview the image / media file under the cursor
of a markdown image link: `![](path/to/img.png)`. The cursor must be between `(the two parenthesis)`.
- **note**: this requires the `telescope-media-files.nvim` plugin to be installed.
- `browse_media()` : uses the `telescope-media-files.nvim` extension to preview the image / media files
- **note**: this requires the `telescope-media-files.nvim` plugin to be installed.
- `setup(opts)`: used for configuring paths, file extension, etc.
To use one of the functions above, just run them with the `:lua ...` command.
@@ -523,6 +533,22 @@ command in vim:
:CalendarT
```
## 2.3 Using the telescope pickers
When you are prompted with a telescope picker to select a note or media file, the following mappings apply:
- <kbd>CTRL</kbd> + <kbd>i</kbd> : inserts a link to the selected note / image
- the option `insert_after_inserting` defines if insert mode will be entered after the link is pasted into your
current buffer
- <kbd>CTRL</kbd> + <kbd>y</kbd> : yanks a link to the selected note / image, ready for <kbd>p</kbd>asting
- the option `close_after_yanking` defines whether the telescope window should be closed when the link has been
yanked
- <kbd>RETURN / ENTER</kbd> : usually opens the selected note or performs the action defined by the called function
- e.g. `insert_img_link()`'s action is to insert a link to the selected image.
## 3. Bind it
Usually, you would set up some key bindings, though:
@@ -532,6 +558,7 @@ nnoremap <leader>zd :lua require('telekasten').find_daily_notes()<CR>
nnoremap <leader>zg :lua require('telekasten').search_notes()<CR>
nnoremap <leader>zz :lua require('telekasten').follow_link()<CR>
nnoremap <leader>zT :lua require('telekasten').goto_today()<CR>
nnoremap <leader>zW :lua require('telekasten').goto_thisweek()<CR>
nnoremap <leader>zw :lua require('telekasten').find_weekly_notes()<CR>
nnoremap <leader>zn :lua require('telekasten').new_note()<CR>
nnoremap <leader>zN :lua require('telekasten').new_templated_note()<CR>
@@ -544,6 +571,7 @@ nnoremap <leader>zb :lua require('telekasten').show_backlinks()<CR>
nnoremap <leader>zF :lua require('telekasten').find_friends()<CR>
nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR>
nnoremap <leader>zp :lua require('telekasten').preview_img()<CR>
nnoremap <leader>zm :lua require('telekasten').browse_media()<CR>
" we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>

View File

@@ -31,6 +31,7 @@ CONTENTS
3.1 Link Notation ............ |telekasten.link_notation|
3.2 Templates ................ |telekasten.templates|
3.3 Calendar ................. |telekasten.calendar|
3.4 Picker mappings .......... |telekasten.picker_mappings|
4. Suggested mappings ............ |telekasten.mappings|
5. Credits ....................... |telekasten.credits|
@@ -621,6 +622,27 @@ Note:~
Calendar functions are only available if you have the plugin `calendar-vim`
installed, which you can find at https://github.com/renerocksai/calendar-vim
--------------------------------------------------------------------------------
Section 3.4: Picker mappings *telekasten.picker_mappings*
When you are prompted with a telescope picker to select a note or media file,
the following mappings apply:
<CTRL> + <i>
Inserts a link to the selected note / image.
The option `insert_after_inserting` defines if insert mode will be entered
after the link is pasted into your current buffer.
<CTRL> + <y>
Yanks a link to the selected note / image, ready for <p>asting.
The option `close_after_yanking` defines whether the telescope window should
be closed when the link has been yanked.
<RETURN> / <ENTER>
Usually opens the selected note or performs the action defined by the called
function. E.g. `insert_img_link()`'s action is to insert a link to the
selected image.
================================================================================
Section 4: Suggested Mappings *telekasten.mappings*
@@ -633,6 +655,7 @@ However, here are some suggestions:
nnoremap <leader>zg :lua require('telekasten').search_notes()<CR>
nnoremap <leader>zz :lua require('telekasten').follow_link()<CR>
nnoremap <leader>zT :lua require('telekasten').goto_today()<CR>
nnoremap <leader>zW :lua require('telekasten').goto_thisweek()<CR>
nnoremap <leader>zw :lua require('telekasten').find_weekly_notes()<CR>
nnoremap <leader>zn :lua require('telekasten').new_note()<CR>
nnoremap <leader>zN :lua require('telekasten').new_templated_note()<CR>
@@ -645,6 +668,7 @@ However, here are some suggestions:
nnoremap <leader>zF :lua require('telekasten').find_friends()<CR>
nnoremap <leader>zI :lua require('telekasten').insert_img_link({ i=true })<CR>
nnoremap <leader>zp :lua require('telekasten').preview_img()<CR>
nnoremap <leader>zm :lua require('telekasten').browse_media()<CR>
" we could define [[ in **insert mode** to call insert link
" inoremap [[ <ESC>:lua require('telekasten').insert_link()<CR>

View File

@@ -8,7 +8,7 @@ local scan = require("plenary.scandir")
local utils = require("telescope.utils")
local previewers = require("telescope.previewers")
local make_entry = require("telescope.make_entry")
local debug_utils = require('plenary.debug_utils')
local debug_utils = require("plenary.debug_utils")
-- declare locals for the nvim api stuff to avoid more lsp warnings
local vim = vim
@@ -58,6 +58,8 @@ M.Cfg = {
-- calendar mark: where to put mark for marked days: 'left', 'right', 'left-fit'
calendar_mark = "left-fit",
},
close_after_yanking = false,
insert_after_inserting = true,
}
local function file_exists(fname)
@@ -295,12 +297,13 @@ end
local sourced_file = debug_utils.sourced_filepath()
M.base_directory = vim.fn.fnamemodify(sourced_file, ":h:h:h")
local media_files_base_directory = M.base_directory .. "/telescope-media-files.nvim"
local media_files_base_directory = M.base_directory
.. "/telescope-media-files.nvim"
local defaulter = utils.make_default_callable
local media_preview = defaulter(function(opts)
local preview_cmd = media_files_base_directory .. "/scripts/vimg"
if vim.fn.executable(preview_cmd) == 0 then
print('Previewer not found: ' .. preview_cmd)
print("Previewer not found: " .. preview_cmd)
return conf.file_previewer(opts)
end
return previewers.new_termopen_previewer({
@@ -405,6 +408,65 @@ local function find_files_sorted(opts)
picker:find()
end
-- note picker actions
local picker_actions = {}
function picker_actions.paste_link(opts)
return function(prompt_bufnr)
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
local fn = path_to_linkname(selection.value)
local title = "[[" .. fn .. "]]"
vim.api.nvim_put({ title }, "", true, true)
if opts.insert_after_inserting then
vim.api.nvim_feedkeys("A", "m", false)
end
end
end
function picker_actions.yank_link(opts)
return function(prompt_bufnr)
opts = opts or {}
if opts.close_after_yanking then
actions.close(prompt_bufnr)
end
local selection = action_state.get_selected_entry()
local fn = path_to_linkname(selection.value)
local title = "[[" .. fn .. "]]"
vim.fn.setreg('"', title)
print("yanked " .. title)
end
end
function picker_actions.paste_img_link(opts)
return function(prompt_bufnr)
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
local fn = selection.value
fn = fn:gsub(M.Cfg.home .. "/", "")
local imglink = "![](" .. fn .. ")"
vim.api.nvim_put({ imglink }, "", true, true)
if opts.insert_after_inserting then
vim.api.nvim_feedkeys("A", "m", false)
end
end
end
function picker_actions.yank_img_link(opts)
return function(prompt_bufnr)
opts = opts or {}
if opts.close_after_yanking then
actions.close(prompt_bufnr)
end
local selection = action_state.get_selected_entry()
local fn = selection.value
fn = fn:gsub(M.Cfg.home .. "/", "")
local imglink = "![](" .. fn .. ")"
vim.fn.setreg('"', imglink)
print("yanked " .. imglink)
end
end
--
-- FindDailyNotes:
-- ---------------
@@ -413,6 +475,10 @@ end
--
local function FindDailyNotes(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
local today = os.date("%Y-%m-%d")
local fname = M.Cfg.dailies .. "/" .. today .. M.Cfg.extension
@@ -431,6 +497,15 @@ local function FindDailyNotes(opts)
prompt_title = "Find daily note",
cwd = M.Cfg.dailies,
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -442,6 +517,10 @@ end
--
local function FindWeeklyNotes(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
local title = os.date("%Y-W%V")
local fname = M.Cfg.weeklies .. "/" .. title .. M.Cfg.extension
@@ -460,6 +539,15 @@ local function FindWeeklyNotes(opts)
prompt_title = "Find weekly note",
cwd = M.Cfg.weeklies,
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -471,10 +559,14 @@ end
--
local function InsertLink(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
find_files_sorted({
prompt_title = "Insert link to note",
cwd = M.Cfg.home,
attach_mappings = function(prompt_bufnr, _)
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
@@ -484,6 +576,12 @@ local function InsertLink(opts)
vim.api.nvim_feedkeys("A", "m", false)
end
end)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
find_command = M.Cfg.find_command,
@@ -498,6 +596,11 @@ end
--
local function FollowLink(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
vim.cmd("normal yi]")
local title = vim.fn.getreg('"0')
title = title:gsub("^(%[)(.+)(%])$", "%2")
@@ -571,6 +674,15 @@ local function FollowLink(opts)
cwd = M.Cfg.home,
default_text = title,
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -622,6 +734,15 @@ local function FollowLink(opts)
-- link to heading in specific file (a daily file): [[The cool note#^xAcSh-xxr]]
-- link to paragraph globally [[#^xAcSh-xxr]]
finder = live_grepper,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
end
@@ -632,7 +753,13 @@ end
--
-- preview media
--
local function PreviewImg(_)
local function PreviewImg(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
vim.cmd("normal yi)")
local fname = vim.fn.getreg('"0')
@@ -656,10 +783,16 @@ local function PreviewImg(_)
},
preview_type = "media",
attach_mappings = function(prompt_bufnr, _)
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
end)
map("i", "<c-y>", picker_actions.yank_img_link(opts))
map("i", "<c-i>", picker_actions.paste_img_link(opts))
map("n", "<c-y>", picker_actions.yank_img_link(opts))
map("n", "<c-i>", picker_actions.paste_img_link(opts))
map("i", "<c-cr>", picker_actions.paste_img_link(opts))
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
return true
end,
})
@@ -668,13 +801,62 @@ local function PreviewImg(_)
end
end
--
-- BrowseImg:
-- -----------
--
-- preview media
--
local function BrowseImg(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
find_files_sorted({
prompt_title = "Preview image/media",
cwd = M.Cfg.home,
find_command = M.Cfg.find_command,
filter_extensions = {
".png",
".jpg",
".bmp",
".gif",
".pdf",
".mp4",
".webm",
},
preview_type = "media",
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
end)
map("i", "<c-y>", picker_actions.yank_img_link(opts))
map("i", "<c-i>", picker_actions.paste_img_link(opts))
map("n", "<c-y>", picker_actions.yank_img_link(opts))
map("n", "<c-i>", picker_actions.paste_img_link(opts))
map("i", "<c-cr>", picker_actions.paste_img_link(opts))
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
return true
end,
})
end
--
-- FindFriends:
-- -----------
--
-- Find notes also linking to the link under cursor
--
local function FindFriends()
local function FindFriends(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
vim.cmd("normal yi]")
local title = vim.fn.getreg('"0')
title = title:gsub("^(%[)(.+)(%])$", "%2")
@@ -684,6 +866,15 @@ local function FindFriends()
cwd = M.Cfg.home,
default_text = "\\[\\[" .. title .. "\\]\\]",
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -707,6 +898,11 @@ end
--
local function GotoToday(opts)
opts = opts or calenderinfo_today()
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
local word = opts.date or os.date("%Y-%m-%d")
local fname = M.Cfg.dailies .. "/" .. word .. M.Cfg.extension
@@ -731,7 +927,7 @@ local function GotoToday(opts)
cwd = M.Cfg.home,
default_text = word,
find_command = M.Cfg.find_command,
attach_mappings = function(prompt_bufnr, _)
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
@@ -741,6 +937,12 @@ local function GotoToday(opts)
end
vim.cmd("e " .. fname)
end)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
@@ -752,11 +954,26 @@ end
--
-- Select from notes
--
local function FindNotes(_)
local function FindNotes(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
find_files_sorted({
prompt_title = "Find notes by name",
cwd = M.Cfg.home,
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -783,7 +1000,7 @@ local function InsertImgLink(opts)
},
preview_type = "media",
attach_mappings = function(prompt_bufnr, _)
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
@@ -794,6 +1011,12 @@ local function InsertImgLink(opts)
vim.api.nvim_feedkeys("A", "m", false)
end
end)
map("i", "<c-y>", picker_actions.yank_img_link(opts))
map("i", "<c-i>", picker_actions.paste_img_link(opts))
map("n", "<c-y>", picker_actions.yank_img_link(opts))
map("n", "<c-i>", picker_actions.paste_img_link(opts))
map("i", "<c-cr>", picker_actions.paste_img_link(opts))
map("n", "<c-cr>", picker_actions.paste_img_link(opts))
return true
end,
})
@@ -805,13 +1028,28 @@ end
--
-- find the file linked to by the word under the cursor
--
local function SearchNotes(_)
local function SearchNotes(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
builtin.live_grep({
prompt_title = "Search in notes",
cwd = M.Cfg.home,
search_dirs = { M.Cfg.home },
default_text = vim.fn.expand("<cword>"),
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -821,7 +1059,13 @@ end
--
-- Find all notes linking to this one
--
local function ShowBacklinks(_)
local function ShowBacklinks(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
local title = path_to_linkname(vim.fn.expand("%"))
-- or vim.api.nvim_buf_get_name(0)
builtin.live_grep({
@@ -831,6 +1075,15 @@ local function ShowBacklinks(_)
search_dirs = { M.Cfg.home },
default_text = "\\[\\[" .. title .. "\\]\\]",
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
map("i", "<c-cr>", picker_actions.paste_link(opts))
map("n", "<c-cr>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -840,7 +1093,13 @@ end
--
-- Prompts for title and creates note with default template
--
local function on_create(title)
local function on_create(opts, title)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
if title == nil then
return
end
@@ -856,16 +1115,24 @@ local function on_create(title)
cwd = M.Cfg.home,
default_text = title,
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
return true
end,
})
end
local function CreateNote(_)
local function CreateNote(opts)
opts = opts or {}
-- vim.ui.input causes ppl problems - see issue #4
-- vim.ui.input({ prompt = "Title: " }, on_create)
local title = vim.fn.input("Title: ")
title = title:gsub("[" .. M.Cfg.extension .. "]+$", "")
if #title > 0 then
on_create(title)
on_create(opts, title)
end
end
@@ -876,11 +1143,17 @@ end
-- Prompts for title, then pops up telescope for template selection,
-- creates the new note by template and opens it
local function on_create_with_template(title)
local function on_create_with_template(opts, title)
if title == nil then
return
end
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
local fname = M.Cfg.home .. "/" .. title .. M.Cfg.extension
local fexists = file_exists(fname)
if fexists == true then
@@ -893,7 +1166,7 @@ local function on_create_with_template(title)
prompt_title = "Select template...",
cwd = M.Cfg.templates,
find_command = M.Cfg.find_command,
attach_mappings = function(prompt_bufnr, _)
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
-- local template = M.Cfg.templates .. "/" .. action_state.get_selected_entry().value
@@ -902,18 +1175,23 @@ local function on_create_with_template(title)
-- open the new note
vim.cmd("e " .. fname)
end)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
return true
end,
})
end
local function CreateNoteSelectTemplate(_)
local function CreateNoteSelectTemplate(opts)
opts = opts or {}
-- vim.ui.input causes ppl problems - see issue #4
-- vim.ui.input({ prompt = "Title: " }, on_create_with_template)
local title = vim.fn.input("Title: ")
title = title:gsub("[" .. M.Cfg.extension .. "]+$", "")
if #title > 0 then
on_create_with_template(title)
on_create_with_template(opts, title)
end
end
@@ -925,6 +1203,10 @@ end
--
local function GotoThisWeek(opts)
opts = opts or {}
opts.insert_after_inserting = opts.insert_after_inserting
or M.Cfg.insert_after_inserting
opts.close_after_yanking = opts.close_after_yanking
or M.Cfg.close_after_yanking
local title = os.date("%Y-W%V")
local fname = M.Cfg.weeklies .. "/" .. title .. M.Cfg.extension
@@ -944,6 +1226,13 @@ local function GotoThisWeek(opts)
cwd = M.Cfg.weeklies,
default_text = title,
find_command = M.Cfg.find_command,
attach_mappings = function(_, map)
map("i", "<c-y>", picker_actions.yank_link(opts))
map("i", "<c-i>", picker_actions.paste_link(opts))
map("n", "<c-y>", picker_actions.yank_link(opts))
map("n", "<c-i>", picker_actions.paste_link(opts))
return true
end,
})
end
@@ -1161,5 +1450,6 @@ M.show_backlinks = ShowBacklinks
M.find_friends = FindFriends
M.insert_img_link = InsertImgLink
M.preview_img = PreviewImg
M.browse_media = BrowseImg
return M