From ba3918fbd6b217f47e1c02fd407fbc2c01bec5e8 Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Sun, 25 Feb 2024 17:36:28 +0100 Subject: [PATCH 1/2] Support Janet's backtick strings --- plugin/paredit.vim | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/plugin/paredit.vim b/plugin/paredit.vim index b5f7f37..f3290bd 100644 --- a/plugin/paredit.vim +++ b/plugin/paredit.vim @@ -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 " ===================================================================== @@ -722,11 +725,19 @@ 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 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 '`' + " but skip escaped \` characters + if a:lines[i] == '`' && a:lines[i-1] != '\' + let matched = strpart( matched, 0, i ) . a:lines[i] . strpart( matched, i+1 ) + let inside_backtick_string = 0 + 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] != '\' @@ -754,6 +765,9 @@ 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 matched = strpart( matched, 0, i ) . a:lines[i] . strpart( matched, i+1 ) + let inside_backtick_string = 1 endif let comment_char = ';' if &ft =~ s:fts_hash_comment @@ -791,6 +805,9 @@ 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') + endif if tmp == matched " All paired chars eliminated let tmp = substitute( tmp, ')\(\s*\)(', ' \1 ', 'g') From 92f91aaf0ba94b31fc95be0d9bcda33f6da07ed9 Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Sun, 25 Feb 2024 23:45:12 +0100 Subject: [PATCH 2/2] Handle Janet strings enclosed in double or triple backticks --- plugin/paredit.vim | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/plugin/paredit.vim b/plugin/paredit.vim index f3290bd..f304119 100644 --- a/plugin/paredit.vim +++ b/plugin/paredit.vim @@ -726,16 +726,19 @@ 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_backtick_string - " We are inside a string, skip parens, wait for closing '`' - " but skip escaped \` characters - if a:lines[i] == '`' && a:lines[i-1] != '\' - let matched = strpart( matched, 0, i ) . a:lines[i] . strpart( matched, i+1 ) + " 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 '"' @@ -766,8 +769,14 @@ function! s:GetMatchedChars( lines, start_in_string, start_in_comment ) let matched = strpart( matched, 0, i ) . a:lines[i] . strpart( matched, i+1 ) let inside_string = 1 elseif a:lines[i] == '`' - let matched = strpart( matched, 0, i ) . a:lines[i] . strpart( matched, i+1 ) 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 @@ -806,6 +815,8 @@ function! s:Unbalanced( matched ) 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