Skip to content

Commit

Permalink
Introduce vertical split mode for executors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyachur committed Feb 19, 2024
1 parent 79692cf commit 99f4778
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 30 deletions.
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
24 changes: 17 additions & 7 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 @@ -327,14 +327,15 @@ function! cmake4vim#CCMake(...) abort
endif
let l:cmd .= 'ccmake ' . 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,18 @@ 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')
if exists('g:cmake_build_executor_height') && g:cmake_build_executor_height !=# '' && !exists('g:cmake_build_executor_window_size')
call utils#common#Warning('g:cmake_cxx_compiler 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
else
let g:cmake_build_executor_window_size = get(g:, 'cmake_build_executor_window_size', 10)
endif

" Build path
let g:cmake_build_path_pattern = get(g:, 'cmake_build_path_pattern' , '' )
Expand Down
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 ', g:cmake_build_executor_window_size)
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 ', g:cmake_build_executor_window_size)
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 ', g:cmake_build_executor_window_size)
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 ', g:cmake_build_executor_window_size)
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', g:cmake_build_executor_window_size, 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 ', g:cmake_build_executor_window_size)
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 ', g:cmake_build_executor_window_size)
endif
if !empty(a:errFormat)
let &l:errorformat = l:old_error
Expand Down
11 changes: 5 additions & 6 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 ', g:cmake_build_executor_window_size)
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 ', g:cmake_build_executor_window_size)
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 ', g:cmake_build_executor_window_size)
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 g:cmake_build_executor_window_size . g:cmake_build_executor_split_mode
execute 'enew'
let l:job = termopen(a:cmd, {
\ 'on_stdout': function('s:nVimOut'),
Expand All @@ -130,13 +130,12 @@ 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)
silent execute printf('keepalt botright %d %s', g:cmake_build_executor_window_size, g:cmake_build_executor_split_mode)
let l:job = term_start(l:cmd, {
\ '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,
\ 'out_modifiable' : 0,
\ 'err_modifiable' : 0,
\ 'norestore': 1,
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', g:cmake_build_executor_window_size, 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
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

0 comments on commit 99f4778

Please sign in to comment.