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) config = function(plugin, opts)
-- setup formatting and keymaps -- 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.format").on_attach(client, buffer)
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer) require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
require("lazyvim.plugins.lsp.misc").on_attach(client, buffer) require("lazyvim.plugins.lsp.misc").on_attach(client, buffer)

View File

@ -1,7 +1,7 @@
return { return {
"nvim-neorg/neorg", "nvim-neorg/neorg",
cmd = "Neorg", -- event = "BufEnter *.norg",
event = "BufEnter *.norg", event = "VeryLazy",
dependencies = "nvim-treesitter", dependencies = "nvim-treesitter",
build = ":Neorg sync-parsers", build = ":Neorg sync-parsers",
opts = { opts = {
@ -29,8 +29,12 @@ return {
}, },
}, },
-- keys = { -- keys = {
-- { "<leader>nn", "<cmd>Neorg<cr>", desc = "Open Neorg" }, -- {
-- { "<leader>nj", "<cmd>Neorg journal<cr>", desc = "Journal" }, -- "<leader>nw",
-- { "<leader>nw", "<cmd>Neorg workspace<cr>", desc = "Workspace" }, -- 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 { return {
{ {

View File

@ -220,7 +220,7 @@ return {
"SmiteshP/nvim-navic", "SmiteshP/nvim-navic",
init = function() init = function()
vim.g.navic_silence = true 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 if client.server_capabilities.documentSymbolProvider then
require("nvim-navic").attach(client, buffer) require("nvim-navic").attach(client, buffer)
end end

View File

@ -40,7 +40,7 @@ return {
}, },
config = function(_, opts) config = function(_, opts)
local whichkey = require("which-key") local whichkey = require("which-key")
local Util = require("lazyvim.functions") local utils = require("lazyvim.utils")
whichkey.setup(opts) whichkey.setup(opts)
@ -79,7 +79,12 @@ return {
name = "+neorg", name = "+neorg",
n = { "<cmd>Neorg<cr>", "Open Neorg" }, n = { "<cmd>Neorg<cr>", "Open Neorg" },
j = { "<cmd>Neorg journal<cr>", "Open Neorg Journal" }, 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 = { f = {
@ -87,13 +92,13 @@ return {
n = { "<cmd>enew<cr>", "New File" }, n = { "<cmd>enew<cr>", "New File" },
t = { t = {
function() function()
Util.float_term(nil, { cwd = Util.get_root() }) utils.float_term(nil, { cwd = utils.get_root() })
end, end,
"Terminal (rood dir)", "Terminal (rood dir)",
}, },
T = { T = {
function() function()
Util.float_term() utils.float_term()
end, end,
"Terminal (cwd)", "Terminal (cwd)",
}, },
@ -136,33 +141,33 @@ return {
}, },
s = { s = {
function() function()
Util.toggle("spell") utils.toggle("spell")
end, end,
"Toggle spelling", "Toggle spelling",
}, },
w = { w = {
function() function()
Util.toggle("wrap") utils.toggle("wrap")
end, end,
"Toggle word wrap", "Toggle word wrap",
}, },
n = { n = {
function() function()
Util.toggle("relativenumber", true) utils.toggle("relativenumber", true)
Util.toggle("number") utils.toggle("number")
end, end,
"Toggle line numbers", "Toggle line numbers",
}, },
d = { d = {
function() function()
Util.toggle_diagnostics() utils.toggle_diagnostics()
end, end,
"Toggle Diagnostics", "Toggle Diagnostics",
}, },
c = { c = {
function() function()
local conceallevel = vim.o.conceallevel > 0 and vim.o.conceallevel or 3 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, end,
"Toggle conceal", "Toggle conceal",
}, },
@ -172,13 +177,13 @@ return {
name = "+git", name = "+git",
g = { g = {
function() function()
Util.float_term({ "lazygit" }) utils.float_term({ "lazygit" })
end, end,
"Lazygit (cwd)", "Lazygit (cwd)",
}, },
G = { G = {
function() function()
Util.float_term({ "lazygit" }, { cwd = Util.get_root() }) utils.float_term({ "lazygit" }, { cwd = utils.get_root() })
end, end,
"Lazygit (root dir)", "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 action_state = require("telescope.actions.state")
local conf = require("telescope.config").values local conf = require("telescope.config").values
local prompt = function(opts, prompt, options, callback) local prompt = function(opts, prompt, inputs, callback)
opts = opts or {} opts = opts or require("telescope.themes").get_dropdown({})
pickers pickers
.new(opts, { .new(opts, {
prompt_title = prompt, prompt_title = prompt,
finder = finders.new_table({ finder = finders.new_table({
results = options, results = inputs,
entry_marker = function(entry) entry_maker = function(entry)
return { return {
value = entry, value = entry,
display = entry[1], display = entry[1],
@ -24,7 +24,7 @@ local prompt = function(opts, prompt, options, callback)
actions.select_default:replace(function() actions.select_default:replace(function()
actions.close(promnt_bufnr) actions.close(promnt_bufnr)
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
vim.notify(selection[1]) vim.notify(selection)
end) end)
return true return true
end, end,
@ -32,7 +32,7 @@ local prompt = function(opts, prompt, options, callback)
:find() :find()
end end
prompt(require("telescope.themes").get_dropdown({}), "test", { prompt(nil, "test", {
{ "one", "1" }, { "one", "1" },
{ "two", "2" }, { "two", "2" },
}, nil) }, nil)