rem Known bugs:
rem  - First character isn't recognizable
rem  - Enters don't work (So I turned this of with the help of :Entermenu)
rem  - If you change the window when you pressed TAB there is a change
rem    that the window will be hidden, and then a second later just appears...
	 
list create,1
rem First line must be empty.
rem First character must be a | so the script will search only the begin of a 
rem character.
list loadfile,1,@path(%0)autocomplete.txt

  DIALOG CREATE,Auto-complete...,-1,0,369,160
  DIALOG ADD,EDIT,EDIT1,0,0,368,128,,MULTI,WRAP,SCROLL
  DIALOG ADD,EDIT,EDIT2,136,128,240,16,,READONLY
  DIALOG ADD,MENU,-,Complete|Tab,Enter|Enter
  DIALOG ADD,TEXT,TEXT1,136,0,,,Press TAB to complete to:
  DIALOG SHOW
  
%%edit1text = @dlgtext(edit1)  

:evloop
%%event = @event()
if @not(@null(%%event))
  goto %%event
  end

%%edit1text = @dlgtext(edit1)  

if @not(@equal(%%edit1text,%%edit1textold))
  %%edit1textold = %%edit1text
  %%text = %%edit1textold
  %z = @item(1,0)

if @equal(@pos(@chr(32),%%text),)
  %%text = %%edit1text
  else
  repeat
  %%text = @strdel(%%text,1,@diff(@pos(@chr(32),%%text),1))
  %%space = @pos(@chr(32),%%text)
  until @equal(%%space,0)
rem ---------------------------------------------------------
  if @equal(@pos(@chr(10),%%text),)
    repeat
    %%text = @strdel(%%text,1,@diff(@pos(@chr(10),%%text),1))  
    %%return = @pos(@chr(10),%%text)
    until @equal(%%return,0)
    end
rem ---------------------------------------------------------
  end

  if @match(1,|%%text)
    if @greater(@len(%%text),0)
	  
      dialog set,edit2,@substr(@item(1),2,999)
	  
	  else
	  dialog set,edit2,
	  end
	end
  end  

goto evloop

:Completemenu
%%textlenght = @len(%%text)

  if @match(1,|%%text)
    if @greater(@len(%%text),0) 
	  dialog set,edit1,@substr(@dlgtext(edit1),1,@diff(@len(@dlgtext(edit1)),%%textlenght))@substr(@item(1),2,999)
	  dialog focus,edit1
	  window send,@winexists(Auto-complete...),@key(end)
	  end
	end
  end 
  
goto evloop

:Entermenu
warn No enters allowed...
goto evloop

:Close
exit    