mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 14:14:24 -05:00
refactor to satisfy lsp
This commit is contained in:
@@ -1,15 +1,14 @@
|
|||||||
local pickers = require "telescope.pickers"
|
|
||||||
local finders = require "telescope.finders"
|
|
||||||
local sorters = require "telescope.sorters"
|
|
||||||
local previewers = require "telescope.previewers"
|
|
||||||
local conf = require("telescope.config").values
|
|
||||||
local builtin = require "telescope.builtin"
|
local builtin = require "telescope.builtin"
|
||||||
|
|
||||||
local actions = require("telescope.actions")
|
local actions = require("telescope.actions")
|
||||||
local action_state = require "telescope.actions.state"
|
local action_state = require "telescope.actions.state"
|
||||||
|
|
||||||
|
-- declare locals for the nvim api stuff to avoid more lsp warnings
|
||||||
|
local vim = vim
|
||||||
|
local api = api
|
||||||
|
|
||||||
-- DEFAULT CONFIG
|
-- DEFAULT CONFIG
|
||||||
zkcfg = {
|
ZkCfg = {
|
||||||
home = vim.fn.expand("~/zettelkasten"),
|
home = vim.fn.expand("~/zettelkasten"),
|
||||||
dailies = vim.fn.expand("~/zettelkasten/daily"),
|
dailies = vim.fn.expand("~/zettelkasten/daily"),
|
||||||
extension = ".md",
|
extension = ".md",
|
||||||
@@ -30,12 +29,12 @@ local downloader2cmd = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- install_daily_finder
|
-- InstallDailyFinder
|
||||||
-- downloads the daily finder scripts to the configured `my_bin` directory
|
-- downloads the daily finder scripts to the configured `my_bin` directory
|
||||||
-- and makes it executable
|
-- and makes it executable
|
||||||
install_daily_finder = function()
|
InstallDailyFinder = function()
|
||||||
local destpath = zkcfg.my_bin .. '/' .. zkcfg.daily_finder
|
local destpath = ZkCfg.my_bin .. '/' .. ZkCfg.daily_finder
|
||||||
local cmd = downloader2cmd[zkcfg.downloader]
|
local cmd = downloader2cmd[ZkCfg.downloader]
|
||||||
vim.api.nvim_command('!'.. cmd .. ' ' .. destpath .. ' https://raw.githubusercontent.com/renerocksai/telekasten.nvim/main/ext_commands/daily_finder.sh')
|
vim.api.nvim_command('!'.. cmd .. ' ' .. destpath .. ' https://raw.githubusercontent.com/renerocksai/telekasten.nvim/main/ext_commands/daily_finder.sh')
|
||||||
vim.api.nvim_command('!chmod +x ' .. destpath)
|
vim.api.nvim_command('!chmod +x ' .. destpath)
|
||||||
end
|
end
|
||||||
@@ -43,7 +42,7 @@ end
|
|||||||
local path_to_linkname = function(p)
|
local path_to_linkname = function(p)
|
||||||
local fn = vim.split(p, "/")
|
local fn = vim.split(p, "/")
|
||||||
fn = fn[#fn]
|
fn = fn[#fn]
|
||||||
fn = vim.split(fn, zkcfg.extension)
|
fn = vim.split(fn, ZkCfg.extension)
|
||||||
fn = fn[1]
|
fn = fn[1]
|
||||||
return fn
|
return fn
|
||||||
end
|
end
|
||||||
@@ -58,22 +57,23 @@ end
|
|||||||
|
|
||||||
|
|
||||||
local check_local_finder = function()
|
local check_local_finder = function()
|
||||||
local ret = vim.fn.system(zkcfg.daily_finder .. ' check')
|
local ret = vim.fn.system(ZkCfg.daily_finder .. ' check')
|
||||||
return ret == "OK\n"
|
return ret == "OK\n"
|
||||||
-- return vim.fn.executable(zkcfg.daily_finder) == 1
|
-- return vim.fn.executable(ZkCfg.daily_finder) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- find_daily_notes:
|
-- FindDailyNotes:
|
||||||
--
|
--
|
||||||
-- Select from daily notes
|
-- Select from daily notes
|
||||||
--
|
--
|
||||||
find_daily_notes = function(opts)
|
FindDailyNotes = function(opts)
|
||||||
|
opts = {} or opts
|
||||||
if (check_local_finder() == true) then
|
if (check_local_finder() == true) then
|
||||||
builtin.find_files({
|
builtin.find_files({
|
||||||
prompt_title = "Find daily note",
|
prompt_title = "Find daily note",
|
||||||
cwd = zkcfg.dailies,
|
cwd = ZkCfg.dailies,
|
||||||
find_command = { zkcfg.daily_finder },
|
find_command = { ZkCfg.daily_finder },
|
||||||
entry_maker = zk_entry_maker,
|
entry_maker = zk_entry_maker,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@@ -81,15 +81,17 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- insert_link:
|
-- InsertLink:
|
||||||
--
|
--
|
||||||
-- Select from all notes and put a link in the current buffer
|
-- Select from all notes and put a link in the current buffer
|
||||||
--
|
--
|
||||||
insert_link = function(opts)
|
InsertLink = function(opts)
|
||||||
|
opts = {} or opts
|
||||||
builtin.find_files({
|
builtin.find_files({
|
||||||
prompt_title = "Insert link to note",
|
prompt_title = "Insert link to note",
|
||||||
cwd = zkcfg.home,
|
cwd = ZkCfg.home,
|
||||||
attach_mappings = function(prompt_bufnr, map)
|
attach_mappings = function(prompt_bufnr, map)
|
||||||
|
map = map -- get rid of lsp error
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
@@ -98,69 +100,94 @@ insert_link = function(opts)
|
|||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
find_command = { zkcfg.daily_finder },
|
find_command = { ZkCfg.daily_finder },
|
||||||
entry_maker = zk_entry_maker,
|
entry_maker = zk_entry_maker,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- follow_link:
|
-- FollowLink:
|
||||||
--
|
--
|
||||||
-- find the file linked to by the word under the cursor
|
-- find the file linked to by the word under the cursor
|
||||||
--
|
--
|
||||||
follow_link = function(opts)
|
FollowLink = function(opts)
|
||||||
|
opts = {} or opts
|
||||||
vim.cmd('normal yi]')
|
vim.cmd('normal yi]')
|
||||||
local word = vim.fn.getreg('"0')
|
local word = vim.fn.getreg('"0')
|
||||||
builtin.find_files({
|
builtin.find_files({
|
||||||
prompt_title = "Follow link to note...",
|
prompt_title = "Follow link to note...",
|
||||||
cwd = zkcfg.home,
|
cwd = ZkCfg.home,
|
||||||
default_text = word,
|
default_text = word,
|
||||||
find_command = { zkcfg.daily_finder },
|
find_command = { ZkCfg.daily_finder },
|
||||||
entry_maker = zk_entry_maker,
|
entry_maker = zk_entry_maker,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
goto_today = function(opts)
|
GotoToday = function(opts)
|
||||||
|
print('local version')
|
||||||
|
opts = {} or opts
|
||||||
local word = os.date("%Y-%m-%d")
|
local word = os.date("%Y-%m-%d")
|
||||||
builtin.find_files({
|
builtin.find_files({
|
||||||
prompt_title = "Follow link to note...",
|
prompt_title = "Follow link to note...",
|
||||||
cwd = zkcfg.home,
|
cwd = ZkCfg.home,
|
||||||
default_text = word,
|
default_text = word,
|
||||||
find_command = { zkcfg.daily_finder },
|
find_command = { ZkCfg.daily_finder },
|
||||||
entry_maker = zk_entry_maker,
|
entry_maker = zk_entry_maker,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- find_notes:
|
-- FindNotes:
|
||||||
--
|
--
|
||||||
-- Select from notes
|
-- Select from notes
|
||||||
--
|
--
|
||||||
find_notes = function(opts)
|
FindNotes = function(opts)
|
||||||
|
opts = {} or opts
|
||||||
builtin.find_files({
|
builtin.find_files({
|
||||||
prompt_title = "Find notes by name",
|
prompt_title = "Find notes by name",
|
||||||
cwd = zkcfg.home,
|
cwd = ZkCfg.home,
|
||||||
find_command = { zkcfg.daily_finder },
|
find_command = { ZkCfg.daily_finder },
|
||||||
entry_maker = zk_entry_maker,
|
entry_maker = zk_entry_maker,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- search_notes:
|
-- SearchNotes:
|
||||||
--
|
--
|
||||||
-- find the file linked to by the word under the cursor
|
-- find the file linked to by the word under the cursor
|
||||||
--
|
--
|
||||||
search_notes = function(opts)
|
SearchNotes = function(opts)
|
||||||
|
opts = {} or opts
|
||||||
builtin.live_grep({
|
builtin.live_grep({
|
||||||
prompt_title = "Search in notes",
|
prompt_title = "Search in notes",
|
||||||
cwd = zkcfg.home,
|
cwd = ZkCfg.home,
|
||||||
search_dirs = { zkcfg.home },
|
search_dirs = { ZkCfg.home },
|
||||||
default_text = vim.fn.expand("<cword>"),
|
default_text = vim.fn.expand("<cword>"),
|
||||||
find_command = { zkcfg.daily_finder },
|
find_command = { ZkCfg.daily_finder },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function file_exists(name)
|
||||||
|
local f=io.open(name,"r")
|
||||||
|
if f~=nil then io.close(f) return true else return false end
|
||||||
|
end
|
||||||
|
|
||||||
|
local create_note_by_tilte = function (title)
|
||||||
|
-- set the filename based on the current date
|
||||||
|
-- local filepath = vim.g['wiki_root']..'journal/'..os.date('%Y-%m-%d')..'.md'
|
||||||
|
local filepath = ZkCfg.home
|
||||||
|
|
||||||
|
-- if the file doesn't exist
|
||||||
|
-- then created file and write date to the top of the file
|
||||||
|
if not file_exists(filepath) then
|
||||||
|
local file = io.open(filepath, 'a')
|
||||||
|
io.output(file)
|
||||||
|
io.write(os.date("# %a, %d %B '%y"))
|
||||||
|
io.close(file)
|
||||||
|
end
|
||||||
|
api.nvim_command('edit '..filepath)
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
-- interesting snippet:
|
-- interesting snippet:
|
||||||
@@ -201,22 +228,23 @@ end
|
|||||||
-- - daily_finder: executable that finds daily notes and sorts them by date
|
-- - daily_finder: executable that finds daily notes and sorts them by date
|
||||||
-- as long as we have no lua equivalent, this will be necessary
|
-- as long as we have no lua equivalent, this will be necessary
|
||||||
--
|
--
|
||||||
setup = function(cfg)
|
Setup = function(cfg)
|
||||||
cfg = cfg or {}
|
cfg = cfg or {}
|
||||||
for k, v in pairs(cfg) do
|
for k, v in pairs(cfg) do
|
||||||
zkcfg[k] = v
|
ZkCfg[k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local M = {
|
local M = {
|
||||||
zkcfg = zkcfg,
|
ZkCfg = ZkCfg,
|
||||||
find_notes = find_notes,
|
find_notes = FindNotes,
|
||||||
find_daily_notes = find_daily_notes,
|
find_daily_notes = FindDailyNotes,
|
||||||
search_notes = search_notes,
|
search_notes = SearchNotes,
|
||||||
insert_link = insert_link,
|
insert_link = InsertLink,
|
||||||
follow_link = follow_link,
|
follow_link = FollowLink,
|
||||||
setup = setup,
|
setup = Setup,
|
||||||
install_daily_finder = install_daily_finder,
|
install_daily_finder = InstallDailyFinder,
|
||||||
goto_today = goto_today,
|
goto_today = GotoToday,
|
||||||
}
|
}
|
||||||
|
print('local version')
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user