Compare commits

...

2 Commits

Author SHA1 Message Date
9371817937 Improve jai search and compiling in vim 2023-01-04 22:25:15 -05:00
8eccc9659a Clean up some aliases 2023-01-04 22:24:48 -05:00
3 changed files with 91 additions and 57 deletions

26
aliases
View File

@ -130,37 +130,37 @@ open_explorer_here() {
# Dev build
b() {
if [ -f build ]; then ./build $@ ; else test -f build.sh && ./build.sh $@ ; fi
test -f build && ./build $@ ; test -f build.sh && ./build.sh $@ ; test -f build.jai && ./build.jai $@
}
# fast dev build
bf() {
if [ -f build ]; then ./build $@ -fast ; else test -f build.sh && ./build.sh $@ -fast ; fi
test -f build && ./build $@ -fast ; test -f build.sh && ./build.sh $@ -fast ; test -f build.jai && ./build.jai $@
}
# Optimized dev build
bb() {
if [ -f build ]; then ./build -o 1 $@ ; else test -f build.sh && ./build.sh -o 1 $@ ; fi
test -f build && ./build $@ -o 1 ; test -f build.sh && ./build.sh $@ -o 1 ; test -f build.jai && ./build.jai -release $@
}
# Production build
bp() {
if [ -f build ]; then ./build -p p $@ ; else test -f build.sh && ./build.sh -p p $@ ; fi
test -f build && ./build $@ -p p ; test -f build.sh && ./build.sh $@ -p p ; test -f build.jai && ./build.jai -release $@ - -prod
}
# Profiling build
bpf() {
if [ -f build ]; then ./build -p pf $@ ; else test -f build.sh && ./build.sh -p pf $@ ; fi
test -f build && ./build $@ -p pf ; test -f build.sh && ./build.sh $@ -p pf
}
# GPU profiling build
bgpf() {
if [ -f build ]; then ./build -p gpu $@ ; else test -f build.sh && ./build.sh -p gpu $@ ; fi
test -f build && ./build $@ -p gpu ; test -f build.sh && ./build.sh $@ -p gpu
}
# Run build
r() {
if [ -f run ]; then ./run $@ ; else test -f run.sh && ./run.sh $@ ; fi
test -f run && ./run $@ ; test -f run.sh && ./run.sh $@
}
# Build then run
@ -602,8 +602,8 @@ dl_twitch_vid() {
if [[ $error -eq 0 ]]; then
if [[ $compress -eq 1 ]]; then
local temp_name="temp_${RANDOM}"
# 1 arg = use GPU
compress-video 0 "$filename" "$temp_name"
# 0=cpu, 1=gpu
compress-video "$filename" "$temp_name" 0
extension="${filename##*.}"
mv "$filename" "orig_$filename"
mv $temp_name.$extension "$filename"
@ -665,8 +665,8 @@ dl_vimeo_vid() {
if [[ $error -eq 0 ]]; then
if [[ $compress -eq 1 ]]; then
local temp_name="temp_${RANDOM}"
# 1 arg = use GPU
compress-video 1 "$filename" "$temp_name"
# 0=cpu, 1=gpu
compress-video "$filename" "$temp_name" 0
extension="${filename##*.}"
mv "$filename" "orig_$filename"
mv $temp_name.$extension "$filename"
@ -878,8 +878,8 @@ function _compress_video_hard() {
error "Format: cmd <source> <dest>\n"
return
fi
# 1 arg = use GPU
compress-video-with-crf 1 $crf "$name" "$out"
# 0=cpu, 1=gpu
compress-video-with-crf $crf "$name" "$out" 0
}
alias compress-video-hard='_compress_video_hard'

122
vimrc
View File

@ -411,7 +411,7 @@ augroup campoCmds
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" Properly indent schemes (scheme, racket, etc).
autocmd BufRead,BufNewFile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt
autocmd BufRead,BufNewFile *.{lisp,scm,rkt} setlocal equalprg=scmindent.vim.rkt
" Elixir indent
autocmd FileType elixir setlocal tabstop=2 | setlocal shiftwidth=2 | setlocal softtabstop=2
@ -615,6 +615,9 @@ imap jj <Esc>
" Suspend vim process and return to the shell. Can return to vim with `fg`.
nnoremap <leader>z <c-z>
" edit a file
nnoremap <leader>e :e
" Open the vimrc file for editing / reload vimrc file.
nnoremap <silent> <leader>ev :vsp $MYVIMRC<cr>
nnoremap <silent> <leader>pv :vsp ~/.vimrc.private<cr>
@ -732,7 +735,7 @@ noremap Q <Nop>
" Open a terminal within vim. Use `exit` to close it.
if exists(':terminal')
noremap <leader>t :terminal<cr>
tnoremap <leader>e <C-\><C-n>
tnoremap <leader>te <C-\><C-n>
tnoremap <A-h> <C-\><C-n><C-w>h
tnoremap <A-j> <C-\><C-n><C-w>j
tnoremap <A-k> <C-\><C-n><C-w>k
@ -1305,48 +1308,56 @@ function! StopRunTask()
call HideAsyncResults()
endfunction
function! Build(optimized=0)
let l:params = ""
function! Build(optimized=0, silent=0)
let l:ext = tolower(expand('%:e'))
if l:ext == "jai"
" Jai build
let l:parent_dir = expand('%:p:h')
let l:async_cmd = "AsyncRun! -save=2 "
if a:silent
let l:async_cmd .= "-post=call\\ HideAsyncResults() "
endif
let l:cmd = ""
if filereadable(l:parent_dir . "/build.jai")
" Jai build file
let l:cmd = "jai " . l:parent_dir . "/build.jai "
if a:optimized == 1
echo "Compiling release build.jai"
let l:cmd .= "-release "
else
echo "Compiling debug build.jai"
endif
elseif l:ext == "jai"
let l:cmd = "jai % "
if a:optimized == 1
echo "Compiling release " . expand('%:t')
let l:cmd .= "-release "
else
echo "Compiling debug " . expand('%:t')
endif
" If there's a local modules/ directory then we'll import it.
if isdirectory(expand('%:p:h') . "/modules")
if isdirectory(l:parent_dir . "/modules")
let l:cmd .= "-import_dir modules "
endif
exec "AsyncRun! -save=2 " . l:cmd
else
let l:cmd .= './build* '
if a:optimized == 1
let l:params .= '-o '
let l:cmd .= '-o '
endif
exec "AsyncRun! -save=2 ./build* " . l:params
endif
endfunction
function! SilentBuild(optimized=0)
AsyncStop
let l:params = ''
let l:extension = tolower(expand('%:e'))
if l:extension == "jai"
if a:optimized == 1
let l:params .= '-release '
endif
exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() jai % " . l:params
else
if a:optimized == 1
let l:params .= '-o '
endif
exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build* " . l:params
endif
exec l:async_cmd . l:cmd
endfunction
function! RunExe()
if tolower(expand('%:e')) == "jai"
exec "AsyncRun! " . expand('%:p:r') . ".exe"
if filereadable(expand('%:p:r') . '.exe')
exec "AsyncRun! " . expand('%:p:r') . ".exe"
else
let l:files = systemlist('ls ' . expand('%:p:h') . '/*.exe 2>/dev/null')
if len(l:files) > 0
exec "AsyncRun! " . l:files[0]
else
call PrintError("No exe found. Compile first?")
endif
endif
else
exec "AsyncRun! -post=call\\ StopRunTask() ./run %"
endif
@ -1359,22 +1370,22 @@ augroup asyncPluginCmds
augroup END
" Toggle build results
noremap <F11> :call ToggleBuildResults()<cr>
nnoremap <leader>bc :call ToggleBuildResults()<cr>
noremap <F11> :call ToggleBuildResults()<cr>
" Hide build results and clear errors
noremap <F10> :call HideBuildResultsAndClearErrors()<cr>
" Execute build script
nnoremap <leader>b :call Build(0)<cr>
nnoremap <F8> :call SilentBuild(0)<cr>
" Execute build script and keep results.
nnoremap <silent><leader>b :call Build(0)<cr>
" Execute build and hide results.
nnoremap <silent><F8> :call Build(0, 1)<cr>
" Execute optimized build script
nnoremap <leader>bb :call Build(1)<cr>
" Execute run script
nnoremap <leader>br :call RunExe()<cr>
nnoremap <F9> :call RunExe()<cr>
nnoremap <silent><leader>br :call RunExe()<cr>
nnoremap <silent><F9> :call RunExe()<cr>
nnoremap <leader>bs :AsyncStop<cr>
@ -1410,17 +1421,35 @@ function! Search(path, search_args, case_insensitive=0)
exec 'Rg ' . l:rg_args . ' -e "' . l:term . '"' . ' ' . a:path
endfunction
" Case insensitive
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Search in current directory.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Case insensitive:
noremap <leader>s :call Search('.', g:campo_custom_search_args, 1)<cr>
noremap <F2> :call Search('.', g:campo_custom_search_args, 1)<cr>
" Jai search
noremap <leader>sm :call Search(g:campo_jai_path, g:campo_custom_search_args, 1)<cr>
" Case sensitive
" Case sensitive:
noremap <leader>ss :call Search('.', g:campo_custom_search_args)<cr>
noremap <F3> :call Search('.', g:campo_custom_search_args)<cr>
" Jai module search
noremap <leader>ssm :call Search(g:campo_jai_path, g:campo_custom_search_args)<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" # Search in directory containing the active file.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Case insensitive:
noremap <leader>sf :call Search(expand('%:p:h'), g:campo_custom_search_args, 1)<cr>
" Case sensitive:
noremap <leader>ssf :call Search(expand('%:p:h'), g:campo_custom_search_args)<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Search in Jai folders
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Case insensitive:
noremap <leader>sg :call Search(g:campo_jai_path, g:campo_custom_search_args, 1)<cr>
noremap <leader>sm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args, 1)<cr>
noremap <leader>sh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args, 1)<cr>
noremap <leader>se :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args, 1)<cr>
" Case sensitive:
noremap <leader>ssg :call Search(g:campo_jai_path, g:campo_custom_search_args)<cr>
noremap <leader>ssm :call Search(g:campo_jai_path . '/modules', g:campo_custom_search_args)<cr>
noremap <leader>ssh :call Search(g:campo_jai_path . '/how_to', g:campo_custom_search_args)<cr>
noremap <leader>sse :call Search(g:campo_jai_path . '/examples', g:campo_custom_search_args)<cr>
" Navigation for the vim-ripgrep search results.
" Hit o on a result line to open the file at that line.
@ -1432,6 +1461,11 @@ nnoremap <expr> p (&buftype is# "quickfix" ? "<CR>\|:copen<CR>" : "p")
" SEARCH & REPLACE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" @warning I've stopped using this because it sometimes locks up vim and I
" have to force exit the process then clean up the swap files.
" @improve Figure out what's causing vim to freeze and fix it. Seems to happen
" when it quickly changes and saves a handful of buffers.
" Replace text in a git repo's committed files.
" The range identifier allows us to run this once when multiple lines are selected in a file.
function! GlobalReplaceIt(confirm_replacement) range