Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
82 lines (77 loc) · 1.94 KB
/
Copy pathinit.lua
File metadata and controls
82 lines (77 loc) · 1.94 KB
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
79
80
81
82
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
require("vimops")
require("lazy").setup({
spec = {
-- { "folke/tokyonight.nvim", config = function() vim.cmd.colorscheme "tokyonight" end },
{ import = "plugins" },
},
change_detection = {
-- automatically check for config file changes and reload the ui
enabled = false,
notify = false, -- get a notification when changes are found
},
})
require("keymaps")
require("persian").setup()
local autosave = vim.api.nvim_create_augroup("AutoSave", { clear = true })
local timers = {}
local function save(buf)
if not vim.api.nvim_buf_is_valid(buf) or not vim.bo[buf].modified then
return
end
if vim.bo[buf].buftype ~= "" or not vim.bo[buf].modifiable then
return
end
if vim.api.nvim_buf_get_name(buf) == "" then
return
end
vim.api.nvim_buf_call(buf, function()
vim.b.skip_format_on_save = true
vim.cmd("silent! write")
vim.b.skip_format_on_save = nil
end)
end
vim.api.nvim_create_autocmd({ "InsertLeave", "TextChanged", "FocusLost", "BufLeave" }, {
group = autosave,
pattern = "*",
callback = function(args)
local buf = args.buf
if timers[buf] then
timers[buf]:stop()
else
timers[buf] = vim.uv.new_timer()
end
timers[buf]:start(
1500,
0,
vim.schedule_wrap(function()
save(buf)
end)
)
end,
})
vim.api.nvim_create_autocmd("BufDelete", {
group = autosave,
callback = function(args)
local t = timers[args.buf]
if t then
t:stop()
t:close()
timers[args.buf] = nil
end
end,
})