A vimscript template for a tidy work

To be continued...



" Last Change:	2021 04 10 
" Vimscript template 
" {{{1 README 
" Maintainer:	Johannes 'kefko' Köhler <Johannes.Koehler@web.de>
" License:	copyleft by gnu
" }}}1

if !has('vim9script')
set verbose:9
redir! > output-1.txt

0verbose let b:err = "DEBUG:LET" .. "…………………………………………………" .. '\n'
0verbose echom	b:err
0verbose execute 'let' 
0verbose let b:err = "END" .. "…………………………………………………" .. '\n'
0verbose echom	b:err
	
function s:Start() abort 

	"debug data 
	"……………………………………………………………………
	let s:x = 1

	"script data
	"……………………………………………………………………
	let s:usedVar = ['g:flag', 's:where', 's:wiki', 'g:check', 'g:n']
	"let s:usedFunc = ['s:test','s:test2']
	let s:usedBuf = ['g:testBuf', 's:bufer']
	"let s:usedAu 
	"let s:files
	let s:usedData = [s:usedVar, s:usedBuf]
	"del functions → dict
	let s:usedFunc = [function('s:Start')]

	"before main reset script data
	"4test: with a recursiv loop
	"……………………………………………………………………
	function s:ResetData() abort
		if len(s:usedData) != 0
			while len(s:usedData[0]) != 0
				if !exists(s:usedData[0][0])
					let b:cmd = 'let ' .. s:usedData[0][0] .. ' = v:null'
					execute b:cmd
					let b:err = "DEBUG:Data: " .. b:cmd
					echom	b:err
				else
					let b:cmd = 'unlet ' .. s:usedData[0][0] .. '|' .. 'let ' .. s:usedData[0][0] .. ' = v:null'
					execute b:cmd
					let b:err = "DEBUG:Data: " .. b:cmd
					echom	b:err
				endif
				call remove(s:usedData[0],0)
"				let b:break = input(s:x,'')	
				let b:err = "DEBUG:Counter: " .. len(s:usedData[0])
				echom	b:err
	 		endwhile
			call remove(s:usedData,0)
			call call('s:ResetData',[])
		else
			return
		endif
	endfunction

	call add(s:usedFunc,function('s:ResetData'))

"	if g:check == v:true

		"let b:break = input('debug 1','')	
		"redir => s:dirtxt
		"redir END
		"let b:break = input('debug 3','')	
		"let s:bufer = bufadd('TEST')
		"let s:bufName = bufname(s:bufer)
		"call bufload(s:bufer)
		"call appendbufline(s:bufName,1,s:dirtxt)

"	else
"		echo ERROR 
"	endif

	" Error → v:statusmsg, v:errmsg, v:exception
	let b:err = "DEBUG:ERROR: " .. v:errmsg
	echom	b:err

	call call('s:ResetData',[])

	"0verbose let g:debugBuf = bufadd('debug')
	"0verbose let g:debugBufName = bufname(g:debugBuf)
	"0verbose call bufload(g:debugBuf)
	"let g:check = bufloaded(g:testBufName)
	"0verbose let b:cmd = 'buffer! ' .. g:debugBuf
	"0verbose execute b:cmd
	"0verbose execute 'sblast'
	"0verbose execute 'bprevious'
	
"	:execute 'bp'
"	let s:cmd = 'bwipeout ' .. g:bufer
"	:execute s:cmd 
"	let s:cmd = 'bwipeout ' .. g:testBuf
"	:execute s:cmd

endfunction	

try 

	redir END | redir! > output-3.txt
	silent! 16verbose call call('s:Start',[]) 

	while len(s:usedFunc) != 0
		let b:break = input(s:x,'')	
 		delfunction! s:usedFunc[0]
		call remove(s:usedFunc,0)
#		let s:x += 1		
	endwhile

	redir END | redir! > output-2.txt
	0verbose let b:err = "DEBUG:LET" .. "…………………………………………………" .. '\n'
	0verbose echom	b:err
	0verbose execute 'let' 
	0verbose let b:err = "END" .. "…………………………………………………" .. '\n'
	0verbose echom	b:err
	redir END

finally

	unlet s:usedVar 
	unlet s:usedBuf 
	unlet s:usedData 
	unlet s:usedFunc 
	unlet s:x
	set verbose:0

endtry

endif