From 52ce0634fad9c94f0c041c151cf691c17f463dfb Mon Sep 17 00:00:00 2001 From: Christian Nieves Date: Tue, 13 Jun 2023 10:45:27 -0500 Subject: [PATCH] move google stuff --- vim/.vim/lua/config/google.lua | 134 +++++++++++++++++++++++++++++ vim/.vim/lua/plugins/google.lua | 148 ++------------------------------ vim/.vimrc | 2 + 3 files changed, 144 insertions(+), 140 deletions(-) create mode 100644 vim/.vim/lua/config/google.lua diff --git a/vim/.vim/lua/config/google.lua b/vim/.vim/lua/config/google.lua new file mode 100644 index 0000000..87bbffc --- /dev/null +++ b/vim/.vim/lua/config/google.lua @@ -0,0 +1,134 @@ +vim.cmd([[ +let g:VCSCommandDisableMappings = 1 + +let g:signify_skip_filename_pattern = ['\.pipertmp.*'] + +function s:blazeExec(cmd, targets) + if len(a:targets) == 0 + exe VimuxRunCommand("build_target.py " . expand('%:p') . " " . a:cmd) + else + exe VimuxRunCommand(a:cmd . " " . join(a:targets, ' ')) + endif +endfunction + +function BlazeRun() abort + call blazeExec("blaze run", blaze#GetTargets()) +endfunction + +function BlazeBuild() abort + call blazeExec("blaze build", blaze#GetTargets()) +endfunction + +function BlazeTest() abort + call blazeExec("blaze test", blaze#GetTargets()) +endfunction + +function BlazeTestDebug() abort + call blazeExec("blaze test --java_debug", blaze#GetTargets()) +endfunction + +function BuildCleanerFile() abort + exe VimuxRunCommand("build_cleaner " . expand('%')) +endfunction + +function UnusedDeps() abort + exe VimuxRunCommand("unused_deps --nouse_build_api --blaze_options='--config=gmscore_tap' " . join(blaze#GetTargets(), ' ')) +endfunction + +function BuildCleanerTarget() abort + exe VimuxRunCommand("build_cleaner " . join(blaze#GetTargets(), ' ')) +endfunction + +nnoremap br :call BlazeRun() +nnoremap bb :call BlazeBuild() +nnoremap bt :call BlazeTest() +nnoremap btd :call BlazeTestDebug() +nnoremap bc :call BuildCleanerTarget() +nnoremap bcf :call BuildCleanerFile() +nnoremap ud :call UnusedDeps() + +let g:asyncrun_open = 1 + +function! s:AsyncBlaze(cmd, targets) abort + "open cwindow manually and immediately when blaze starts. + "simulate the same behavior from google-emacs blaze plugin. + let l:aro = g:asyncrun_open + let g:asyncrun_open = 0 + let l:target = ':'.expand('%:r') + call setqflist([]) | copen 15 + " don't use !, so we scrolling the output. + call asyncrun#run("", {"rows": 15}, a:cmd . ' ' . join(a:targets, ' ')) + let g:asyncrun_open = l:aro +endfunction + +function AsyncBlazeBuild() abort + call AsyncBlaze("blaze build", blaze#GetTargets()) +endfunction + +function AsyncBlazeTest() abort + call AsyncBlaze("blaze test", blaze#GetTargets()) +endfunction + +augroup autoformat_settings + autocmd FileType borg,gcl,patchpanel AutoFormatBuffer gclfmt + autocmd FileType bzl AutoFormatBuffer buildifier + autocmd FileType c,cpp,javascript,typescript AutoFormatBuffer clang-format + autocmd FileType dart AutoFormatBuffer dartfmt + autocmd FileType go AutoFormatBuffer gofmt + autocmd FileType java AutoFormatBuffer google-java-format + autocmd FileType jslayout AutoFormatBuffer jslfmt + autocmd FileType markdown AutoFormatBuffer mdformat + autocmd FileType ncl AutoFormatBuffer nclfmt + autocmd FileType python AutoFormatBuffer pyformat + autocmd FileType soy AutoFormatBuffer soyfmt + autocmd FileType textpb AutoFormatBuffer text-proto-format + autocmd FileType proto AutoFormatBuffer protofmt + autocmd FileType sql AutoFormatBuffer format_sql + autocmd FileType kotlin AutoFormatBuffer ktfmt + " autocmd FileType html,css,json AutoFormatBuffer js-beautify +augroup END + +function! CitCWorkspace() + let l:workspace = substitute(getcwd(), '/google/src/cloud/[^/]\+/\([^/]\+\)/.*', '\1', 'g') + return l:workspace +endfunction + +function! G4Blame(...) + " Grab the filename from the argument, use expand() to expand '%'. + if a:0 > 0 + let file = expand(a:1) + else + let file = expand('%') + endif + " Lock scrolling in right pane + setl scb + " Create left pane + vnew + " It's 37 columns wide + vert res 37 + " Get the output, split it on newline and keep empty lines, skip the first 2 + " lines because they're headers we don't need, and put it in starting on line + " 1 of the left pane + call setline(1, split(system('g4 blame ' . file), '\n', 1)[2:]) + " Lock scrolling in left pane, turn off word wrap, set the buffer as + " not-modified, remove any listchars highlighting (common in google code), set + " it readonly (to make modifications slightly more annoying). + setl scb nowrap nomod nolist ro + " Move back to the right pane (not sure if there's a better way to do this?) + exe "normal \\" + " if a file was specified, open it + if a:0 > 0 + execute "e ". file + endif + " Get the non-active pane scrolled to the same relative offset. + syncbind +endfunction + +com! -nargs=? -complete=file Blame :call G4Blame() + +nnoremap cc :CritiqueUnresolvedComments + +nmap rbs ss rb + +nmap yb :let @+ = join(blaze#GetTargets(), ' ') +]]) diff --git a/vim/.vim/lua/plugins/google.lua b/vim/.vim/lua/plugins/google.lua index 743cf06..3e2327f 100644 --- a/vim/.vim/lua/plugins/google.lua +++ b/vim/.vim/lua/plugins/google.lua @@ -22,12 +22,6 @@ if use_google() then goog("glaive"), goog("alert"), goog("csearch"), - goog( - "codefmt", - function() - vim.cmd([[Glaive codefmt ktfmt_executable=`["/google/bin/releases/kotlin-google-eng/ktfmt/ktfmt_deploy.jar", "--google-style"]`]]) - end - ), goog("codefmt-google"), goog("languages"), goog("googlestyle"), @@ -46,6 +40,14 @@ if use_google() then goog("g4"), goog("outline-window"), goog("fzf-query"), + { + name = "codefmt", + dir = "/usr/share/vim/google/codefmt", + dependencies = { "maktaba", "glaive" }, + config = function() + vim.cmd([[Glaive codefmt ktfmt_executable=`["/google/bin/releases/kotlin-google-eng/ktfmt/ktfmt_deploy.jar", "--google-style"]`]]) + end + }, { name = "imp-google", dir = "/usr/share/vim/google/imp-google", @@ -122,137 +124,3 @@ else return {} end -vim.cmd([[ -let g:VCSCommandDisableMappings = 1 - -let g:signify_skip_filename_pattern = ['\.pipertmp.*'] - -function s:blazeExec(cmd, targets) - if len(a:targets) == 0 - exe VimuxRunCommand("build_target.py " . expand('%:p') . " " . a:cmd) - else - exe VimuxRunCommand(a:cmd . " " . join(a:targets, ' ')) - endif -endfunction - -function BlazeRun() abort - call blazeExec("blaze run", blaze#GetTargets()) -endfunction - -function BlazeBuild() abort - call blazeExec("blaze build", blaze#GetTargets()) -endfunction - -function BlazeTest() abort - call blazeExec("blaze test", blaze#GetTargets()) -endfunction - -function BlazeTestDebug() abort - call blazeExec("blaze test --java_debug", blaze#GetTargets()) -endfunction - -function BuildCleanerFile() abort - exe VimuxRunCommand("build_cleaner " . expand('%')) -endfunction - -function UnusedDeps() abort - exe VimuxRunCommand("unused_deps --nouse_build_api --blaze_options='--config=gmscore_tap' " . join(blaze#GetTargets(), ' ')) -endfunction - -function BuildCleanerTarget() abort - exe VimuxRunCommand("build_cleaner " . join(blaze#GetTargets(), ' ')) -endfunction - -nnoremap br :call BlazeRun() -nnoremap bb :call BlazeBuild() -nnoremap bt :call BlazeTest() -nnoremap btd :call BlazeTestDebug() -nnoremap bc :call BuildCleanerTarget() -nnoremap bcf :call BuildCleanerFile() -nnoremap ud :call UnusedDeps() - -let g:asyncrun_open = 1 - -function! s:AsyncBlaze(cmd, targets) abort - "open cwindow manually and immediately when blaze starts. - "simulate the same behavior from google-emacs blaze plugin. - let l:aro = g:asyncrun_open - let g:asyncrun_open = 0 - let l:target = ':'.expand('%:r') - call setqflist([]) | copen 15 - " don't use !, so we scrolling the output. - call asyncrun#run("", {"rows": 15}, a:cmd . ' ' . join(a:targets, ' ')) - let g:asyncrun_open = l:aro -endfunction - -function AsyncBlazeBuild() abort - call AsyncBlaze("blaze build", blaze#GetTargets()) -endfunction - -function AsyncBlazeTest() abort - call AsyncBlaze("blaze test", blaze#GetTargets()) -endfunction - -augroup autoformat_settings - autocmd FileType borg,gcl,patchpanel AutoFormatBuffer gclfmt - autocmd FileType bzl AutoFormatBuffer buildifier - autocmd FileType c,cpp,javascript,typescript AutoFormatBuffer clang-format - autocmd FileType dart AutoFormatBuffer dartfmt - autocmd FileType go AutoFormatBuffer gofmt - autocmd FileType java AutoFormatBuffer google-java-format - autocmd FileType jslayout AutoFormatBuffer jslfmt - autocmd FileType markdown AutoFormatBuffer mdformat - autocmd FileType ncl AutoFormatBuffer nclfmt - autocmd FileType python AutoFormatBuffer pyformat - autocmd FileType soy AutoFormatBuffer soyfmt - autocmd FileType textpb AutoFormatBuffer text-proto-format - autocmd FileType proto AutoFormatBuffer protofmt - autocmd FileType sql AutoFormatBuffer format_sql - autocmd FileType kotlin AutoFormatBuffer ktfmt - " autocmd FileType html,css,json AutoFormatBuffer js-beautify -augroup END - -function! CitCWorkspace() - let l:workspace = substitute(getcwd(), '/google/src/cloud/[^/]\+/\([^/]\+\)/.*', '\1', 'g') - return l:workspace -endfunction - -function! G4Blame(...) - " Grab the filename from the argument, use expand() to expand '%'. - if a:0 > 0 - let file = expand(a:1) - else - let file = expand('%') - endif - " Lock scrolling in right pane - setl scb - " Create left pane - vnew - " It's 37 columns wide - vert res 37 - " Get the output, split it on newline and keep empty lines, skip the first 2 - " lines because they're headers we don't need, and put it in starting on line - " 1 of the left pane - call setline(1, split(system('g4 blame ' . file), '\n', 1)[2:]) - " Lock scrolling in left pane, turn off word wrap, set the buffer as - " not-modified, remove any listchars highlighting (common in google code), set - " it readonly (to make modifications slightly more annoying). - setl scb nowrap nomod nolist ro - " Move back to the right pane (not sure if there's a better way to do this?) - exe "normal \\" - " if a file was specified, open it - if a:0 > 0 - execute "e ". file - endif - " Get the non-active pane scrolled to the same relative offset. - syncbind -endfunction - -com! -nargs=? -complete=file Blame :call G4Blame() - -nnoremap cc :CritiqueUnresolvedComments - -nmap rbs ss rb - -nmap yb :let @+ = join(blaze#GetTargets(), ' ') -]]) diff --git a/vim/.vimrc b/vim/.vimrc index ec15402..3261029 100644 --- a/vim/.vimrc +++ b/vim/.vimrc @@ -189,3 +189,5 @@ endfun filetype plugin indent on syntax on + +lua require("config.google")