Meikel  Brandmeyer avatar Meikel Brandmeyer committed 7e64a4c

Relearn whether server is started

Check on command execution if the server is started now. Then proceed
as normal. Otherwise give an informative error message.

Comments (0)

Files changed (3)

vim/autoload/vimclojure.vim

 				\ . a:f . "\"), [ " . a:args . " ])<CR>"
 endfunction
 
+function! vimclojure#MakeCommandPlug(mode, plug, f, args)
+	execute a:mode . "noremap <Plug>Clojure" . a:plug
+				\ . " :call vimclojure#ProtectedPlug("
+				\ . " function(\"vimclojure#CommandPlug\"),"
+				\ . " [ function(\"" . a:f . "\"), [ " . a:args . " ]])<CR>"
+endfunction
+
 function! vimclojure#MapPlug(mode, keys, plug)
 	if !hasmapto("<Plug>Clojure" . a:plug)
 		execute a:mode . "map <buffer> <unique> <silent> <LocalLeader>" . a:keys
 	endif
 endfunction
 
-function! vimclojure#MapCommandPlug(mode, keys, plug)
-	if exists("b:vimclojure_namespace")
-		call vimclojure#MapPlug(a:mode, a:keys, a:plug)
-	elseif g:vimclojure#WantNailgun == 1
-		let msg = ':call vimclojure#ReportError("VimClojure could not initialise the server connection.\n'
-					\ . 'That means you will not be able to use the interactive features.\n'
-					\ . 'Reasons might be that the server is not running or that there is\n'
-					\ . 'some trouble with the classpath.\n\n'
-					\ . 'VimClojure will *not* start the server for you or handle the classpath.\n'
-					\ . 'There is a plethora of tools like ivy, maven, gradle and leiningen,\n'
-					\ . 'which do this better than VimClojure could ever do it.")'
-		execute a:mode . "map <buffer> <silent> <LocalLeader>" . a:keys
-					\ . " " . msg . "<CR>"
-	endif
-endfunction
+if !exists("*vimclojure#CommandPlug")
+	function vimclojure#CommandPlug(f, args)
+		if exists("b:vimclojure_loaded")
+					\ && !exists("b:vimclojure_namespace")
+					\ && g:vimclojure#WantNailgun == 1
+			unlet b:vimclojure_loaded
+			call vimclojure#InitBuffer("silent")
+		endif
+
+		if exists("b:vimclojure_namespace")
+			call call(a:f, a:args)
+		elseif g:vimclojure#WantNailgun == 1
+			let msg = "VimClojure could not initialise the server connection.\n"
+						\ . "That means you will not be able to use the interactive features.\n"
+						\ . "Reasons might be that the server is not running or that there is\n"
+						\ . "some trouble with the classpath.\n\n"
+						\ . "VimClojure will *not* start the server for you or handle the classpath.\n"
+						\ . "There is a plethora of tools like ivy, maven, gradle and leiningen,\n"
+						\ . "which do this better than VimClojure could ever do it."
+			throw msg
+		endif
+	endfunction
+endif
 
 if !exists("*vimclojure#ProtectedPlug")
 	function vimclojure#ProtectedPlug(f, args)
 	endif
 endfunction
 
-function! vimclojure#InitBuffer()
+function! vimclojure#InitBuffer(...)
 	if exists("b:vimclojure_loaded")
 		return
 	endif
 					endif
 					let b:vimclojure_namespace = namespace.value
 				catch /.*/
-					call vimclojure#ReportError(
-								\ "Could not determine the Namespace of the file.\n\n"
-								\ . "This might have different reasons. Please check, that the ng server\n"
-								\ . "is running with the correct classpath and that the file does not contain\n"
-								\ . "syntax errors. The interactive features will not be enabled, ie. the\n"
-								\ . "keybindings will not be mapped.\n\nReason:\n" . v:exception)
+					if a:000 == []
+						call vimclojure#ReportError(
+									\ "Could not determine the Namespace of the file.\n\n"
+									\ . "This might have different reasons. Please check, that the ng server\n"
+									\ . "is running with the correct classpath and that the file does not contain\n"
+									\ . "syntax errors. The interactive features will not be enabled, ie. the\n"
+									\ . "keybindings will not be mapped.\n\nReason:\n" . v:exception)
+					endif
 				endtry
 			endif
 		endif

vim/ftplugin/clojure.vim

 call vimclojure#MapPlug("n", "aw", "AddToLispWords")
 call vimclojure#MapPlug("n", "tr", "ToggleParenRainbow")
 
-call vimclojure#MapCommandPlug("n", "lw", "DocLookupWord")
-call vimclojure#MapCommandPlug("n", "li", "DocLookupInteractive")
-call vimclojure#MapCommandPlug("n", "jw", "JavadocLookupWord")
-call vimclojure#MapCommandPlug("n", "ji", "JavadocLookupInteractive")
-call vimclojure#MapCommandPlug("n", "fd", "FindDoc")
+call vimclojure#MapPlug("n", "lw", "DocLookupWord")
+call vimclojure#MapPlug("n", "li", "DocLookupInteractive")
+call vimclojure#MapPlug("n", "jw", "JavadocLookupWord")
+call vimclojure#MapPlug("n", "ji", "JavadocLookupInteractive")
+call vimclojure#MapPlug("n", "fd", "FindDoc")
 
-call vimclojure#MapCommandPlug("n", "mw", "MetaLookupWord")
-call vimclojure#MapCommandPlug("n", "mi", "MetaLookupInteractive")
+call vimclojure#MapPlug("n", "mw", "MetaLookupWord")
+call vimclojure#MapPlug("n", "mi", "MetaLookupInteractive")
 
-call vimclojure#MapCommandPlug("n", "sw", "SourceLookupWord")
-call vimclojure#MapCommandPlug("n", "si", "SourceLookupInteractive")
+call vimclojure#MapPlug("n", "sw", "SourceLookupWord")
+call vimclojure#MapPlug("n", "si", "SourceLookupInteractive")
 
-call vimclojure#MapCommandPlug("n", "gw", "GotoSourceWord")
-call vimclojure#MapCommandPlug("n", "gi", "GotoSourceInteractive")
+call vimclojure#MapPlug("n", "gw", "GotoSourceWord")
+call vimclojure#MapPlug("n", "gi", "GotoSourceInteractive")
 
-call vimclojure#MapCommandPlug("n", "rf", "RequireFile")
-call vimclojure#MapCommandPlug("n", "rF", "RequireFileAll")
+call vimclojure#MapPlug("n", "rf", "RequireFile")
+call vimclojure#MapPlug("n", "rF", "RequireFileAll")
 
-call vimclojure#MapCommandPlug("n", "rt", "RunTests")
+call vimclojure#MapPlug("n", "rt", "RunTests")
 
-call vimclojure#MapCommandPlug("n", "me", "MacroExpand")
-call vimclojure#MapCommandPlug("n", "m1", "MacroExpand1")
+call vimclojure#MapPlug("n", "me", "MacroExpand")
+call vimclojure#MapPlug("n", "m1", "MacroExpand1")
 
-call vimclojure#MapCommandPlug("n", "ef", "EvalFile")
-call vimclojure#MapCommandPlug("n", "el", "EvalLine")
-call vimclojure#MapCommandPlug("v", "eb", "EvalBlock")
-call vimclojure#MapCommandPlug("n", "et", "EvalToplevel")
-call vimclojure#MapCommandPlug("n", "ep", "EvalParagraph")
+call vimclojure#MapPlug("n", "ef", "EvalFile")
+call vimclojure#MapPlug("n", "el", "EvalLine")
+call vimclojure#MapPlug("v", "eb", "EvalBlock")
+call vimclojure#MapPlug("n", "et", "EvalToplevel")
+call vimclojure#MapPlug("n", "ep", "EvalParagraph")
 
-call vimclojure#MapCommandPlug("n", "sr", "StartRepl")
-call vimclojure#MapCommandPlug("n", "sR", "StartLocalRepl")
+call vimclojure#MapPlug("n", "sr", "StartRepl")
+call vimclojure#MapPlug("n", "sR", "StartLocalRepl")
 
 if exists("b:vimclojure_namespace")
 	setlocal omnifunc=vimclojure#OmniCompletion

vim/plugin/clojure.vim

 call vimclojure#MakeProtectedPlug("n", "AddToLispWords", "vimclojure#AddToLispWords", "expand(\"<cword>\")")
 call vimclojure#MakeProtectedPlug("n", "ToggleParenRainbow", "vimclojure#ToggleParenRainbow", "")
 
-call vimclojure#MakeProtectedPlug("n", "DocLookupWord", "vimclojure#DocLookup", "expand(\"<cword>\")")
-call vimclojure#MakeProtectedPlug("n", "DocLookupInteractive", "vimclojure#DocLookup", "input(\"Symbol to look up: \")")
-call vimclojure#MakeProtectedPlug("n", "JavadocLookupWord", "vimclojure#JavadocLookup", "expand(\"<cword>\")")
-call vimclojure#MakeProtectedPlug("n", "JavadocLookupInteractive", "vimclojure#JavadocLookup", "input(\"Class to lookup: \")")
-call vimclojure#MakeProtectedPlug("n", "FindDoc", "vimclojure#FindDoc", "")
+call vimclojure#MakeCommandPlug("n", "DocLookupWord", "vimclojure#DocLookup", "expand(\"<cword>\")")
+call vimclojure#MakeCommandPlug("n", "DocLookupInteractive", "vimclojure#DocLookup", "input(\"Symbol to look up: \")")
+call vimclojure#MakeCommandPlug("n", "JavadocLookupWord", "vimclojure#JavadocLookup", "expand(\"<cword>\")")
+call vimclojure#MakeCommandPlug("n", "JavadocLookupInteractive", "vimclojure#JavadocLookup", "input(\"Class to lookup: \")")
+call vimclojure#MakeCommandPlug("n", "FindDoc", "vimclojure#FindDoc", "")
 
-call vimclojure#MakeProtectedPlug("n", "MetaLookupWord", "vimclojure#MetaLookup", "expand(\"<cword>\")")
-call vimclojure#MakeProtectedPlug("n", "MetaLookupInteractive", "vimclojure#MetaLookup", "input(\"Symbol to look up: \")")
+call vimclojure#MakeCommandPlug("n", "MetaLookupWord", "vimclojure#MetaLookup", "expand(\"<cword>\")")
+call vimclojure#MakeCommandPlug("n", "MetaLookupInteractive", "vimclojure#MetaLookup", "input(\"Symbol to look up: \")")
 
-call vimclojure#MakeProtectedPlug("n", "SourceLookupWord", "vimclojure#SourceLookup", "expand(\"<cword>\")")
-call vimclojure#MakeProtectedPlug("n", "SourceLookupInteractive", "vimclojure#SourceLookup", "input(\"Symbol to look up: \")")
+call vimclojure#MakeCommandPlug("n", "SourceLookupWord", "vimclojure#SourceLookup", "expand(\"<cword>\")")
+call vimclojure#MakeCommandPlug("n", "SourceLookupInteractive", "vimclojure#SourceLookup", "input(\"Symbol to look up: \")")
 
-call vimclojure#MakeProtectedPlug("n", "GotoSourceWord", "vimclojure#GotoSource", "expand(\"<cword>\")")
-call vimclojure#MakeProtectedPlug("n", "GotoSourceInteractive", "vimclojure#GotoSource", "input(\"Symbol to go to: \")")
+call vimclojure#MakeCommandPlug("n", "GotoSourceWord", "vimclojure#GotoSource", "expand(\"<cword>\")")
+call vimclojure#MakeCommandPlug("n", "GotoSourceInteractive", "vimclojure#GotoSource", "input(\"Symbol to go to: \")")
 
-call vimclojure#MakeProtectedPlug("n", "RequireFile", "vimclojure#RequireFile", "0")
-call vimclojure#MakeProtectedPlug("n", "RequireFileAll", "vimclojure#RequireFile", "1")
+call vimclojure#MakeCommandPlug("n", "RequireFile", "vimclojure#RequireFile", "0")
+call vimclojure#MakeCommandPlug("n", "RequireFileAll", "vimclojure#RequireFile", "1")
 
-call vimclojure#MakeProtectedPlug("n", "RunTests", "vimclojure#RunTests", "0")
+call vimclojure#MakeCommandPlug("n", "RunTests", "vimclojure#RunTests", "0")
 
-call vimclojure#MakeProtectedPlug("n", "MacroExpand",  "vimclojure#MacroExpand", "0")
-call vimclojure#MakeProtectedPlug("n", "MacroExpand1", "vimclojure#MacroExpand", "1")
+call vimclojure#MakeCommandPlug("n", "MacroExpand",  "vimclojure#MacroExpand", "0")
+call vimclojure#MakeCommandPlug("n", "MacroExpand1", "vimclojure#MacroExpand", "1")
 
-call vimclojure#MakeProtectedPlug("n", "EvalFile",      "vimclojure#EvalFile", "")
-call vimclojure#MakeProtectedPlug("n", "EvalLine",      "vimclojure#EvalLine", "")
-call vimclojure#MakeProtectedPlug("v", "EvalBlock",     "vimclojure#EvalBlock", "")
-call vimclojure#MakeProtectedPlug("n", "EvalToplevel",  "vimclojure#EvalToplevel", "")
-call vimclojure#MakeProtectedPlug("n", "EvalParagraph", "vimclojure#EvalParagraph", "")
+call vimclojure#MakeCommandPlug("n", "EvalFile",      "vimclojure#EvalFile", "")
+call vimclojure#MakeCommandPlug("n", "EvalLine",      "vimclojure#EvalLine", "")
+call vimclojure#MakeCommandPlug("v", "EvalBlock",     "vimclojure#EvalBlock", "")
+call vimclojure#MakeCommandPlug("n", "EvalToplevel",  "vimclojure#EvalToplevel", "")
+call vimclojure#MakeCommandPlug("n", "EvalParagraph", "vimclojure#EvalParagraph", "")
 
-call vimclojure#MakeProtectedPlug("n", "StartRepl", "vimclojure#StartRepl", "")
-call vimclojure#MakeProtectedPlug("n", "StartLocalRepl", "vimclojure#StartRepl", "b:vimclojure_namespace")
+call vimclojure#MakeCommandPlug("n", "StartRepl", "vimclojure#StartRepl", "")
+call vimclojure#MakeCommandPlug("n", "StartLocalRepl", "vimclojure#StartRepl", "b:vimclojure_namespace")
 
 inoremap <Plug>ClojureReplEnterHook <Esc>:call b:vimclojure_repl.enterHook()<CR>
 inoremap <Plug>ClojureReplUpHistory <C-O>:call b:vimclojure_repl.upHistory()<CR>
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.