-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautocmds.lua
78 lines (75 loc) · 2.92 KB
/
autocmds.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
vim.api.nvim_create_autocmd("FileType", {
desc = "Enable wrap and spell for text like documents",
group = vim.api.nvim_create_augroup("auto_spell", { clear = true }),
pattern = { "gitcommit", "markdown", "text", "plaintex" },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})
-- Autocommand to set up folding for Neorg files
-- vim.api.nvim_create_autocmd("FileType", {
-- pattern = "norg",
-- callback = function()
-- -- Set folding method to Treesitter
-- vim.opt_local.foldmethod = 'expr'
-- vim.opt_local.foldexpr = 'nvim_treesitter#foldexpr()'
-- vim.opt_local.foldenable = true
-- vim.opt_local.foldlevelstart = 99
--
-- -- Function to fold `@document.meta` section
-- local function fold_meta()
-- local bufnr = vim.fn.bufnr()
-- local meta_start = vim.fn.search('@document.meta', 'nw')
-- if meta_start > 0 then
-- vim.fn.setpos('.', {bufnr, meta_start, 1, 0})
-- -- Use pcall to catch errors and prevent them from propagating
-- pcall(vim.cmd, 'normal! zc')
-- -- vim.cmd('normal! zc')
-- -- Move to the last cursor position
-- vim.cmd('normal! g`"')
-- end
-- end
--
-- -- Call the fold_meta function on BufWinEnter event
-- vim.api.nvim_create_autocmd("BufWinEnter", {
-- buffer = 0, -- Apply to the current buffer
-- callback = fold_meta
-- })
-- end,
-- })
-- Autocommand to set up folding for Org files
vim.api.nvim_create_autocmd("FileType", {
pattern = "org",
callback = function()
-- Set folding method to Treesitter
vim.opt_local.foldmethod = 'expr'
vim.opt_local.foldexpr = 'nvim_treesitter#foldexpr()'
vim.opt_local.foldenable = true
vim.opt_local.foldlevelstart = 99
-- Function to fold `@document.meta` section
local function fold_meta()
local bufnr = vim.fn.bufnr()
local meta_start = vim.fn.search('* Document meta-information', 'nw')
if meta_start > 0 then
local current_pos = vim.fn.getcurpos()
print("found:", current_pos)
vim.fn.setpos('.', {bufnr, meta_start, 1, 0})
-- Use pcall to catch errors and prevent them from propagating
-- pcall(vim.cmd, 'normal! zc')
vim.cmd('normal! zc')
-- Move to the last cursor position
-- vim.cmd('normal! g`"')
end
end
-- Call the fold_meta function on BufWinEnter event
vim.api.nvim_create_autocmd("BufWinEnter", {
buffer = 0, -- Apply to the current buffer
callback = function()
vim.defer_fn(function()
fold_meta()
end, 100)
end,
})
end,
})