<commit_before>" Part of Vim filetype plugin for Clojure
" Language:     Clojure
" Maintainer:   <NAME> <<EMAIL>>

let s:save_cpo = &cpo
set cpo&vim

function! vimclojure#util#SynIdName()
	return synIDattr(synID(line("."), col("."), 0), "name")
endfunction

function! vimclojure#util#WithSaved(closure)
	let v = a:closure.save()
	try
		let r = a:closure.f()
	finally
		call a:closure.restore(v)
	endtry
	return r
endfunction

function! vimclojure#util#WithSavedPosition(closure)
	function a:closure.save() dict
		let [ _b, l, c, _o ] = getpos(".")
		let b = bufnr("%")
		return [b, l, c]
	endfunction

	function a:closure.restore(value) dict
		let [b, l, c] = a:value

		if bufnr("%") != b
			execute b "buffer!"
		endif
		call setpos(".", [0, l, c, 0])
	endfunction

	return vimclojure#util#WithSaved(a:closure)
endfunction

function! vimclojure#util#WithSavedRegister(reg, closure)
	let a:closure._register = a:reg

	function a:closure.save() dict
		return [getreg(self._register, 1), getregtype(self._register)]
	endfunction

	function a:closure.restore(value) dict
		call call(function("setreg"), [self._register] + a:value)
	endfunction

	return vimclojure#util#WithSaved(a:closure)
endfunction

function! vimclojure#util#WithSavedOption(option, closure)
	let a:closure._option = a:option

	function a:closure.save() dict
		return eval("&" . self._option)
	endfunction

	function a:closure.restore(value) dict
		execute "let &" . self._option . " = a:value"
	endfunction

	return vimclojure#util#WithSaved(a:closure)
endfunction

function! vimclojure#util#Yank(r, how)
	let closure = {'reg': a:r, 'yank': a:how}

	function closure.f() dict
		silent execute self.yank
		return getreg(self.reg)
	endfunction

	return vimclojure#util#WithSavedRegister(a:r, closure)
endfunction

function! vimclojure#util#MoveBackward()
	call search('\S', 'Wb')
endfunction

function! vimclojure#util#MoveForward()
	call search('\S', 'W')
endfunction

" Epilog
let &cpo = s:save_cpo
<commit_msg>Be more defensive with registers (reported by Dave Ray)<commit_after>" Part of Vim filetype plugin for Clojure
" Language:     Clojure
" Maintainer:   <NAME> <<EMAIL>>

let s:save_cpo = &cpo
set cpo&vim

function! vimclojure#util#SynIdName()
	return synIDattr(synID(line("."), col("."), 0), "name")
endfunction

function! vimclojure#util#WithSaved(closure)
	let v = a:closure.save()
	try
		let r = a:closure.f()
	finally
		call a:closure.restore(v)
	endtry
	return r
endfunction

function! vimclojure#util#WithSavedPosition(closure)
	function a:closure.save() dict
		let [ _b, l, c, _o ] = getpos(".")
		let b = bufnr("%")
		return [b, l, c]
	endfunction

	function a:closure.restore(value) dict
		let [b, l, c] = a:value

		if bufnr("%") != b
			execute b "buffer!"
		endif
		call setpos(".", [0, l, c, 0])
	endfunction

	return vimclojure#util#WithSaved(a:closure)
endfunction

function! vimclojure#util#SafeRegister(reg)
	return [a:reg, getreg(a:reg, 1), getregtype(a:reg)]
endfunction

function! vimclojure#util#WithSavedRegister(reg, closure)
	let a:closure._register = a:reg

	function a:closure.save() dict
		return map([self._register, "", "/", "-",
					\ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
					\ "vimclojure#util#SafeRegister(v:val)")
	endfunction

	function a:closure.restore(registers) dict
		for register in a:registers
			call call(function("setreg"), register)
		endfor
	endfunction

	return vimclojure#util#WithSaved(a:closure)
endfunction

function! vimclojure#util#WithSavedOption(option, closure)
	let a:closure._option = a:option

	function a:closure.save() dict
		return eval("&" . self._option)
	endfunction

	function a:closure.restore(value) dict
		execute "let &" . self._option . " = a:value"
	endfunction

	return vimclojure#util#WithSaved(a:closure)
endfunction

function! vimclojure#util#Yank(r, how)
	let closure = {'reg': a:r, 'yank': a:how}

	function closure.f() dict
		silent execute self.yank
		return getreg(self.reg)
	endfunction

	return vimclojure#util#WithSavedRegister(a:r, closure)
endfunction

function! vimclojure#util#MoveBackward()
	call search('\S', 'Wb')
endfunction

function! vimclojure#util#MoveForward()
	call search('\S', 'W')
endfunction

" Epilog
let &cpo = s:save_cpo

{'fraction_non_alphanumeric': 0.14380478559583038, 'fraction_numerical': 0.0042643923240938165, 'mean_word_length': 5.2179675994108985, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3846567', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1597, 'n_words': 375}