Commits

Meikel Brandmeyer committed 358a945

Move helper functions to util namespace

Comments (0)

Files changed (4)

vim/autoload/vimclojure.vim

 	endif
 endfunction
 
-function! vimclojure#SynIdName()
-	return synIDattr(synID(line("."), col("."), 0), "name")
-endfunction
-
-function! vimclojure#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#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#WithSaved(a:closure)
-endfunction
-
-function! vimclojure#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#WithSaved(a:closure)
-endfunction
-
-function! vimclojure#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#WithSaved(a:closure)
-endfunction
-
-function! vimclojure#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#WithSavedRegister(a:r, closure)
-endfunction
-
 function! vimclojure#EscapePathForOption(path)
 	let path = fnameescape(a:path)
 
 		let start = getpos(".")
 
 		if getline(start[1])[start[2] - 1] == "("
-					\ && vimclojure#SynIdName() =~ 'clojureParen' . self.level
+					\ && vimclojure#util#SynIdName() =~ 'clojureParen' . self.level
 			let pos = [start[1], start[2]]
 		endif
 
 		if pos == [0, 0]
 			let pos = searchpairpos('(', '', ')', 'bW' . self.flag,
-						\ 'vimclojure#SynIdName() !~ "clojureParen\\d"')
+						\ 'vimclojure#util#SynIdName() !~ "clojureParen\\d"')
 		endif
 
 		if pos == [0, 0]
 			throw "Error: Not in a s-expression!"
 		endif
 
-		return [pos, vimclojure#Yank('l', 'normal! "ly%')]
+		return [pos, vimclojure#util#Yank('l', 'normal! "ly%')]
 	endfunction
 
-	return vimclojure#WithSavedPosition(closure)
+	return vimclojure#util#WithSavedPosition(closure)
 endfunction
 
 function! vimclojure#BufferName()
 			return self.instance
 		endfunction
 
-		return vimclojure#WithSavedOption('switchbuf', closure)
+		return vimclojure#util#WithSavedOption('switchbuf', closure)
 	endif
 
 	let b:vimclojure_result_buffer = 1
 		return map(copy(self.vals), 'shellescape(v:val)')
 	endfunction
 
-	return vimclojure#WithSavedOption('shellslash', closure)
+	return vimclojure#util#WithSavedOption('shellslash', closure)
 endfunction
 
 function! vimclojure#ExecuteNailWithInput(nail, input, ...)
 		return line(".")
 	endfunction
 
-	let endPosition = vimclojure#WithSavedPosition(closure)
+	let endPosition = vimclojure#util#WithSavedPosition(closure)
 
 	let content = getbufline(bufnr("%"), startPosition, endPosition)
 	let result = vimclojure#ExecuteNailWithInput("Repl", content,
 		return ""
 	endif
 
-	let cmd = vimclojure#Yank("l", ln . "," . line("$") . "yank l")
+	let cmd = vimclojure#util#Yank("l", ln . "," . line("$") . "yank l")
 
 	let cmd = substitute(cmd, "^" . self._prompt . "\\s*", "", "")
 	let cmd = substitute(cmd, "\n$", "", "")
 		return col(".")
 	endfunction
 
-	if line(".") < line("$") || col(".") < vimclojure#WithSavedPosition(lastCol)
+	if line(".") < line("$") || col(".") < vimclojure#util#WithSavedPosition(lastCol)
 		call vimclojure#ReplDoEnter()
 		return
 	endif

vim/autoload/vimclojure/util.vim

+" Part of Vim filetype plugin for Clojure
+" Language:     Clojure
+" Maintainer:   Meikel Brandmeyer <mb@kotka.de>
+
+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
+
+" Epilog
+let &cpo = s:save_cpo

vim/ftplugin/clojure.vim

 	function closure.f() dict
 		execute self.lineno
 
-		if vimclojure#SynIdName() =~ 'clojureParen\d' && vimclojure#Yank('l', 'normal! "lyl') == '('
+		if vimclojure#util#SynIdName() =~ 'clojureParen\d' && vimclojure#util#Yank('l', 'normal! "lyl') == '('
 			return 1
 		endif
 
-		if searchpairpos('(', '', ')', 'bWr', 'vimclojure#SynIdName() !~ "clojureParen\\d"') != [0, 0]
+		if searchpairpos('(', '', ')', 'bWr', 'vimclojure#util#SynIdName() !~ "clojureParen\\d"') != [0, 0]
 			return 1
 		endif
 

vim/indent/clojure.vim

 	" Stop only on vector and map [ resp. {. Ignore the ones in strings and
 	" comments.
 	return searchpairpos(a:open, '', a:close, 'bWn',
-				\ 'vimclojure#SynIdName() !~ "clojureParen\\d"',
+				\ 'vimclojure#util#SynIdName() !~ "clojureParen\\d"',
 				\ a:stopat)
 endfunction
 
 
 	call cursor(nb, 0)
 	call cursor(0, col("$") - 1)
-	if vimclojure#SynIdName() != "clojureString"
+	if vimclojure#util#SynIdName() != "clojureString"
 		return -1
 	endif
 
 	" This will not work for a " in the first column...
-	if vimclojure#Yank('l', 'normal! "lyl') == '"'
+	if vimclojure#util#Yank('l', 'normal! "lyl') == '"'
 		call cursor(0, col("$") - 2)
-		if vimclojure#SynIdName() != "clojureString"
+		if vimclojure#util#SynIdName() != "clojureString"
 			return -1
 		endif
-		if vimclojure#Yank('l', 'normal! "lyl') != '\\'
+		if vimclojure#util#Yank('l', 'normal! "lyl') != '\\'
 			return -1
 		endif
 		call cursor(0, col("$") - 1)
 endfunction
 
 function! VimClojureCheckForString()
-	return vimclojure#WithSavedPosition({'f': function("VimClojureCheckForStringWorker")})
+	return vimclojure#util#WithSavedPosition({'f': function("VimClojureCheckForStringWorker")})
 endfunction
 
 function! GetClojureIndent()
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.