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

Support Janet's backtick strings #50

Open
wants to merge 2 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
30 changes: 29 additions & 1 deletion plugin/paredit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ let s:fts_datum_comment = '.*\(scheme\).*'
" Filetypes with hash comment
let s:fts_hash_comment = '.*\(janet\).*'

" Filetypes with backtick strings
let s:fts_backtick_string = '.*\(janet\).*'

" =====================================================================
" General utility functions
" =====================================================================
Expand Down Expand Up @@ -722,11 +725,22 @@ endfunction
function! s:GetMatchedChars( lines, start_in_string, start_in_comment )
let inside_string = a:start_in_string
let inside_comment = a:start_in_comment
let inside_backtick_string = 0
let backtick_count = 1
let multiline_comment = 0
let matched = repeat( ' ', len( a:lines ) )
let i = 0
while i < len( a:lines )
if inside_string
if inside_backtick_string
" We are inside a string, skip parens, wait for closing '`' (1 or
" more) but skip escaped \` characters
let last = i + backtick_count - 1
if a:lines[i:last] == repeat('`', backtick_count) && a:lines[i-1] != '\'
let matched = strpart( matched, 0, i ) . a:lines[i:last] . strpart( matched, i+backtick_count )
let inside_backtick_string = 0
let i = last
endif
elseif inside_string
" We are inside a string, skip parens, wait for closing '"'
" but skip escaped \" characters
if a:lines[i] == '"' && a:lines[i-1] != '\'
Expand Down Expand Up @@ -754,6 +768,15 @@ function! s:GetMatchedChars( lines, start_in_string, start_in_comment )
if a:lines[i] == '"'
let matched = strpart( matched, 0, i ) . a:lines[i] . strpart( matched, i+1 )
let inside_string = 1
elseif a:lines[i] == '`'
let inside_backtick_string = 1
let backtick_count = 1
let first = i
while a:lines[i+1] == '`'
let i = i + 1
let backtick_count = backtick_count + 1
endwhile
let matched = strpart( matched, 0, first ) . a:lines[first:i] . strpart( matched, i+1 )
endif
let comment_char = ';'
if &ft =~ s:fts_hash_comment
Expand Down Expand Up @@ -791,6 +814,11 @@ function! s:Unbalanced( matched )
let tmp = substitute( tmp, '{\(\s*\)}', ' \1 ', 'g')
endif
let tmp = substitute( tmp, '"\(\s*\)"', ' \1 ', 'g')
if &ft =~ s:fts_backtick_string
let tmp = substitute( tmp, '```\(\s*\)```', ' \1 ', 'g')
let tmp = substitute( tmp, '``\(\s*\)``', ' \1 ', 'g')
let tmp = substitute( tmp, '`\(\s*\)`', ' \1 ', 'g')
endif
if tmp == matched
" All paired chars eliminated
let tmp = substitute( tmp, ')\(\s*\)(', ' \1 ', 'g')
Expand Down