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

Added ability to expand abbreviations #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 31 additions & 14 deletions autoload/doorboy/mapping.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,45 @@ let s:CR = "\<CR>"
let s:UP = "\<UP>"
let s:TAB = "\<TAB>"

let s:EXPAND_ABBR = "\<C-]>"

"""""""""" Mapped functions

function! doorboy#mapping#put_quotation(quotation)
let l:expand_abbr = s:get_expand_abbr(quotation)
if doorboy#util#get_next_char() ==# a:quotation
return s:SKIP
return l:expand_abbr . s:SKIP
endif
if doorboy#util#in_regular_expression()
return a:quotation
return l:expand_abbr . a:quotation
endif
if doorboy#util#get_left_str() !~ s:get_separator_l_exp()
return a:quotation
return l:expand_abbr . a:quotation
endif
if doorboy#util#get_right_str() !~ s:get_separator_r_exp()
return a:quotation
return l:expand_abbr . a:quotation
endif
return a:quotation . a:quotation . s:BACK
return l:expand_abbr . a:quotation . a:quotation . s:BACK
endfunction

function! doorboy#mapping#put_opening_bracket(opening_bracket, closing_bracket)
let next_char = doorboy#util#get_next_char()
let l:expand_abbr = s:get_expand_abbr(a:opening_bracket)
if next_char ==# a:opening_bracket
return s:SKIP
return l:expand_abbr . s:SKIP
endif
if s:is_present(next_char) && next_char !~ s:get_separator_r_exp()
return a:opening_bracket
return l:expand_abbr . a:opening_bracket
endif
return a:opening_bracket . a:closing_bracket . s:BACK
return l:expand_abbr . a:opening_bracket . a:closing_bracket . s:BACK
endfunction

function! doorboy#mapping#put_closing_bracket(closing_bracket)
let l:expand_abbr = s:get_expand_abbr(a:closing_bracket)
if doorboy#util#get_next_char() ==# a:closing_bracket
return s:SKIP
return l:expand_abbr . s:SKIP
endif
return a:closing_bracket
return l:expand_abbr . a:closing_bracket
endfunction

function! doorboy#mapping#backspace()
Expand All @@ -58,17 +63,19 @@ function! doorboy#mapping#backspace()
endfunction

function! doorboy#mapping#space()
let l:expand_abbr = s:get_expand_abbr(expand(s:SPACE))
if doorboy#util#is_between_brackets()
return s:SPACE . s:SPACE . s:BACK
return l:expand_abbr . s:SPACE . s:SPACE . s:BACK
endif
return s:SPACE
return l:expand_abbr . s:SPACE
endfunction

function! doorboy#mapping#cr()
let l:expand_abbr = s:get_expand_abbr(expand(s:CR))
if doorboy#util#is_between_brackets()
return s:CR . s:CR . s:UP . s:TAB
return l:expand_abbr . s:CR . s:CR . s:UP . s:TAB
endif
return s:CR
return l:expand_abbr . s:CR
endfunction

function! s:is_present(char)
Expand Down Expand Up @@ -99,3 +106,13 @@ function! s:get_separator_r_exp()
endif
return '\v^%([\)}\]>,\.=/]|\s|$)'
endfunction

"
" Returns s:EXPAND_ABBR if char is not a keyword character, '' otherwise.
"
function! s:get_expand_abbr(char)
if match(a:char, '\k') == -1
return s:EXPAND_ABBR
endif
return ''
endfunction