git » msnlib » commit 2549bdc

Fix tab completion.

author Alberto Bertogli
2005-04-12 18:30:53 UTC
committer Alberto Bertogli
2005-04-12 18:30:53 UTC
parent 461ca9e1f85d19b3c2dc68d4a3a25cf726df28ee

Fix tab completion.

msn +9 -12

diff --git a/msn b/msn
index ecf8470..0b66820 100644
--- a/msn
+++ b/msn
@@ -381,29 +381,29 @@ def matchemail(begin, only_online = 0, start = 0):
 		start_from = 0
 
 	if start:
-		pos = start_from + 1
+		pos = (start_from + 1) % len(emails)
 	else:
-		pos = 0
+		pos = start_from
 
 	found = 0
 	while not found:
 		# we made a complete loop without matches
 		if start and pos == start_from:
 			break
-		elif pos == len(emails) - 1:
+		elif pos == (start_from - 1) % len(emails):
 			break
 
 		#msnlib.debug("l: %d %s\n" % (pos, emails[pos]))
 		current = emails[pos]
 		if only_online and m.users[current].status == 'FLN':
-				pos = (pos + 1) % len(emails)
-				continue
+			pos = (pos + 1) % len(emails)
+			continue
 		if findemailnick(emails[pos], begin):
 			found = 1
 			break
 		pos = (pos + 1) % len(emails)
 
-	start_from = pos + 1 % len(emails)
+	start_from = pos
 
 	if found:
 		if findemailnick(emails[pos], begin) == 1:
@@ -621,7 +621,6 @@ def stdin_read():
 				del(inbuf_history[0][0])
 			inbuf_history[0].append(inbuf[:-1])
 			inbuf_history[1] = len(inbuf_history[0]) - 1 # moves the pointer
-			start_from = 0 		# reset tab completion
 
 			safe_write(char)
 			tmpbuf = inbuf
@@ -730,7 +729,7 @@ def stdin_read():
 					if matchc_last == len(command_list):
 						matchc_last = 0
 						found = 0
-						break
+						continue
 					elif command_list[matchc_last].find(p[0]) == 0:
 						matchc_status = 2
 						matchc_root = p[0]
@@ -755,10 +754,8 @@ def stdin_read():
 				else:
 					matchp_root = pn
 					matchp_status = 2
-					p[len(p) -1] = email
-					inbuf = ''
-					for pi in p:
-						inbuf = inbuf + pi + ' '
+					pos = inbuf.rfind(' ')
+					inbuf = inbuf[:pos] + ' ' + email
 
 			redraw_cli()