Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce vertical split mode for executors #197

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ The current version of the plugin supports next commands:

#### Integration

- **`:CCMake`** allow to use *ccmake* command inside vim. The command supports next open modes: 'vsplit' - vertical mode, 'hsplit' - horizontal mode, 'tab' - open ccmake in the new tab (by default the horizontal mode is used).
- **`:CCMake`** allow to use *ccmake* command inside vim. The command supports next open modes: 'vsplit' - vertical mode, 'split' - horizontal mode, 'tab' - open ccmake in the new tab (by default the executor window split mode is used).

#### FZF plugins

Expand Down Expand Up @@ -141,7 +141,11 @@ The options below allow to change plugin behavior.
- 'dispatch' uses [vim-dispatch](https://github.com/tpope/vim-dispatch) plugin to asynchronous build
- 'system' uses synchronous build
- '' uses automatic detection of supported modes (the priority is `dispatch`, `job`, `term`, `system`)
- **`g:cmake_build_executor_height`** defines the height (in rows) of the build window and quickfixlist window showing the results. Default is 10.
- **`g:cmake_build_executor_window_size`** defines the size of build window and quickfixlist. Default is 10.
- **`g:cmake_build_executor_split_mode`** Allows to configure split mode for build window and quickfixlist. Avaulable values are:
- 'sp' enables horizontal mode. It is the default value.
- 'vsp' enables vertical mode.
- **`g:cmake_build_executor_height`** defines the height (in rows) of the build window and quickfixlist window showing the results. **The option was deprecated, please use `let g:cmake_build_executor_window_size=<size>` instead.** Default is 10.

#### Build path

Expand Down
20 changes: 12 additions & 8 deletions autoload/cmake4vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ endfunction

" Complete CCMake window modes
function! cmake4vim#CompleteCCMakeModes(arg_lead, cmd_line, cursor_pos) abort
let l:modes = ['hsplit', 'vsplit', 'tab']
let l:modes = ['split', 'vsplit', 'tab']
return join(l:modes, "\n")
endfunction

Expand All @@ -313,7 +313,7 @@ function! cmake4vim#CCMake(...) abort
" * empty, h - Open ccmake in horizontal split
" * v - Open ccmake in vertical split
" * t - Open ccmake in new tab
let l:mode = a:0 ? a:1 : 'hsplit'
let l:mode = a:0 ? a:1 : g:cmake_build_executor_split_mode ==# 'sp' ? 'split' : 'vsplit'
let l:supported_modes = split(cmake4vim#CompleteCCMakeModes(0, 0, 0), '\n')

if index(l:supported_modes, l:mode) == -1
Expand All @@ -325,16 +325,17 @@ function! cmake4vim#CCMake(...) abort
if !has('nvim')
let l:cmd .= '++close '
endif
let l:cmd .= 'ccmake ' . utils#fs#fnameescape(utils#cmake#getBuildDir())
let l:cmd .= 'ccmake -B ' . utils#fs#fnameescape(utils#cmake#getBuildDir())
if has('nvim')
let l:modes = { 'hsplit': 'vsp | ', 'vsplit': 'sp ', 'tab': 'tabnew | ' }
let l:modes = { 'split': 'sp ', 'vsplit': 'vsp | ', 'tab': 'tabnew | ' }
else
let l:modes = { 'hsplit': '', 'vsplit': 'vertical ', 'tab': 'tab ' }
let l:modes = { 'split': '', 'vsplit': 'vertical ', 'tab': 'tab ' }
endif
exec l:modes[l:mode] l:cmd
endfunction

function! cmake4vim#init() abort
" Common properties
let g:cmake_executable = get(g:, 'cmake_executable' , 'cmake' )
let g:cmake_reload_after_save = get(g:, 'cmake_reload_after_save' , 0 )
let g:cmake_change_build_command = get(g:, 'cmake_change_build_command' , 1 )
Expand All @@ -353,9 +354,12 @@ function! cmake4vim#init() abort
\ })

" Optional variable allow to specify the build executor
" Possible values: 'job', 'dispatch', 'system', ''
let g:cmake_build_executor = get(g:, 'cmake_build_executor' , '')
let g:cmake_build_executor_height = get(g:, 'cmake_build_executor_height', 10)
" Possible values: 'job', 'dispatch', 'system', 'term', ''
let g:cmake_build_executor = get(g:, 'cmake_build_executor' , '')

" Possible values: sp - horizontal mode, vsp - vertical mode
let g:cmake_build_executor_split_mode = get(g:, 'cmake_build_executor_split_mode' , 'sp')
let g:cmake_build_executor_window_size = get(g:, 'cmake_build_executor_window_size', 10)

" Build path
let g:cmake_build_path_pattern = get(g:, 'cmake_build_path_pattern' , '' )
Expand Down
10 changes: 10 additions & 0 deletions autoload/utils/common.vim
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,13 @@ function! utils#common#Warning(msg) abort
\ echomsg a:msg |
\ echohl None
endfunction

" Resolve deprecated variables
function! utils#common#getWindowSize() abort
if exists('g:cmake_build_executor_height') && g:cmake_build_executor_height !=# ''
call utils#common#Warning('g:cmake_build_executor_height option is deprecated and will be removed at the April of 2024 year!' .
\ ' Please use `let g:cmake_build_executor_window_size=<size>` instead.')
let g:cmake_build_executor_window_size = g:cmake_build_executor_height
endif
return g:cmake_build_executor_window_size
endfunction
12 changes: 6 additions & 6 deletions autoload/utils/exec/job.vim
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ function! s:vimClose(channel) abort
call s:createQuickFix()

if l:open_qf == 0
silent execute printf('botright %dcwindow', g:cmake_build_executor_height)
silent execute printf('%sbotright %d cwindow', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
else
silent execute printf('botright %dcopen', g:cmake_build_executor_height)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
cbottom
endfunction
Expand Down Expand Up @@ -106,7 +106,7 @@ function! s:nVimExit(job_id, data, event) abort
endif
call s:createQuickFix()
if a:data != 0 || l:open_qf != 0
silent execute printf('botright %dcopen', g:cmake_build_executor_height)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
endfunction

Expand All @@ -117,10 +117,10 @@ function! s:createJobBuf() abort
" qflist is open somewhere
if !empty(filter(range(1, winnr('$')), 'getwinvar(v:val, "&ft") ==# "qf"'))
" move the cursor there
silent execute printf('botright %dcopen', g:cmake_build_executor_height)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
silent execute 'keepalt edit ' . s:cmake4vim_buf
else
silent execute printf('keepalt botright %dsplit %s', g:cmake_build_executor_height, s:cmake4vim_buf)
silent execute printf('keepalt botright %d %s %s', utils#common#getWindowSize(), g:cmake_build_executor_split_mode, s:cmake4vim_buf)
endif
setlocal bufhidden=hide buftype=nofile buflisted nolist
setlocal noswapfile nowrap nomodifiable
Expand Down Expand Up @@ -149,7 +149,7 @@ function! utils#exec#job#stop() abort
endif
let s:cmake4vim_jobs_pool = []
call s:createQuickFix()
silent execute g:cmake_build_executor_height . 'copen'
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
call utils#common#Warning('Job is cancelled!')
endfunction

Expand Down
2 changes: 1 addition & 1 deletion autoload/utils/exec/system.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function! utils#exec#system#run(cmd, open_qf, errFormat) abort
cgetexpr l:s_out
call setqflist( [], 'a', { 'title' : a:cmd } )
if a:open_qf == 1 || l:ret_code != 0
execute g:cmake_build_executor_height . 'copen'
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
if !empty(a:errFormat)
let &l:errorformat = l:old_error
Expand Down
17 changes: 9 additions & 8 deletions autoload/utils/exec/term.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ function! s:vimClose(channel, status) abort
call s:createQuickFix()

if l:open_qf == 0
silent execute printf('botright %dcwindow', g:cmake_build_executor_height)
silent execute printf('%sbotright %d cwindow', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
else
silent execute printf('botright %dcopen', g:cmake_build_executor_height)
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
cbottom

Expand Down Expand Up @@ -86,7 +86,7 @@ function! s:nVimExit(job_id, data, event) abort
call s:createQuickFix()

if a:data != 0 || l:open_qf != 0
silent execute g:cmake_build_executor_height . 'copen'
silent execute printf('%sbotright %d copen', g:cmake_build_executor_split_mode ==# 'sp' ? '' : 'vert ', utils#common#getWindowSize())
endif
if a:data == 0
silent echon 'Success! ' . l:cmd
Expand Down Expand Up @@ -118,7 +118,7 @@ function! utils#exec#term#run(cmd, open_qf, cwd, err_fmt) abort
\ 'err_fmt': a:err_fmt
\ }
if has('nvim')
execute g:cmake_build_executor_height . 'split'
execute utils#common#getWindowSize() . g:cmake_build_executor_split_mode
execute 'enew'
let l:job = termopen(a:cmd, {
\ 'on_stdout': function('s:nVimOut'),
Expand All @@ -130,19 +130,20 @@ function! utils#exec#term#run(cmd, open_qf, cwd, err_fmt) abort
let l:termbufnr = bufnr()
else
let l:cmd = has('win32') ? a:cmd : [&shell, '-c', a:cmd]
silent execute printf('keepalt botright %dsplit', g:cmake_build_executor_height)
let l:job = term_start(l:cmd, {
silent execute printf('keepalt botright %d %s', utils#common#getWindowSize(), g:cmake_build_executor_split_mode)
let l:options = {
\ 'term_name': l:cmake4vim_term,
\ 'exit_cb': function('s:vimClose'),
\ 'out_cb': function('s:vimOut'),
\ 'term_finish': 'close',
\ 'term_rows': g:cmake_build_executor_height,
\ g:cmake_build_executor_split_mode ==# 'sp' ? 'term_rows' : 'term_cols': utils#common#getWindowSize(),
\ 'out_modifiable' : 0,
\ 'err_modifiable' : 0,
\ 'norestore': 1,
\ 'curwin': 1,
\ 'cwd': a:cwd
\ })
\ }
let l:job = term_start(l:cmd, l:options)
endif
if has('nvim')
let s:cmake4vim_term['termbuf'] = l:termbufnr
Expand Down
2 changes: 1 addition & 1 deletion autoload/utils/window.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function! utils#window#OpenCMakeInfoWindow() abort
let wcmd = s:cmake_info_win_name
let s:cmake_info_prev_win_id = winnr()

exe 'silent! botright ' . 30 . 'split ' . wcmd
silent execute printf('botright %d %s %s', utils#common#getWindowSize(), g:cmake_build_executor_split_mode, wcmd)
endfunction

function! utils#window#GotoCMakeInfoWindow() abort
Expand Down
23 changes: 18 additions & 5 deletions doc/cmake4vim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ COMMANDS *cmake-commands*

:CCMake *:CCMake*
Allows to use *ccmake* command inside vim.
The command supports next open modes (by default the horizontal mode
is used):
The command supports next open modes (by default the executor window split
mode is used):
* 'vsplit' - vertical mode
* 'hsplit' - horizontal mode
* 'split' - horizontal mode
* 'tab' - open ccmake in the new tab

:CMakeCompileSource *:CMakeCompileSource*
Expand Down Expand Up @@ -169,8 +169,13 @@ g:cmake_build_executor allows to force set the build executor.
Available values are 'job', 'term', 'dispatch',
'system' and ''. Default is empty.

g:cmake_build_executor_height defines the height (in rows) of the
build window and quickfixlist window showing
g:cmake_build_executor_split_mode defines the split mode for executor window.
'sp' is used by default and means
horizontal mode.
Use 'vsp' for vertical split mode.

g:cmake_build_executor_window_size defines the size of the build window and
quickfixlist window showing
the results. Default is 10.

g:cmake_vimspector_support enables support of vimspector config.
Expand Down Expand Up @@ -202,4 +207,12 @@ g:cmake_kits enables predefined cmake kits in the form
g:cmake_selected_kit currently selected cmake kit.
Default is empty.

DEPRECATED VARIABLES *cmake-deprecated-variables*

g:cmake_build_executor_height defines the height (in rows) of the
build window and quickfixlist window showing
the results. Default is 10.
Will be removed at the April of 2022.
Please use `let g:cmake_build_executor_window_size=<size>` instead.

vim: tw=79 ts=8 sw=4 sts=4 et ft=help
6 changes: 6 additions & 0 deletions test/tests/basic/generate_cmake_project.vader
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ Execute ([CMake generate] Create incorrect folder):
Assert !isdirectory("custom-folder"), "Build directory shouldn't exist"
call utils#fs#makeDir('custom-folder')
Assert !isdirectory("custom-folder"), "Build directory shouldn't exist"

Execute ([CMake generate] Verify deprecated warning):
let g:cmake_build_executor_height = 10
Assert !isdirectory("cmake-build-Release"), "Build directory shouldn't exist"
silent CMake
Assert filereadable("cmake-build-Release/CMakeCache.txt"), "CMakeCache.txt should be generated"
4 changes: 2 additions & 2 deletions test/tests/integration/ccmake.vader
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ After:
silent call RemoveCMakeDirs()

Execute ([CCMake] Get ccmake modes):
let ref_modes = ['hsplit', 'vsplit', 'tab']
let ref_modes = ['split', 'vsplit', 'tab']
let modes = split(cmake4vim#CompleteCCMakeModes(0,0,0), "\n")
AssertEqual len(modes), len(ref_modes), printf("Number of targets: %d List: %s", len(modes), join(modes))
AssertEqual ref_modes, modes
Expand All @@ -25,7 +25,7 @@ Execute ([CCMake] Run ccmake in default mode):
Execute ([CCMake] Run ccmake in horizontal mode):
if !has('win32')
silent CMake
CCMake hsplit
CCMake split
endif

Execute ([CCMake] Run ccmake in vertical mode):
Expand Down
2 changes: 2 additions & 0 deletions test/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ function! ResetPluginOptions()
let g:cmake_selected_kit = ''
let g:cmake_kits = {}
let g:cmake_kits_global_path = ''
let g:cmake_build_executor_height = ''
let g:cmake_build_executor_window_size = 10

let g:cmake_vimspector_default_configuration = {
\ 'adapter': '',
Expand Down
Loading