From b842eb4a488c38c740cfb011de808eeeb83513d9 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 20 Oct 2019 13:55:10 +0200 Subject: [PATCH 1/5] Replace FSwitch call with vimscript --- autoload/splitopen.vim | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/autoload/splitopen.vim b/autoload/splitopen.vim index d4f2aac..98aa3b0 100644 --- a/autoload/splitopen.vim +++ b/autoload/splitopen.vim @@ -1,11 +1,28 @@ +function s:getFileExtension(filename) + return fnamemodify(a:filename, ":e") +endfunction + +function s:getFileRoot(filename) + return fnamemodify(a:filename, ":r") +endfunc + +function s:getSwitchExtension(extension) + if (a:extension == "cpp") + return "h" + elseif (a:extension == "h") + return "cpp" + endif +endfunc + +function s:getSwitchFile(filename) + return s:getFileRoot(a:filename) . "." . s:getSwitchExtension(s:getFileExtension(a:filename)) +endfunc + +function s:addLeftSplit(filename) + execute("vsplit " . s:getSwitchFile(a:filename)) +endfunc + function splitopen#SplitOpenFile(filename) execute("tabedit " . a:filename) - let l:file_extension = tolower(fnamemodify(a:filename, ":e")) - if l:file_extension == "cpp" - execute("FSSplitLeft") - execute("wincmd l") - elseif l:file_extension == "h" - execute("FSSplitRight") - execute("wincmd h") - endif + call s:addLeftSplit(a:filename) endfunction From cd2d19844798ecc18381c2336ea3362eca1a0bfb Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 20 Oct 2019 15:39:32 +0200 Subject: [PATCH 2/5] Define left- and right-hand filetypes via global config variable --- autoload/splitopen.vim | 46 +++++++++++++++++++++++++++++++++++------- plugin/splitopen.vim | 11 +++++++++- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/autoload/splitopen.vim b/autoload/splitopen.vim index 98aa3b0..b4488ba 100644 --- a/autoload/splitopen.vim +++ b/autoload/splitopen.vim @@ -1,3 +1,22 @@ +function s:invert_dict(source_dict) + let result = {} + for [key, value] in items(a:source_dict) + let result[value] = key + endfor + return result +endfunc + +let s:extensions = g:splitopen_extensions +let s:extensions_rev = s:invert_dict(s:extensions) + +function s:isLeftSideExtension(extension) + return has_key(s:extensions, a:extension) +endfunc + +function s:isRightSideExtension(extension) + return has_key(s:extensions_rev, a:extension) +endfunc + function s:getFileExtension(filename) return fnamemodify(a:filename, ":e") endfunction @@ -6,23 +25,36 @@ function s:getFileRoot(filename) return fnamemodify(a:filename, ":r") endfunc -function s:getSwitchExtension(extension) - if (a:extension == "cpp") - return "h" - elseif (a:extension == "h") - return "cpp" +function s:getSwitchExtension(filename) + let extension = s:getFileExtension(a:filename) + if s:isLeftSideExtension(extension) + return s:extensions[extension] + elseif s:isRightSideExtension(extension) + return s:extensions_rev[extension] endif endfunc function s:getSwitchFile(filename) - return s:getFileRoot(a:filename) . "." . s:getSwitchExtension(s:getFileExtension(a:filename)) + return s:getFileRoot(a:filename) . "." . s:getSwitchExtension(a:filename) endfunc function s:addLeftSplit(filename) execute("vsplit " . s:getSwitchFile(a:filename)) + execute("wincmd l") +endfunc + +function s:addRightSplit(filename) + execute("vsplit " . s:getSwitchFile(a:filename)) + execute("wincmd L") + execute("wincmd h") endfunc function splitopen#SplitOpenFile(filename) execute("tabedit " . a:filename) - call s:addLeftSplit(a:filename) + let extension = s:getFileExtension(a:filename) + if s:isLeftSideExtension(extension) + call s:addRightSplit(a:filename) + elseif s:isRightSideExtension(extension) + call s:addLeftSplit(a:filename) + endif endfunction diff --git a/plugin/splitopen.vim b/plugin/splitopen.vim index 91cabdd..7f54b02 100644 --- a/plugin/splitopen.vim +++ b/plugin/splitopen.vim @@ -1,5 +1,13 @@ command -nargs=1 SplitOpen :call splitopen#SplitOpenFile("") +" map left-split / right-split file extensions +if !exists("g:splitopen_extensions") + let g:splitopen_extensions = { + \ "h": "cpp", + \ "H": "CPP", + \ } +endif + if !exists('g:splitopen_set_fzf_keys') let g:splitopen_set_fzf_keys = 0 endif @@ -9,5 +17,6 @@ if g:splitopen_set_fzf_keys \ 'ctrl-s': 'SplitOpen', \ 'ctrl-t': 'tab split', \ 'ctrl-x': 'split', - \ 'ctrl-v': 'vsplit' } + \ 'ctrl-v': 'vsplit', + \ } endif From b6b1377f93b771e8538b47b1136a3575a8fc0640 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 20 Oct 2019 15:45:53 +0200 Subject: [PATCH 3/5] Added documentation for g:splitopen_extensions --- README.md | 9 +++++++++ doc/splitopen.txt | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 823c8a7..8481b70 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,15 @@ source file in the right window. You can configure the following settings: +### g:splitopen_extensions + +Use this dictionary to define your pairs of left-hand- right-hand-side file +types. E.g. + + let g:splitopen_extensions = {"h": "cpp"} + +always places a .cpp file on the right-hand side when opening an .h file and +vice versa. ### g:splitopen_set_fzf_keys diff --git a/doc/splitopen.txt b/doc/splitopen.txt index c4b3e6e..39cb2a6 100644 --- a/doc/splitopen.txt +++ b/doc/splitopen.txt @@ -5,7 +5,8 @@ CONTENTS *SplitOpenContents* 1. Usage ..............................|SplitOpenUsage| 2. Configuration ......................|SlitOpenConfiguraton| - 2.1 g:splitopen_set_fzf_keys.......|SplitOpenConfiguration_set_fzf_keys| + 2.1 g:splitopen_extensions.........|SplitOpenConfiguration_extensions| + 2.2 g:splitopen_set_fzf_keys.......|SplitOpenConfiguration_set_fzf_keys| 3. License ............................|SplitOpenLicense| 4. Changelog ..........................|SplitOpenChangelog| @@ -27,7 +28,19 @@ You can configure the following settings: -------------------------------------------------------------------------------- -2.1 g:splitopen_set_fzf_keys *SplitOpenConfiguration_set_fzf_keys* +2.1 g:splitopen_extensions *SplitOpenConfiguration_extensions* + +Use this dictionary to define your pairs of left-hand- right-hand-side file +types. E.g. + + let g:splitopen_extensions = {"h": "cpp"} + +always places a .cpp file on the right-hand side when opening an .h file and +vice versa. + +-------------------------------------------------------------------------------- + +2.2 g:splitopen_set_fzf_keys *SplitOpenConfiguration_set_fzf_keys* Set this option to 1 From a6f8b0fda5c36c236b864d3b9a2bc9580cfab1e6 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 20 Oct 2019 15:48:05 +0200 Subject: [PATCH 4/5] Formatting --- doc/splitopen.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/splitopen.txt b/doc/splitopen.txt index 39cb2a6..ef3aa40 100644 --- a/doc/splitopen.txt +++ b/doc/splitopen.txt @@ -27,7 +27,6 @@ source file in the right window. You can configure the following settings: -------------------------------------------------------------------------------- - 2.1 g:splitopen_extensions *SplitOpenConfiguration_extensions* Use this dictionary to define your pairs of left-hand- right-hand-side file @@ -39,7 +38,6 @@ always places a .cpp file on the right-hand side when opening an .h file and vice versa. -------------------------------------------------------------------------------- - 2.2 g:splitopen_set_fzf_keys *SplitOpenConfiguration_set_fzf_keys* Set this option to 1 From d91bb228a7e1f2ed4a32f67b1e03866806e23172 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Sun, 20 Oct 2019 15:53:29 +0200 Subject: [PATCH 5/5] Added release notes --- README.md | 3 +++ doc/splitopen.txt | 2 ++ 2 files changed, 5 insertions(+) diff --git a/README.md b/README.md index 8481b70..9418060 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,9 @@ SplitOpen is GPL-3.0 licensed. See LICENSE file for more info. ## Changelog +v0.0.4 +* Add filetype configuraton + v0.0.3 * Add fzf.vim keybinding diff --git a/doc/splitopen.txt b/doc/splitopen.txt index ef3aa40..55e954d 100644 --- a/doc/splitopen.txt +++ b/doc/splitopen.txt @@ -55,6 +55,8 @@ SplitOpen is GPL-3.0 licensed. See LICENSE file for more info. ================================================================================ 4. Changelog *SplitOpenChangelog* +v0.0.4 + * Add filetype configuraton v0.0.3 * Add fzf.vim keybinding v0.0.2