I have a function that accepts a count of iterations, its command
is defined with -range
:
command -nargs=1 -range DocbkPrintTag :call s:DocbkPrintTag(<f-args>)
and to output
<listitem>
<para>
</para>
</listitem>
I map it followingly:
nnoremap <unique> <localleader>li :<C-U>DocbkPrintTag li<CR>
the <listitem>
is defined in a custom dictionary as
let s:tags.li = { 'tag': 'listitem', 'type': 'outline', 'include': ['pa'] }
while <para>
['pa'] is defined as
let s:tags.pa = { 'tag': 'para', 'type': 'outline' }
The DocbkPrintTag
function calls another function DocbkRenderTag
which assembles the XML output for a tag, possibly rendering it n-times if count
is specified on a keyboard before the mapping itself.
The problem is that for the case of ,
I call DocbkRenderTag
recursively from itself to first render <para/>
as an inside element of <listitem/>
.
Everyhing works fine for 1 repetition, but if i want to print 2 or more such structures, the v:count1
parameter is passed over to the inner function calling
but the inner tag should be repeated only once. How can i force to do the inner function call only once?
For completeness, here is the important part of the code:
if !exists(":DocbkPrintTag")
command -nargs=1 -range DocbkPrintTag :call s:DocbkPrintTag(<f-args>)
endif
function s:DocbkPrintTag(tag)
let result = s:DocbkRenderTag(a:tag)
if !empty(result)
call feedkeys('a' . result, 'n')
endif
endfunction
function s:DocbkRenderTag(tag)
[...]
let result = ''
" number of repetitions
let i = 1
while i <= v:count1
[...]
if !empty(include)
for incl_tag in include
let incl_result .= s:DocbkRenderTag(incl_tag)
endfor
endif
[...]
endwhile
return result
endfunction
The output now is for example
<listitem><para></para><para></para></listitem>
<listitem><para></para><para></para></listitem>
instead of just
<listitem><para></para></listitem>
<listitem><para></para></listitem>
v:count1
. You should also describe how you invoke your command.