# HG changeset patch # User zegervdv # Date 1632056234 -7200 # Node ID ae7e377bced805be16e066288baae930aa3d8aa3 # Parent 43262db8ecf62ec0395999039095b14cb3168ebe Add autocmd wrapper for lua diff -r 43262db8ecf6 -r ae7e377bced8 .chezmoitemplates/au.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.chezmoitemplates/au.lua Sun Sep 19 14:57:14 2021 +0200 @@ -0,0 +1,50 @@ +-- +-- Copied from https://gist.github.com/numToStr/1ab83dd2e919de9235f9f774ef8076da +-- +local cmd = vim.api.nvim_command + +local function autocmd(this, event, spec) + local is_table = type(spec) == 'table' + local pattern = is_table and spec[1] or '*' + local action = is_table and spec[2] or spec + if type(action) == 'function' then + action = this.set(action) + end + local e = type(event) == 'table' and table.concat(event, ',') or event + cmd('autocmd ' .. e .. ' ' .. pattern .. ' ' .. action) +end + +local S = { + __au = {}, +} + +local X = setmetatable({}, { + __index = S, + __newindex = autocmd, + __call = autocmd, +}) + +function S.exec(id) + S.__au[id]() +end + +function S.set(fn) + local id = string.format('%p', fn) + S.__au[id] = fn + return string.format('lua require("au").exec("%s")', id) +end + +function S.group(grp, cmds) + cmd('augroup ' .. grp) + cmd 'autocmd!' + if type(cmds) == 'function' then + cmds(X) + else + for _, au in ipairs(cmds) do + autocmd(S, au[1], { au[2], au[3] }) + end + end + cmd 'augroup END' +end + +return X diff -r 43262db8ecf6 -r ae7e377bced8 .chezmoitemplates/config.vim --- a/.chezmoitemplates/config.vim Sun Sep 19 14:47:17 2021 +0200 +++ b/.chezmoitemplates/config.vim Sun Sep 19 14:57:14 2021 +0200 @@ -3,7 +3,7 @@ let s:darwin = has('mac') let s:windows = has('win32') -" Activate built in plugins +" Activate built in plugins if !has('nvim') if has('packages') packadd! matchit @@ -21,9 +21,9 @@ let g:python3_host_prog=expand('$HOME/.config/virtualenvs/python3/bin/python') let g:python_host_prog=expand('$HOME/.config/virtualenvs/python2/bin/python') endif -" +" -" General Settings and options +" General Settings and options augroup cline au! @@ -46,9 +46,9 @@ endif endif -" +" -" Mappings +" Mappings " Set leader to spacebar map @@ -191,9 +191,9 @@ nnoremap f :vert sfind -" +" -" Functions +" Functions " When editing a file, always jump to the last known cursor position. " Don't do it for commit messages, when the position is invalid, or when " inside an event handler (happens when dropping a file on gvim). @@ -219,34 +219,29 @@ au FocusLost * if !&readonly | :wa | endif augroup END -augroup LuaHighlight - autocmd! - autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank() -augroup END - -" Resize splits after window resize +" Resize splits after window resize augroup vim_resize au! au VimResized * exe "normal! \=" augroup END -" +" -" Automatically reload vimrc when saving +" Automatically reload vimrc when saving augroup reload_vim autocmd! autocmd BufWritePost $MYVIMRC nested source $MYVIMRC augroup END -" +" -" Reload diffs +" Reload diffs augroup diff_files au! au BufWritePost * if &diff == 1 | diffupdate | endif augroup END -" +" " Custom folding by Steve Losh -function! MyFoldText() " +function! MyFoldText() " let line = getline(v:foldstart) let nucolwidth = &fdc + &number * &numberwidth @@ -260,11 +255,11 @@ let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) let fillcharcount = windowwidth - len(line) - len(foldedlinecount) return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' -endfunction " +endfunction " set foldtext=MyFoldText() set foldopen+=jump -" Detect Filetype from content if file has no extension +" Detect Filetype from content if file has no extension augroup newFileDetection au! autocmd CursorMovedI * call CheckFileType() @@ -283,9 +278,9 @@ autocmd! newFileDetection endif endfunction -" +" -" Convert hex <-> decimal +" Convert hex <-> decimal command! -nargs=? -range Dec2hex call s:Dec2hex(, , '') function! s:Dec2hex(line1, line2, arg) range if empty(a:arg) @@ -321,9 +316,9 @@ echo (a:arg =~? '^0x') ? a:arg + 0 : ('0x'.a:arg) + 0 endif endfunction -" +" -" Recognize filetype for dup files +" Recognize filetype for dup files autocmd! BufRead *.dup call DupSetSyntax(@%) function! DupSetSyntax(name) @@ -338,11 +333,11 @@ echo "Unknown filetype" endif endfunction -" +" " Create arguments list from files in quickfix list " Allows to Grep for a pattern and apply an argdo command on each of the -" matching files +" matching files command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames() function! QuickfixFilenames() " Building a hash ensures we get each buffer only once @@ -363,7 +358,7 @@ augroup END -" Toggle between opening/closing the quickfix window +" Toggle between opening/closing the quickfix window function! GetBufferList() redir =>buflist silent! ls! @@ -392,10 +387,10 @@ endfunction nnoremap :call ToggleList("Quickfix List", 'c') -" +" -" Make list-like commands more intuitive +" Make list-like commands more intuitive " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 function! CCR() let cmdline = getcmdline() @@ -434,9 +429,9 @@ endif endfunction cnoremap CCR() -" +" -" Text objects +" Text objects function! s:inIndentation() " select all text in current indentation level excluding any empty lines " that precede or follow the current indentationt level; @@ -568,11 +563,11 @@ " "around indentation" (indentation level and any surrounding empty lines) xnoremap ai :call aroundIndentation() onoremap ai :call aroundIndentation() -" -" +" +" -" Filetype specific settings -" Text +" Filetype specific settings +" Text augroup ft_text au! " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb @@ -594,33 +589,33 @@ " Color errors syn match Error "\v^ERROR:.*$" endfunction -" -" Git commit messages +" +" Git commit messages augroup ft_git au! au FileType gitcommit setlocal spell spelllang=en_gb autocmd FileType gitcommit,gitrebase,gitconfig set bufhidden=delete augroup END -" -" Ruby +" +" Ruby augroup ft_ruby au! autocmd BufRead *_spec.rb set filetype=rspec augroup END -" -" Matlab +" +" Matlab augroup ft_matlab au! autocmd FileType matlab setlocal commentstring=\%\ %s augroup END -" -" C +" +" C augroup ft_c au! au FileType c setlocal foldmethod=syntax augroup END -" -" TCL +" +" TCL augroup ft_tcl au! @@ -634,8 +629,8 @@ augroup END " shortcuts iabbrev procargs array set arg [::argument_processing::proces_arguments $args]; -" -" GPG +" +" GPG " Don't save backups of gpg asc files set backupskip+=*.asc @@ -648,8 +643,8 @@ au BufWritePost *.asc u au VimLeave *.asc :!clear augroup END -" -" System Verilog +" +" System Verilog augroup ft_systemverilog au! au FileType systemverilog setlocal suffixesadd+=.sv,.v @@ -665,21 +660,21 @@ \ ')': { 'pattern': '[()]', 'left_margin': 0, 'right_margin': 0, 'stick_to_left': 0} \} endfunction -" -" Make +" +" Make augroup ft_make autocmd! autocmd BufEnter *.make setlocal filetype=make autocmd FileType make setlocal noexpandtab augroup END -" JSON +" JSON augroup ft_json autocmd! autocmd FileType json setlocal equalprg=jq augroup END -" -" -" Python +" +" +" Python augroup f_python autocmd! autocmd FileType python setlocal shiftwidth=4 @@ -689,14 +684,14 @@ augroup END let g:python_highlight_all=1 -" -" +" +" -" Plugin settings -" Gundo tree +" Plugin settings +" Gundo tree nnoremap u :GundoToggle -" -" Projectionist +" +" Projectionist let g:projectionist_heuristics = { \ "*.c": { \ "*.c": { @@ -716,8 +711,8 @@ \ "*.py": { "make": "ipython {}" } \ }, \ } -" -" Grep +" +" Grep let g:grepper = { \ 'tools': ['ag', 'hg'], \ 'highlight': 1, @@ -730,11 +725,11 @@ command! -nargs=* -complete=file Ag Grepper -noprompt -tool ag -grepprg rg --vimgrep -" -" Vinegar/NetRW +" +" Vinegar/NetRW autocmd FileType netrw setl bufhidden=delete -" -" NCM +" +" NCM function! s:check_back_space() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' @@ -763,9 +758,9 @@ imap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' smap vsnip#jumpable(-1) ? '(vsnip-jump-prev)' : '' -" -" -" +" +" +" function! SendOSCClipboard(lines, regtype) call SendViaOSC52(join(a:lines, "\n")) diff -r 43262db8ecf6 -r ae7e377bced8 .chezmoitemplates/init.lua --- a/.chezmoitemplates/init.lua Sun Sep 19 14:47:17 2021 +0200 +++ b/.chezmoitemplates/init.lua Sun Sep 19 14:57:14 2021 +0200 @@ -721,6 +721,12 @@ vim.cmd [[command! LspRename lua LspRename()]] +local au = require 'au' + +au.TextYankPost = function() + vim.highlight.on_yank { timeout = 120 } +end + -- Try importing local config local ok, localconfig = pcall(require, 'localconfig') if ok then diff -r 43262db8ecf6 -r ae7e377bced8 dot_config/nvim/lua/au.lua.tmpl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dot_config/nvim/lua/au.lua.tmpl Sun Sep 19 14:57:14 2021 +0200 @@ -0,0 +1,1 @@ +{{- template "au.lua" -}}