Skip to content

Commit

Permalink
feat: support line continuation comment in ft=vim (fix #85)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyru committed Sep 12, 2018
1 parent ffdda24 commit dedb063
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions after/ftplugin/vim/caw.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let s:save_cpo = &cpo
set cpo&vim

let b:caw_oneline_comment = '"'
let b:caw_hatpos_sp = {lnum -> getline(lnum) =~# '^\s*\\' ? "" : " "}
let b:caw_zeropos_sp = b:caw_hatpos_sp

if !exists("b:did_caw_ftplugin")
if exists('b:undo_ftplugin')
Expand Down
1 change: 1 addition & 0 deletions macros/after-ftplugin-template.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set cpo&vim
<ONELINE>
<WRAP_ONELINE>
<WRAP_MULTILINE>
<ADDITIONAL_VARS>

if !exists("b:did_caw_ftplugin")
if exists('b:undo_ftplugin')
Expand Down
20 changes: 20 additions & 0 deletions macros/generate-ftplugins.vim
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@ function! s:wrap_multiline() abort
\}
endfunction

function! s:additional_vars() abort
return {
\ 'vim': [
\ ['b:caw_hatpos_sp', '{lnum -> getline(lnum) =~# ''^\s*\\'' ? "" : " "}'],
\ ['b:caw_zeropos_sp', 'b:caw_hatpos_sp'],
\ ],
\}
endfunction


let s:root_dir = expand('<sfile>:h:h')
Expand Down Expand Up @@ -435,6 +443,7 @@ function! s:write_all() abort
let oneline = s:oneline()
let wrap_oneline = s:wrap_oneline()
let wrap_multiline = s:wrap_multiline()
let additional_vars = s:additional_vars()
let all_keys = s:sort_unique(
\ keys(oneline) + keys(wrap_oneline) + keys(wrap_multiline)
\)
Expand Down Expand Up @@ -468,6 +477,17 @@ function! s:write_all() abort
g/<WRAP_MULTILINE>/d
endif

" More additional variables
if has_key(additional_vars, filetype)
let additionals = []
for [k, v] in get(additional_vars, filetype)
let additionals += [printf('let %s = %s', k, v)]
endfor
%s@<ADDITIONAL_VARS>@\=join(additionals, "\n")@
else
g/<ADDITIONAL_VARS>/d
endif

write
endfor
endfunction
Expand Down

0 comments on commit dedb063

Please sign in to comment.