Meikel  Brandmeyer avatar Meikel Brandmeyer committed 8047c87

Added Repl.showPrompt() and fixed infinite loop for missing prompt

Comments (0)

Files changed (1)

autoload/vimclojure.vim

 	endif
 endfunction
 
+function! vimclojure#Repl.showPrompt() dict
+	call self.showText(self._prompt . " ")
+	normal G
+	startinsert!
+endfunction
+
 function! vimclojure#Repl.getCommand() dict
 	let ln = line("$")
 
-	while getline(ln) !~ "^" . self._prompt
+	while getline(ln) !~ "^" . self._prompt && ln > 0
 		let ln = ln - 1
 	endwhile
 
+	" Special Case: User deleted Prompt by accident. Insert a new one.
+	if ln == 0
+		call self.showPrompt()
+		return ""
+	endif
+
 	let cmd = vimclojure#Yank("l", ln . "," . line("$") . "yank l")
 
 	let cmd = substitute(cmd, "^" . self._prompt . "\\s*", "", "")
 function! vimclojure#Repl.enterHook() dict
 	let cmd = self.getCommand()
 
+	" Special Case: Showed prompt (or user just hit enter).
+	if cmd == ""
+		return
+	endif
+
 	if self.isReplCommand(cmd)
 		call self.doReplCommand(cmd)
 		return
 	if result == "false"
 		execute "normal! GA\<CR>x"
 		normal ==x
+		startinsert!
 	else
 		let result = vimclojure#ExecuteNailWithInput("Repl", cmd,
 					\ "-r", "-i", self._id)
 
 		let self._historyDepth = 0
 		let self._history = [cmd] + self._history
-		call self.showText(self._prompt . " ")
-		normal G
+		call self.showPrompt()
 	endif
-	startinsert!
 endfunction
 
 function! vimclojure#Repl.upHistory() dict
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.