Skip to content

Commit

Permalink
autocmd -> lua
Browse files Browse the repository at this point in the history
  • Loading branch information
ediw8311xht committed Nov 21, 2024
1 parent db96451 commit 33d5b4e
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 93 deletions.
7 changes: 2 additions & 5 deletions nvim/init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,15 @@ let g:vimtex_compiler_latexmk = {
"let g:tex_conceal='abdmg'
"----------------------"

source ${HOME}/.config/nvim/autocmd.vim
lua require('functions')
lua require('autocmd')
source ${HOME}/.config/nvim/plugins.vim
source ${HOME}/.config/nvim/functions.vim
lua require('mytreesitter')
lua require('base')

colorscheme pop-punk

"source ${HOME}/.config/nvim/leader_bindings.vim
"source ${HOME}/.config/nvim/etc_bindings.vim

lua require('functions')
lua require('mappings')
lua require('textobjects')

Expand Down
144 changes: 144 additions & 0 deletions nvim/lua/autocmd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@

TemplatePath = "${HOME}/.config/nvim/language_specific/templates/"
MaxLinesCMP = 5000
local va = vim.api;
local vauto = vim.api.nvim_create_autocmd;
local vc = vim.cmd;

---------------------------------
-- Disable CMP For Large Files --
---------------------------------
vauto({"BufEnter", "BufWinEnter"}, {
pattern = {"*"},
callback = function(args)
if va.nvim_buf_line_count(args.buf) > MaxLinesCMP then
require('cmp').setup.buffer( { enabled = false } )
end
end})
vauto({"FocusGained", "CursorHold", "CursorHoldI"}, {
pattern = { "*" },
callback = function()
vc("silent! checktime")
end})
-------------------------
-- BufNewFile, BufRead --
-------------------------
local function bufnew_bufread(glob, comms)
vauto({"BufNewFile", "BufRead"}, {
pattern = glob,
callback = function()
for _,com in ipairs(comms) do
vc(com)
end
end})
end
local function bufnr_add(globcomms)
for glob,comms in pairs(globcomms) do
bufnew_bufread(glob, comms)
end
end
-------------------------
-- Templates ------------
-------------------------
local function template_add(glob, template_path)
vauto({"BufNewFile"}, {
pattern = glob,
callback = function()
local full_path = TemplatePath .. template_path
vc("0read " .. full_path)
vc("silent w")
vc("silent !chmod 700 %")
end})
end
local function template_add_e(exts)
for _,ext in ipairs(exts) do
template_add("*." .. ext, "template." .. ext)
end
end
-------------------------
-- Vars -----------------
-------------------------
local exts = { "sh", "py", "kalker", "exs", "tex", "ex", "html", "cpp" }
local globcomms = {
["${HOME}/.bashrc"] = {
"setfiletype bash",
"source ${HOME}/.config/nvim/language_specific/bashrc.vim"
},
["${HOME}/bashrc_files/*" ] = { "setfiletype bash" },
["*.sh" ] = { "setfiletype bash" },
["${HOME}/.config/polybar/*.ini" ] = { "setfiletype dosini" },
["${HOME}/.config/polybar/*/*.ini" ] = { "setfiletype dosini" },
["*.kalker" ] = { "setfiletype kalker" },
["${HOME}/.config/i3/*" ] = { "setfiletype i3" },
["*.ex,*.exs" ] = { "setfiletype elixir" },
["*.schema" ] = { "setfiletype sql" },
["*.md" ] = { "setfiletype markdown" },

["${HOME}/.config/zathura/*"] = { "set syntax=zathurarc" },

}
template_add_e(exts)
bufnr_add(globcomms)

-------------------------
-- VimLeave -------------
-------------------------
vauto({"VimLeave"}, {
pattern = "*",
callback = function()
ClipBoardExit()
end
})

-------------------------
-- TermOpen -------------
-------------------------
vauto({"TermOpen"}, {
pattern = "*",
callback = function()
vc("setlocal statusline=%{b:term_title}")
end
})

-------------------------
-- FileType Formatting --
-------------------------
vauto({"FileType"}, {
pattern = "*",
callback = function()
vc("setlocal formatoptions-=c formatoptions-=r formatoptions-=o")
end
})

-------------------------
-- Help File ------------
-------------------------

local pattern_a = "'\\l{2,}'"
local pattern_b = "[|]\\zs\\S+\\ze[|]"
local combined = pattern_a .. "|" .. pattern_b
local bindings_help_buffer={
[ "CR" ] = "<C-]>",
[ "BS" ] = "<C-T>",
[ "o" ] = "/\\v(" .. combined .. ")<CR>",
[ "O" ] = "?\\v(" .. combined .. ")<CR>",
[ "<CR>" ] = "<C-]>",
[ "<BS>" ] = "<C-T>",
}

vauto({"FileType"}, {
pattern = "help",
callback = function()
for key,bind in pairs(bindings_help_buffer) do
vim.keymap.set( "n", key, bind, { remap = false, buffer = true } )
end
end
})

-- autocmd FileType help nnoremap <buffer> <CR> <C-]>
-- autocmd FileType help nnoremap <buffer> <BS> <C-T>





70 changes: 0 additions & 70 deletions nvim/lua/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ local marks = require('marks')
local lspstatus = require('lsp-status')
local cmp_capabilities = require('cmp_nvim_lsp').default_capabilities()

-- texlab.setup({})
-- local luasnip_latex_snips = require('luasnip_latex_snippets')
-- local cmp_dictionary = require("cmp_dictionary")
-- luasnip_latex_snips.setup({})


marks.setup({
default_mappings = true,
builtin_marks = {".", "<", ">", "^"},
Expand Down Expand Up @@ -144,18 +138,6 @@ cmp.setup({
{ name = 'dotenv'},
})
})
-- cmp.setup.filetype("tex", {
-- enabled = true,
-- sources = {
-- { name = "nvim_lsp" },
-- { name = "latex_symbols" },
-- },
-- })

-- cmp_dictionary.setup({
-- paths = { "/usr/share/dict/words" },
-- exact_length = 2,
-- })
gitsigns.setup({
signs = {
add = { text = '+' },
Expand All @@ -182,10 +164,6 @@ gitsigns.setup({
ignore_whitespace = true,
virt_text_priority = 100,
},
-- current_line_blame_formatter = '<author>, <author_time:%Y-%m-%d> - <summary>',
-- current_line_blame_formatter_opts = {
-- relative_time = false,
-- },
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
Expand Down Expand Up @@ -283,28 +261,9 @@ lspconfig.pyright.setup({
on_attach = lsp_status.on_attach,
capabilities = cmp_capabilities,
})
-- lspconfig.clangd.setup({
-- cmd = {'clangd', '--background-index', '--compile-commands-dir', 'D:/systemc/excersies/build'},
-- init_options = {
-- clangdFileStatus = true,
-- clangdSemanticHighlighting = true
-- },
-- filetypes = {'c', 'cpp', 'cxx', 'cc'},
-- root_dir = function() vim.fn.getcwd() end,
-- settings = {
-- ['clangd'] = {
-- ['compilationDatabasePath'] = 'build',
-- ['fallbackFlags'] = {'-std=c++17'}
-- }
-- }
-- })
lspconfig.ccls.setup({
filetypes = {"c", "cpp"},
})
-- lspconfig.texlab.setup({
-- capabilities = cmp_capabilities,
-- })
-- lspconfig.sourcekit.setup({})
-- lspconfig.elixirls.setup{
-- credo = { enable = false },
-- cmd = { "/usr/lib/elixir-ls/language_server.sh" },
Expand All @@ -322,32 +281,3 @@ lspconfig.ccls.setup({
-- };
-- }

-- cmp.setup.cmdline({ '/', '?' }, {
-- mapping = cmp.mapping.preset.cmdline(),
-- sources = {
-- { name = 'buffer' }
-- }
-- })
-- cmp.setup.cmdline(':', {
-- mapping = cmp.mapping.preset.cmdline(),
-- sources = cmp.config.sources({
-- { name = 'path' }
-- }, {
-- { name = 'cmdline' }
-- }),
-- matching = { disallow_symbol_nonprefix_matching = false }
-- })
-- local hologram = require('hologram')
-- local lsp_lines = require("lsp_lines")


-- Disable virtual_text since it's redundant due to lsp_lines.
-- vim.diagnostic.config({
-- virtual_text = false,
-- })
-- lsp_lines.setup({})

-- require('hologram').setup{
-- auto_display = true -- WIP automatic markdown image display, may be prone to breaking
-- }

23 changes: 7 additions & 16 deletions nvim/lua/functions.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
-- local nvim_rocks = require('nvim_rocks')
-- nvim_rocks.install('fun')

function DisableSlow()
require('cmp').setup.buffer( { enabled = false } )
local va = vim.api;
local vauto = vim.api.nvim_create_autocmd;
local vc = vim.cmd;
function ClipBoardExit()
if va.executable("xclip") then
va.system('xclip -selection clipboard -i -r <<< ', va.getreg('a'))
end
end

function CheckSize(args)
if vim.api.nvim_buf_line_count(args.buf) > 5000 then
DisableSlow()
end
end


vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*"},
callback = CheckSize
})
5 changes: 3 additions & 2 deletions xorg/SetKeys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
# vi: ft=bash

toggle_r_rate() {
local status='On'
if [[ "${1,,}" != 'on' ]] &&
{ xset q | grep -q -Pi 'auto[ ]*repeat[:][ ]*on'; }
then xset r off
then xset r off; status='Off'
else xset r rate 300 50
fi
notify-send -t 3000 "Keyboard Repeat Toggled"
notify-send -t 3000 "Keyboard Repeat Toggled" "${status}"
}

main() {
Expand Down

0 comments on commit 33d5b4e

Please sign in to comment.