From 45d3fa244a0f219218376e93b915219c1bbfd686 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Fri, 30 Dec 2022 18:47:27 -0500 Subject: [PATCH] Clean up vim search and import local jai modules when building --- vimrc | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/vimrc b/vimrc index 08bbe1f..3584647 100644 --- a/vimrc +++ b/vimrc @@ -662,7 +662,7 @@ function! s:CreateCtags() let g:campo_ctags_exclude = g:campo_ctags_exclude + ['.git', 'node_modules'] let l:exclude_list = "" for name in g:campo_ctags_exclude - let l:exclude_list = l:exclude_list . "--exclude=" . name . " " + let l:exclude_list .= "--exclude=" . name . " " endfor " Include local variables for C-like languages. @@ -671,7 +671,7 @@ function! s:CreateCtags() " Add the filename to the ctags command if not running in recursive mode. let l:recursive = matchstr(g:campo_custom_ctags_args, '\(-R\s\)\|\(-R$\)\|\(--recurse=yes\)\|\(--recurse\s\)\|\(--recurse$\)') if l:recursive == '' - let l:ctags_cmd = l:ctags_cmd . ' ' . expand('%:t') + let l:ctags_cmd .= ' ' . expand('%:t') echo "Creating non-recursive ctags" else echo "Creating recursive ctags" @@ -910,7 +910,7 @@ let g:rg_window_height = g:quickfix_pane_height function! g:SetExtraCtagsPaths(paths_array) let l:list = './tags,tags' " This is the default tags list set by vim. for path in a:paths_array - let l:list = l:list . ',' . path + let l:list .= ',' . path endfor let &tags=l:list endfunction @@ -955,7 +955,7 @@ function! CtrlP_JaiSearch(jai_rel_search_path) endif let l:path = g:campo_jai_path if a:jai_rel_search_path != '' - let l:path = l:path. '/' . a:jai_rel_search_path + let l:path .= '/' . a:jai_rel_search_path endif if !isdirectory(l:path) call PrintError("Directory ".l:path." doesn't exist.") @@ -1306,12 +1306,19 @@ function! StopRunTask() endfunction function! Build(optimized=0) - let l:params = '' - if tolower(expand('%:e')) == "jai" + let l:params = "" + let l:ext = tolower(expand('%:e')) + if l:ext == "jai" + " Jai build + let l:cmd = "jai % " if a:optimized == 1 - let l:params .= '-release ' + let l:cmd .= "-release " endif - exec "AsyncRun! -save=2 jai % " . l:params + " If there's a local modules/ directory then we'll import it. + if isdirectory(expand('%:p:h') . "/modules") + let l:cmd .= "-import_dir modules " + endif + exec "AsyncRun! -save=2 " . l:cmd else if a:optimized == 1 let l:params .= '-o ' @@ -1385,8 +1392,8 @@ nnoremap :cp """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Search using ripgrep (first install with Rust: cargo install ripgrep). -function! Search(case_sensitive, search_args) - let l:helper = "Search [" . a:search_args . " | " . (a:case_sensitive ? "case-sensitive" : "case-insensitive") . "]: " +function! Search(path, search_args, case_insensitive=0) + let l:helper = "Search '" . a:path . "' (" . (len(a:search_args) > 0 ? a:search_args . " | " : '') . (a:case_insensitive ? "INSENSITIVE" : "SENSITIVE") . "): " let l:term = input(l:helper) if empty(l:term) return @@ -1396,20 +1403,24 @@ function! Search(case_sensitive, search_args) "quickfix window doesn't seem to parse the ansi color codes. let l:rg_args = "--column --line-number --no-heading --fixed-strings --no-ignore --hidden --follow --trim -g \"!tags\" -g \"!.git/\" -g \"!AppData/\" " . a:search_args - if !a:case_sensitive + if a:case_insensitive let l:rg_args .= " --ignore-case" endif - exec 'Rg ' . l:rg_args . ' -e "' . l:term . '"' + exec 'Rg ' . l:rg_args . ' -e "' . l:term . '"' . ' ' . a:path endfunction " Case insensitive -noremap s :call Search(0, g:campo_custom_search_args) -noremap :call Search(0, g:campo_custom_search_args_2) +noremap s :call Search('.', g:campo_custom_search_args, 1) +noremap :call Search('.', g:campo_custom_search_args, 1) +" Jai search +noremap sm :call Search(g:campo_jai_path, g:campo_custom_search_args, 1) " Case sensitive -noremap ss :call Search(1, g:campo_custom_search_args) -noremap :call Search(1, g:campo_custom_search_args_2) +noremap ss :call Search('.', g:campo_custom_search_args) +noremap :call Search('.', g:campo_custom_search_args) +" Jai module search +noremap ssm :call Search(g:campo_jai_path, g:campo_custom_search_args) " Navigation for the vim-ripgrep search results. " Hit o on a result line to open the file at that line.