updated neorg

This commit is contained in:
Solomon Laing 2023-01-16 12:17:12 +10:30
parent 5967684e2b
commit 46d5ac6d62
8 changed files with 119 additions and 26 deletions

View File

@ -33,7 +33,7 @@ return {
},
config = function(plugin, opts)
-- setup formatting and keymaps
require("lazyvim.functions").on_attach(function(client, buffer)
require("lazyvim.utils").on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.format").on_attach(client, buffer)
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
require("lazyvim.plugins.lsp.misc").on_attach(client, buffer)

View File

@ -1,7 +1,7 @@
return {
"nvim-neorg/neorg",
cmd = "Neorg",
event = "BufEnter *.norg",
-- event = "BufEnter *.norg",
event = "VeryLazy",
dependencies = "nvim-treesitter",
build = ":Neorg sync-parsers",
opts = {
@ -29,8 +29,12 @@ return {
},
},
-- keys = {
-- { "<leader>nn", "<cmd>Neorg<cr>", desc = "Open Neorg" },
-- { "<leader>nj", "<cmd>Neorg journal<cr>", desc = "Journal" },
-- { "<leader>nw", "<cmd>Neorg workspace<cr>", desc = "Workspace" },
-- {
-- "<leader>nw",
-- function()
-- require("lazyvim.utils.neorg").workspace_switcher()
-- end,
-- desc = "Workspace",
-- },
-- },
}

View File

@ -1,4 +1,4 @@
local util = require("lazyvim.functions")
local util = require("lazyvim.utils")
return {
{

View File

@ -220,7 +220,7 @@ return {
"SmiteshP/nvim-navic",
init = function()
vim.g.navic_silence = true
require("lazyvim.functions").on_attach(function(client, buffer)
require("lazyvim.utils").on_attach(function(client, buffer)
if client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, buffer)
end

View File

@ -40,7 +40,7 @@ return {
},
config = function(_, opts)
local whichkey = require("which-key")
local Util = require("lazyvim.functions")
local utils = require("lazyvim.utils")
whichkey.setup(opts)
@ -79,7 +79,12 @@ return {
name = "+neorg",
n = { "<cmd>Neorg<cr>", "Open Neorg" },
j = { "<cmd>Neorg journal<cr>", "Open Neorg Journal" },
w = { "<cmd>Neorg workspace<cr>", "Open Neorg Workspace" },
w = {
function()
require("lazyvim.utils.neorg").workspace_switcher()
end,
"Workspace Switcher",
},
},
f = {
@ -87,13 +92,13 @@ return {
n = { "<cmd>enew<cr>", "New File" },
t = {
function()
Util.float_term(nil, { cwd = Util.get_root() })
utils.float_term(nil, { cwd = utils.get_root() })
end,
"Terminal (rood dir)",
},
T = {
function()
Util.float_term()
utils.float_term()
end,
"Terminal (cwd)",
},
@ -136,33 +141,33 @@ return {
},
s = {
function()
Util.toggle("spell")
utils.toggle("spell")
end,
"Toggle spelling",
},
w = {
function()
Util.toggle("wrap")
utils.toggle("wrap")
end,
"Toggle word wrap",
},
n = {
function()
Util.toggle("relativenumber", true)
Util.toggle("number")
utils.toggle("relativenumber", true)
utils.toggle("number")
end,
"Toggle line numbers",
},
d = {
function()
Util.toggle_diagnostics()
utils.toggle_diagnostics()
end,
"Toggle Diagnostics",
},
c = {
function()
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3
Util.toggle("conceallevel", false, { 0, conceallevel })
utils.toggle("conceallevel", false, { 0, conceallevel })
end,
"Toggle conceal",
},
@ -172,13 +177,13 @@ return {
name = "+git",
g = {
function()
Util.float_term({ "lazygit" })
utils.float_term({ "lazygit" })
end,
"Lazygit (cwd)",
},
G = {
function()
Util.float_term({ "lazygit" }, { cwd = Util.get_root() })
utils.float_term({ "lazygit" }, { cwd = utils.get_root() })
end,
"Lazygit (root dir)",
},

View File

@ -0,0 +1,84 @@
local themes = require("telescope.themes")
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local actions = require("telescope.actions")
local action_set = require("telescope.actions.set")
local state = require("telescope.actions.state")
local conf = require("telescope.config").values
local previewers = require("telescope.previewers")
local neorg_loaded, _ = pcall(require, "neorg.modules")
assert(neorg_loaded, "Neorg is not loaded - please make sure to load Neorg first")
local ns = vim.api.nvim_create_namespace("neorg-tele-workspace-preview")
local workspaces
local M = {}
function M.workspace_switcher(options)
if not workspaces then
workspaces = {}
local workspaces_raw = neorg.modules.get_module("core.norg.dirman").get_workspaces()
for name, path in pairs(workspaces_raw) do
table.insert(workspaces, { name = name, path = path })
end
end
local opts = options
or themes.get_dropdown({
border = true,
layout_config = {
prompt_position = "top",
},
})
pickers
.new(opts, {
prompt_title = "Switch Workspace",
preview_title = "Details",
results_title = "Workspaces",
finder = finders.new_table({
results = workspaces,
entry_maker = function(ws)
return {
value = ws,
display = ws.name,
ordinal = ws.name,
}
end,
}),
sorter = conf.generic_sorter(opts),
previewer = previewers.new_buffer_previewer({
define_preview = function(self, entry, status)
local workspace = entry.value
local lines = {}
table.insert(lines, "Path:")
table.insert(lines, workspace.path)
table.insert(lines, "Files:")
local files = neorg.modules.get_module("core.norg.dirman").get_norg_files(workspace.name)
for _, file in ipairs(files) do
table.insert(lines, file)
end
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, true, lines)
vim.api.nvim_buf_add_highlight(self.state.bufnr, ns, "Special", 0, 0, -1)
vim.api.nvim_buf_add_highlight(self.state.bufnr, ns, "Special", 2, 0, -1)
end,
}),
attach_mappings = function(prompt_bufnr)
action_set.select:replace(function()
local entry = state.get_selected_entry()
actions.close(prompt_bufnr)
if entry then
neorg.modules.get_module("core.norg.dirman").open_workspace(entry.value.name)
end
end)
return true
end,
})
:find()
end
return M

View File

@ -4,14 +4,14 @@ local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local conf = require("telescope.config").values
local prompt = function(opts, prompt, options, callback)
opts = opts or {}
local prompt = function(opts, prompt, inputs, callback)
opts = opts or require("telescope.themes").get_dropdown({})
pickers
.new(opts, {
prompt_title = prompt,
finder = finders.new_table({
results = options,
entry_marker = function(entry)
results = inputs,
entry_maker = function(entry)
return {
value = entry,
display = entry[1],
@ -24,7 +24,7 @@ local prompt = function(opts, prompt, options, callback)
actions.select_default:replace(function()
actions.close(promnt_bufnr)
local selection = action_state.get_selected_entry()
vim.notify(selection[1])
vim.notify(selection)
end)
return true
end,
@ -32,7 +32,7 @@ local prompt = function(opts, prompt, options, callback)
:find()
end
prompt(require("telescope.themes").get_dropdown({}), "test", {
prompt(nil, "test", {
{ "one", "1" },
{ "two", "2" },
}, nil)