From 1c24594c70c9dcd4048eaefa068900aa4aaaa2fd Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sat, 14 Sep 2013 23:33:40 +0800 Subject: [PATCH 01/11] added split support for goto action --- autoload/jedi.vim | 1 + doc/jedi-vim.txt | 10 ++++++++++ jedi_vim.py | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index b4a4d16..1a78543 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -221,6 +221,7 @@ endfor let s:settings = { \ 'use_tabs_not_buffers': 1, + \ 'use_splits_not_buffers': "", \ 'auto_initialization': 1, \ 'auto_vim_configuration': 1, \ 'goto_assignments_command': "'g'", diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index c5ad8d6..af94571 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -37,6 +37,7 @@ Contents *jedi-vim-contents* 6.7. use_tabs_not_buffers |g:jedi#use_tabs_not_buffers| 6.8. squelch_py_warning |g:jedi#squelch_py_warning| 6.9. completions_enable |g:jedi#completions_enable| + 6.10. use_splits_not_buffers |g:jedi#user_splits_not_buffers| 7. Testing |jedi-vim-testing| 8. Contributing |jedi-vim-contributing| 9. License |jedi-vim-license| @@ -394,6 +395,15 @@ YCM). Options: 0 or 1 Default: 1 +------------------------------------------------------------------------------ +6.9. `g:jedi#completions_enable` *g:jedi#completions_enable* + +If you want to open new split for "go to", you could set this option to the +direction which you want to open a split with. + +Options: top, left, right or bottom +Default: "" (not enabled by default) + ============================================================================== 7. Testing *jedi-vim-testing* diff --git a/jedi_vim.py b/jedi_vim.py index 1f1d056..df65cae 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -399,6 +399,24 @@ def new_buffer(path, options=''): # options are what you can to edit the edit options if vim_eval('g:jedi#use_tabs_not_buffers') == '1': _tabnew(path, options) + elif vim_eval('g:jedi#use_splits_not_buffers'): + user_split_option = vim_eval('g:jedi#use_splits_not_buffers') + split_options = [ + 'top', + 'right', + 'left', + 'bottom' + ] + if user_split_option not in split_options: + print('g:jedi#use_splits_not_buffers value is not correct, valid options are: %s' % ','.join(split_options)) + else: + VIM_SPLIT_COMMAND = { + 'top': 'topleft split', + 'left': 'topleft vsplit', + 'right': 'botright vsplit', + 'bottom': 'botright split' + } + vim_command(VIM_SPLIT_COMMAND[user_split_option] + " %s" % path) else: if vim_eval("!&hidden && &modified") == '1': if vim_eval("bufname('%')") is None: From ec405fa3b26996ba9f53f3eabb2a5e3560bed388 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 00:20:20 +0800 Subject: [PATCH 02/11] fixed type and set default value to 1 to avoid testing error --- autoload/jedi.vim | 2 +- doc/jedi-vim.txt | 2 +- jedi_vim.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index 1a78543..201a8e3 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -221,7 +221,7 @@ endfor let s:settings = { \ 'use_tabs_not_buffers': 1, - \ 'use_splits_not_buffers': "", + \ 'use_splits_not_buffers': 1, \ 'auto_initialization': 1, \ 'auto_vim_configuration': 1, \ 'goto_assignments_command': "'g'", diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index af94571..8f9cf63 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -37,7 +37,7 @@ Contents *jedi-vim-contents* 6.7. use_tabs_not_buffers |g:jedi#use_tabs_not_buffers| 6.8. squelch_py_warning |g:jedi#squelch_py_warning| 6.9. completions_enable |g:jedi#completions_enable| - 6.10. use_splits_not_buffers |g:jedi#user_splits_not_buffers| + 6.10. use_splits_not_buffers |g:jedi#use_splits_not_buffers| 7. Testing |jedi-vim-testing| 8. Contributing |jedi-vim-contributing| 9. License |jedi-vim-license| diff --git a/jedi_vim.py b/jedi_vim.py index df65cae..b674805 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -399,7 +399,7 @@ def new_buffer(path, options=''): # options are what you can to edit the edit options if vim_eval('g:jedi#use_tabs_not_buffers') == '1': _tabnew(path, options) - elif vim_eval('g:jedi#use_splits_not_buffers'): + elif not vim_eval('g:jedi#use_splits_not_buffers') == '1': user_split_option = vim_eval('g:jedi#use_splits_not_buffers') split_options = [ 'top', From 63162524c249c61615247dcc8eeed61a6d745371 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 00:29:56 +0800 Subject: [PATCH 03/11] moved up the split_options --- jedi_vim.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index b674805..e982e68 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -401,22 +401,16 @@ def new_buffer(path, options=''): _tabnew(path, options) elif not vim_eval('g:jedi#use_splits_not_buffers') == '1': user_split_option = vim_eval('g:jedi#use_splits_not_buffers') - split_options = [ - 'top', - 'right', - 'left', - 'bottom' - ] + split_options = { + 'top': 'topleft split', + 'left': 'topleft vsplit', + 'right': 'botright vsplit', + 'bottom': 'botright split' + } if user_split_option not in split_options: print('g:jedi#use_splits_not_buffers value is not correct, valid options are: %s' % ','.join(split_options)) else: - VIM_SPLIT_COMMAND = { - 'top': 'topleft split', - 'left': 'topleft vsplit', - 'right': 'botright vsplit', - 'bottom': 'botright split' - } - vim_command(VIM_SPLIT_COMMAND[user_split_option] + " %s" % path) + vim_command(split_options[user_split_option] + " %s" % path) else: if vim_eval("!&hidden && &modified") == '1': if vim_eval("bufname('%')") is None: From df81a593ec21931483169737e107a05bf0349522 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 00:48:19 +0800 Subject: [PATCH 04/11] generate list by keys() for join() --- jedi_vim.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jedi_vim.py b/jedi_vim.py index e982e68..35df53a 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -408,7 +408,7 @@ def new_buffer(path, options=''): 'bottom': 'botright split' } if user_split_option not in split_options: - print('g:jedi#use_splits_not_buffers value is not correct, valid options are: %s' % ','.join(split_options)) + print('g:jedi#use_splits_not_buffers value is not correct, valid options are: %s' % ','.join(split_options.keys())) else: vim_command(split_options[user_split_option] + " %s" % path) else: From 27d35b4fc09da8fd2c53012581c078baf179410a Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 00:54:10 +0800 Subject: [PATCH 05/11] fixed wrong title in doc --- doc/jedi-vim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index 8f9cf63..d0f8f9a 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -396,7 +396,7 @@ Options: 0 or 1 Default: 1 ------------------------------------------------------------------------------ -6.9. `g:jedi#completions_enable` *g:jedi#completions_enable* +6.10. `g:jedi#use_splits_not_buffers` *g:jedi#use_splits_not_buffers* If you want to open new split for "go to", you could set this option to the direction which you want to open a split with. From e1cac7d3f7bb87d01f12908df121f1705d628042 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 00:57:47 +0800 Subject: [PATCH 06/11] updated README.rst for use_splits_not_buffers --- README.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.rst b/README.rst index 080980f..6bd91ca 100644 --- a/README.rst +++ b/README.rst @@ -106,6 +106,13 @@ put that in your ``.vimrc``: let g:jedi#use_tabs_not_buffers = 0 +If you are a person who likes to use VIM-splits, you might want to put this in your ``.vimrc``: + +.. code-block:: vim + + let g:jedi#use_splits_not_buffers = "left" + +This options could be "left", "right", "top" or "bottom", it will decide the direction where the split open. Jedi automatically starts the completion, if you type a dot, e.g. ``str.``, if you don't want this: From 2a3eaeb2dc47eaa23bd54b29b4de95ed99d7d3f1 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 00:59:28 +0800 Subject: [PATCH 07/11] this is better --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6bd91ca..cb0dcdb 100644 --- a/README.rst +++ b/README.rst @@ -112,7 +112,7 @@ If you are a person who likes to use VIM-splits, you might want to put this in y let g:jedi#use_splits_not_buffers = "left" -This options could be "left", "right", "top" or "bottom", it will decide the direction where the split open. +This options could be "left", "right", "top" or "bottom". It will decide the direction where the split open. Jedi automatically starts the completion, if you type a dot, e.g. ``str.``, if you don't want this: From b8edeef966b35c0671f706dac05eb65216138939 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 01:18:21 +0800 Subject: [PATCH 08/11] added myself to AUTHORS.txt --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 77e3526..35872a3 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -33,6 +33,7 @@ ethinx (@ethinx) Wouter Overmeire (@lodagro) Stephen J. Fuhry (@fuhrysteve) Sheng Yun (@ShengYun) +Colin Su (@littleq0903) @something are github user names. From aa56af0d9c8e548a0854fed6a306da0d69c316e2 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 02:06:17 +0800 Subject: [PATCH 09/11] only need to check the opening direction is correct --- test/goto.vim | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/goto.vim b/test/goto.vim index 45acd81..bd46e86 100644 --- a/test/goto.vim +++ b/test/goto.vim @@ -135,4 +135,35 @@ describe 'goto_with_buffers' end end + + +describe 'goto_with_splits' + before + set filetype=python + let g:jedi#use_splits_not_buffers = 'left' + end + + after + bd! + bd! + end + + it 'follow_import' + put = ['import subprocess', 'subprocess'] + silent normal G\g + Expect getline('.') == 'import subprocess' + Expect line('.') == 2 + Expect col('.') == 8 + + silent normal G\d + Expect g:current_buffer_is_module('subprocess') == 1 + Expect line('.') == 1 + Expect col('.') == 1 + wincmd l + Expect bufname('%') == '' + end + +end + + " vim: et:ts=4:sw=4 From a247e9b1c7879054301e8b5ebdcd4cce53b0f97d Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 02:19:48 +0800 Subject: [PATCH 10/11] make sure it really opened a split window --- test/goto.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/test/goto.vim b/test/goto.vim index bd46e86..48f038c 100644 --- a/test/goto.vim +++ b/test/goto.vim @@ -159,6 +159,7 @@ describe 'goto_with_splits' Expect g:current_buffer_is_module('subprocess') == 1 Expect line('.') == 1 Expect col('.') == 1 + Expect winnr('$') == 2 wincmd l Expect bufname('%') == '' end From b8269d70d42d36d978ff157059389261316e1cd6 Mon Sep 17 00:00:00 2001 From: LittleQ Date: Sun, 15 Sep 2013 03:03:59 +0800 Subject: [PATCH 11/11] added tests for checking other goto will perform in only one window, no other split buffer will be opened accidentially --- test/goto.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/goto.vim b/test/goto.vim index 48f038c..6163093 100644 --- a/test/goto.vim +++ b/test/goto.vim @@ -67,6 +67,7 @@ describe 'goto_with_tabs' Expect line('.') == 1 Expect col('.') == 1 Expect tabpagenr('$') == 2 + Expect winnr('$') == 1 tabprevious Expect bufname('%') == '' end @@ -78,12 +79,14 @@ describe 'goto_with_tabs' Expect g:current_buffer_is_module('token') == 0 execute "normal \" Expect tabpagenr('$') == 2 + Expect winnr('$') == 1 Expect g:current_buffer_is_module('token') == 1 bd silent normal G$\d execute "normal j\" Expect tabpagenr('$') == 2 + Expect winnr('$') == 1 Expect g:current_buffer_is_module('tokenize') == 1 end end @@ -112,6 +115,7 @@ describe 'goto_with_buffers' set hidden call jedi#goto_assignments() Expect g:current_buffer_is_module('os') == 1 + Expect winnr('$') == 1 Expect tabpagenr('$') == 1 Expect line('.') == 1 Expect col('.') == 1 @@ -125,12 +129,14 @@ describe 'goto_with_buffers' Expect g:current_buffer_is_module('token') == 0 execute "normal \" Expect tabpagenr('$') == 1 + Expect winnr('$') == 1 Expect g:current_buffer_is_module('token') == 1 bd silent normal G$\d execute "normal j\" Expect tabpagenr('$') == 1 + Expect winnr('$') == 1 Expect g:current_buffer_is_module('tokenize') == 1 end end