From 5179833cfc60e40d0ca14944e2721f0c23faa50b Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Sun, 25 Feb 2024 15:26:10 +0100 Subject: [PATCH 1/2] Recognize comments in Janet files --- plugin/paredit.vim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin/paredit.vim b/plugin/paredit.vim index 83401a9..eeb690f 100644 --- a/plugin/paredit.vim +++ b/plugin/paredit.vim @@ -588,11 +588,12 @@ function! s:InsideComment( ... ) let c = a:0 ? a:2 : col('.') if &syntax == '' " No help from syntax engine, - " remove strings and search for ';' up to the cursor position + " remove strings and search for ';' (Janet: '#') up to the cursor position let line = strpart( getline(l), 0, c - 1 ) let line = substitute( line, '\\"', '', 'g' ) let line = substitute( line, '"[^"]*"', '', 'g' ) - return match( line, ';' ) >= 0 + if &ft == 'janet' | let comment_char = '#' | else | let comment_char = ';' | end + return match( line, comment_char ) >= 0 endif if s:SynIDMatch( 'clojureComment', l, c, 1 ) if strpart( getline(l), c-1, 2 ) == '#_' || strpart( getline(l), c-2, 2 ) == '#_' @@ -748,7 +749,8 @@ 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 endif - if a:lines[i] == ';' + if &ft == 'janet' | let comment_char = '#' | else | let comment_char = ';' | end + if a:lines[i] == comment_char let inside_comment = 1 if &ft =~ s:fts_datum_comment && i > 0 && a:lines[i-1] == '#' " Datum comment: pretend that we are not inside comment @@ -1206,12 +1208,13 @@ function! s:EraseFwd( count, startcol ) let ve_save = &virtualedit set virtualedit=all let c = a:count + if &ft == 'janet' | let comment_char = '#' | else | let comment_char = ';' | end while c > 0 if line[pos] == '\' && line[pos+1] =~ b:any_matched_char && (pos < 1 || line[pos-1] != '\') " Erasing an escaped matched character let reg = reg . line[pos : pos+1] let line = strpart( line, 0, pos ) . strpart( line, pos+2 ) - elseif s:InsideComment() && line[pos] == ';' && a:startcol >= 0 + elseif s:InsideComment() && line[pos] == comment_char && a:startcol >= 0 " Erasing the whole comment, only when erasing a block of characters let reg = reg . strpart( line, pos ) let line = strpart( line, 0, pos ) From 31c3ced0814d7bcacc4bea6552ab49be3045eb49 Mon Sep 17 00:00:00 2001 From: Max Schillinger Date: Sun, 25 Feb 2024 17:34:53 +0100 Subject: [PATCH 2/2] Introduce s:fts_hash_comment --- plugin/paredit.vim | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/plugin/paredit.vim b/plugin/paredit.vim index eeb690f..b5f7f37 100644 --- a/plugin/paredit.vim +++ b/plugin/paredit.vim @@ -86,6 +86,9 @@ let s:fts_multiline_comment = '.*\(scheme\|racket\).*' " Filetypes with datum comment #;(...) let s:fts_datum_comment = '.*\(scheme\).*' +" Filetypes with hash comment +let s:fts_hash_comment = '.*\(janet\).*' + " ===================================================================== " General utility functions " ===================================================================== @@ -592,7 +595,10 @@ function! s:InsideComment( ... ) let line = strpart( getline(l), 0, c - 1 ) let line = substitute( line, '\\"', '', 'g' ) let line = substitute( line, '"[^"]*"', '', 'g' ) - if &ft == 'janet' | let comment_char = '#' | else | let comment_char = ';' | end + let comment_char = ';' + if &ft =~ s:fts_hash_comment + let comment_char = '#' + endif return match( line, comment_char ) >= 0 endif if s:SynIDMatch( 'clojureComment', l, c, 1 ) @@ -749,7 +755,10 @@ 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 endif - if &ft == 'janet' | let comment_char = '#' | else | let comment_char = ';' | end + let comment_char = ';' + if &ft =~ s:fts_hash_comment + let comment_char = '#' + endif if a:lines[i] == comment_char let inside_comment = 1 if &ft =~ s:fts_datum_comment && i > 0 && a:lines[i-1] == '#' @@ -1208,7 +1217,10 @@ function! s:EraseFwd( count, startcol ) let ve_save = &virtualedit set virtualedit=all let c = a:count - if &ft == 'janet' | let comment_char = '#' | else | let comment_char = ';' | end + let comment_char = ';' + if &ft =~ s:fts_hash_comment + let comment_char = '#' + endif while c > 0 if line[pos] == '\' && line[pos+1] =~ b:any_matched_char && (pos < 1 || line[pos-1] != '\') " Erasing an escaped matched character