if bufexists("CodeCommCommenting") != 0
bdelete! CodeCommCommenting
endif
- g:codecomm_count += 1
+
+ g:codecomm_ctr_ = -1
+ if filereadable(g:codecomm_ctr) | g:codecomm_ctr_ = str2nr(readfile(g:codecomm_ctr)[0]) | endif
+ g:codecomm_ctr_ += 1
# Determine file's path inside repository
var path = expand("%:p")
else
header = add(header, path)
endif
- var ready = [printf("-----#%2d [ %54S ]-----", g:codecomm_count, join(header, " "))]
+ var ready = [printf("-----#%2d [ %54S ]-----", g:codecomm_ctr_, join(header, " "))]
# Collect enumerated selected code block's lines
var fmted: string
setlocal noreadonly noswapfile buftype=acwrite filetype=codecomm
append(0, ready)
- # Separate codecomm_file consolidating function, called when buffer is saved
- # autocmd! BufWriteCmd CodeCommCommenting
autocmd! BufWriteCmd CodeCommCommenting {
var ccprev = [" vim: filetype=codecomm", ""]
- if filereadable(g:codecomm_file) | ccprev = readfile(g:codecomm_file) | endif
+ if filereadable(g:codecomm_txt) | ccprev = readfile(g:codecomm_txt) | endif
var ready = ccprev + getline(0, "$") + [""]
- writefile(ready, g:codecomm_file)
+ writefile(ready, g:codecomm_txt)
+ writefile([string(g:codecomm_ctr_)], g:codecomm_ctr)
setlocal nomodified
echohl MoreMsg | echomsg "Commented:" len(ready) "lines" | echohl None
}
enddef
export def Clear()
- writefile([], g:codecomm_file)
- g:codecomm_count = 0
+ delete(g:codecomm_txt)
+ delete(g:codecomm_ctr)
execute "sign unplace * buffer=" .. bufnr("%")
echohl WarningMsg | echomsg "Comments are wiped" | echohl None
enddef
with aggregated comments. By default it is /tmp/codecomm.txt.
You can override /tmp with $TMPDIR environment variable and the whole
file path with: >
- let g:codecomm_file = "/another/path.txt"
+ let g:codecomm_txt = "/another/path.txt"
+ let g:codecomm_ctr = "/another/path.ctr"
PLUGIN USAGE *codecomm-usage*
if exists("*codecomm#Do") | finish | endif
-if !exists("g:codecomm_file")
- g:codecomm_file = ((getenv("TMPDIR") == null) ? "/tmp" : getenv("TMPDIR")) ..
- "/" .. "codecomm.txt"
+if !exists("g:codecomm_txt")
+ var tmp = (getenv("TMPDIR") == null) ? "/tmp" : getenv("TMPDIR")
+ g:codecomm_txt = tmp .. "/" .. "codecomm.txt"
+ g:codecomm_ctr = tmp .. "/" .. "codecomm.ctr"
endif
-if !exists("g:codecomm_count") | g:codecomm_count = 0 | endif
-
function CCRangeWrapper() range
call codecomm#Do(a:firstline, a:lastline, FugitiveExtractGitDir(getcwd()))
endfunction
command! CodeCommClear codecomm#Clear()
-command! CodeCommEdit :execute "edit " .. g:codecomm_file
+command! CodeCommEdit :execute "edit " .. g:codecomm_txt
command! -range CodeComm <line1>, <line2> call <SID>CCRangeWrapper()
vnoremap <silent><Leader>cc :call <SID>CCRangeWrapper()<CR>