Meikel  Brandmeyer avatar Meikel Brandmeyer committed cf3f6ef

Remove usages of anonymous functions (reported by Dave Ray)

Fixes #88

Comments (0)

Files changed (4)

vim/autoload/vimclojure.vim

 	endif
 endfunction
 
+function! ClojureExtractSexprWorker() dict
+	let pos = [0, 0]
+	let start = getpos(".")
+
+	if getline(start[1])[start[2] - 1] == "("
+				\ && vimclojure#util#SynIdName() =~ 'clojureParen' . self.level
+		let pos = [start[1], start[2]]
+	endif
+
+	if pos == [0, 0]
+		let pos = searchpairpos('(', '', ')', 'bW' . self.flag,
+					\ 'vimclojure#util#SynIdName() !~ "clojureParen\\d"')
+	endif
+
+	if pos == [0, 0]
+		throw "Error: Not in a s-expression!"
+	endif
+
+	return [pos, vimclojure#util#Yank('l', 'normal! "ly%')]
+endfunction
+
 " Nailgun part:
 function! vimclojure#ExtractSexpr(toplevel)
 	let closure = {
 				\ "flag"  : (a:toplevel ? "r" : ""),
-				\ "level" : (a:toplevel ? "0" : '\d')
+				\ "level" : (a:toplevel ? "0" : '\d'),
+				\ "f"     : function("ClojureExtractSexprWorker")
 				\ }
 
-	function closure.f() dict
-		let pos = [0, 0]
-		let start = getpos(".")
-
-		if getline(start[1])[start[2] - 1] == "("
-					\ && vimclojure#util#SynIdName() =~ 'clojureParen' . self.level
-			let pos = [start[1], start[2]]
-		endif
-
-		if pos == [0, 0]
-			let pos = searchpairpos('(', '', ')', 'bW' . self.flag,
-						\ 'vimclojure#util#SynIdName() !~ "clojureParen\\d"')
-		endif
-
-		if pos == [0, 0]
-			throw "Error: Not in a s-expression!"
-		endif
-
-		return [pos, vimclojure#util#Yank('l', 'normal! "ly%')]
-	endfunction
-
 	return vimclojure#util#WithSavedPosition(closure)
 endfunction
 
 let vimclojure#ResultBuffer["__superBufferInit"] = vimclojure#ResultBuffer["Init"]
 let vimclojure#ResultBuffer.__instance = []
 
+function! ClojureResultBufferNewWorker() dict
+	set switchbuf=useopen
+	call self.instance.goHereWindow()
+	call call(self.instance.Init, self.args, self.instance)
+
+	return self.instance
+endfunction
+
 function! vimclojure#ResultBuffer.New(...) dict
 	if g:vimclojure#ResultBuffer.__instance != []
 		let closure = {
 					\ 'instance' : g:vimclojure#ResultBuffer.__instance[0],
 					\ 'args'     : a:000
+					\ 'f'        : function("ClojureResultBufferNewWorker")
 					\ }
-		function closure.f() dict
-			set switchbuf=useopen
-			call self.instance.goHereWindow()
-			call call(self.instance.Init, self.args, self.instance)
-
-			return self.instance
-		endfunction
 
 		return vimclojure#util#WithSavedOption('switchbuf', closure)
 	endif
 	let vimclojure#NailgunClient = "ng"
 endif
 
+function! ClojureShellEscapeArgumentsWorker() dict
+	set noshellslash
+	return map(copy(self.vals), 'shellescape(v:val)')
+endfunction
+
 function! vimclojure#ShellEscapeArguments(vals)
-	let closure = { 'vals': a:vals }
-
-	function closure.f() dict
-		set noshellslash
-		return map(copy(self.vals), 'shellescape(v:val)')
-	endfunction
+	let closure = {
+				\ 'vals': a:vals,
+				\ 'f'   : function("ClojureShellEscapeArgumentsWorker")
+				\ }
 
 	return vimclojure#util#WithSavedOption('shellslash', closure)
 endfunction
 	wincmd p
 endfunction
 
+function! ClojureEvalParagraphWorker() dict
+	normal! }
+	return line(".")
+endfunction
+
 function! vimclojure#EvalParagraph()
 	let file = vimclojure#BufferName()
 	let ns = b:vimclojure_namespace
 	let startPosition = line(".")
 
-	let closure = {}
-
-	function! closure.f() dict
-		normal! }
-		return line(".")
-	endfunction
+	let closure = { 'f' : function("ClojureEvalParagraphWorker") }
 
 	let endPosition = vimclojure#util#WithSavedPosition(closure)
 

vim/autoload/vimclojure/util.vim

 	return r
 endfunction
 
+function! s:SavePosition() dict
+	let [ _b, l, c, _o ] = getpos(".")
+	let b = bufnr("%")
+	return [b, l, c]
+endfunction
+
+function! s:RestorePosition(value) dict
+	let [b, l, c] = a:value
+
+	if bufnr("%") != b
+		execute b "buffer!"
+	endif
+	call setpos(".", [0, l, c, 0])
+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
+	let a:closure.save = function("s:SavePosition")
+	let a:closure.restore = function("s:RestorePosition")
 
 	return vimclojure#util#WithSaved(a:closure)
 endfunction
 
-function! vimclojure#util#SafeRegister(reg)
+function! s:SaveRegister(reg)
 	return [a:reg, getreg(a:reg, 1), getregtype(a:reg)]
 endfunction
 
+function! s:SaveRegisters() dict
+	return map([self._register, "", "/", "-",
+				\ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
+				\ "s:SaveRegister(v:val)")
+endfunction
+
+function! s:RestoreRegisters(registers) dict
+	for register in a:registers
+		call call(function("setreg"), register)
+	endfor
+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
+	let a:closure.save = function("s:SaveRegisters")
+	let a:closure.restore = function("s:RestoreRegisters")
 
 	return vimclojure#util#WithSaved(a:closure)
 endfunction
 
+function! s:SaveOption() dict
+	return eval("&" . self._option)
+endfunction
+
+function! s:RestoreOption(value) dict
+	execute "let &" . self._option . " = a:value"
+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
+	let a:closure.save = function("s:SaveOption")
+	let a:closure.restore = function("s:RestoreOption")
 
 	return vimclojure#util#WithSaved(a:closure)
 endfunction
 
+function! s:DoYank() dict
+	silent execute self.yank
+	return getreg(self.reg)
+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
+	let closure = {
+				\ 'reg': a:r,
+				\ 'yank': a:how,
+				\ 'f': function("s:DoYank")
+				\ }
 
 	return vimclojure#util#WithSavedRegister(a:r, closure)
 endfunction

vim/ftplugin/clojure.vim

 endfor
 
 " Define toplevel folding if desired.
+function! ClojureGetFoldingLevelWorker() dict
+	execute self.lineno
+
+	if vimclojure#util#SynIdName() =~ 'clojureParen\d' && vimclojure#util#Yank('l', 'normal! "lyl') == '('
+		return 1
+	endif
+
+	if searchpairpos('(', '', ')', 'bWr', 'vimclojure#util#SynIdName() !~ "clojureParen\\d"') != [0, 0]
+		return 1
+	endif
+
+	return 0
+endfunction
+
 function! ClojureGetFoldingLevel(lineno)
-	let closure = { 'lineno' : a:lineno }
-
-	function closure.f() dict
-		execute self.lineno
-
-		if vimclojure#util#SynIdName() =~ 'clojureParen\d' && vimclojure#util#Yank('l', 'normal! "lyl') == '('
-			return 1
-		endif
-
-		if searchpairpos('(', '', ')', 'bWr', 'vimclojure#util#SynIdName() !~ "clojureParen\\d"') != [0, 0]
-			return 1
-		endif
-
-		return 0
-	endfunction
+	let closure = {
+				\ 'lineno' : a:lineno,
+				\ 'f'      : function("ClojureGetFoldingLevelWorker")
+				\ }
 
 	return vimclojure#WithSavedPosition(closure)
 endfunction

vim/indent/clojure.vim

 				\ a:stopat)
 endfunction
 
-function! s:CheckForString()
-	let closure = {}
+function! ClojureCheckForStringWorker() dict
+	" Check whether there is the last character of the previous line is
+	" highlighted as a string. If so, we check whether it's a ". In this
+	" case we have to check also the previous character. The " might be the
+	" closing one. In case the we are still in the string, we search for the
+	" opening ". If this is not found we take the indent of the line.
+	let nb = prevnonblank(v:lnum - 1)
 
-	function closure.f() dict
-		" Check whether there is the last character of the previous line is
-		" highlighted as a string. If so, we check whether it's a ". In this
-		" case we have to check also the previous character. The " might be the
-		" closing one. In case the we are still in the string, we search for the
-		" opening ". If this is not found we take the indent of the line.
-		let nb = prevnonblank(v:lnum - 1)
+	if nb == 0
+		return -1
+	endif
 
-		if nb == 0
-			return -1
-		endif
+	call cursor(nb, 0)
+	call cursor(0, col("$") - 1)
+	if vimclojure#util#SynIdName() != "clojureString"
+		return -1
+	endif
 
-		call cursor(nb, 0)
-		call cursor(0, col("$") - 1)
+	" This will not work for a " in the first column...
+	if vimclojure#util#Yank('l', 'normal! "lyl') == '"'
+		call cursor(0, col("$") - 2)
 		if vimclojure#util#SynIdName() != "clojureString"
 			return -1
 		endif
+		if vimclojure#util#Yank('l', 'normal! "lyl') != '\\'
+			return -1
+		endif
+		call cursor(0, col("$") - 1)
+	endif
 
-		" This will not work for a " in the first column...
-		if vimclojure#util#Yank('l', 'normal! "lyl') == '"'
-			call cursor(0, col("$") - 2)
-			if vimclojure#util#SynIdName() != "clojureString"
-				return -1
-			endif
-			if vimclojure#util#Yank('l', 'normal! "lyl') != '\\'
-				return -1
-			endif
-			call cursor(0, col("$") - 1)
-		endif
+	let p = searchpos('\(^\|[^\\]\)\zs"', 'bW')
 
-		let p = searchpos('\(^\|[^\\]\)\zs"', 'bW')
+	if p != [0, 0]
+		return p[1] - 1
+	endif
 
-		if p != [0, 0]
-			return p[1] - 1
-		endif
+	return indent(".")
+endfunction
 
-		return indent(".")
-	endfunction
+function! s:CheckForString()
+	return vimclojure#util#WithSavedPosition({
+				\ 'f' : function("ClojureCheckForStringWorker")
+				\ })
+endfunction
 
-	return vimclojure#util#WithSavedPosition(closure)
+function! ClojureIsMethodSpecialCaseWorker() dict
+	" Find the next enclosing form.
+	call vimclojure#util#MoveBackward()
+
+	" Special case: we are at a '(('.
+	if vimclojure#util#Yank('l', 'normal! "lyl') == '('
+		return 0
+	endif
+	call cursor(self.pos)
+
+	let nextParen = s:MatchPairs('(', ')', 0)
+
+	" Special case: we are now at toplevel.
+	if nextParen == [0, 0]
+		return 0
+	endif
+	call cursor(nextParen)
+
+	call vimclojure#util#MoveForward()
+	let keyword = vimclojure#util#Yank('l', 'normal! "lye')
+	if index([ 'deftype', 'defrecord', 'reify', 'proxy',
+				\ 'extend', 'extend-type', 'extend-protocol',
+				\ 'letfn' ], keyword) >= 0
+		return 1
+	endif
+
+	return 0
 endfunction
 
 function! s:IsMethodSpecialCase(position)
-	let closure = { 'pos': a:position }
-
-	function closure.f() dict
-		" Find the next enclosing form.
-		call vimclojure#util#MoveBackward()
-
-		" Special case: we are at a '(('.
-		if vimclojure#util#Yank('l', 'normal! "lyl') == '('
-			return 0
-		endif
-		call cursor(self.pos)
-
-		let nextParen = s:MatchPairs('(', ')', 0)
-
-		" Special case: we are now at toplevel.
-		if nextParen == [0, 0]
-			return 0
-		endif
-		call cursor(nextParen)
-
-		call vimclojure#util#MoveForward()
-		let keyword = vimclojure#util#Yank('l', 'normal! "lye')
-		if index([ 'deftype', 'defrecord', 'reify', 'proxy',
-					\ 'extend', 'extend-type', 'extend-protocol',
-					\ 'letfn' ], keyword) >= 0
-			return 1
-		endif
-
-		return 0
-	endfunction
+	let closure = {
+				\ 'pos': a:position,
+				\ 'f' : function("ClojureIsMethodSpecialCaseWorker")
+				\ }
 
 	return vimclojure#util#WithSavedPosition(closure)
 endfunction
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.