On 14/03/09 17:04 +0200, Agathoklis D. Hatzimanikas wrote:
> On Sat, Mar 14, at 06:27 Dasn wrote:
> >
> > Hi,
> > :h catch-interrupt
> > shows an example of catching interrupts, but it works not as it was
> > described. The document says:
> >
> > > If you press CTRL-C at the prompt, the script is terminated.
> >
> > But the problem is: when I press CTRL-C at the prompt, the script is not
> > terminated, instead, it will give you another prompt.
> >
> > How to catch the interrupts at 'input()' prompt?
>
> You can surround the try/endtry block with another try/endtry
> and use a catch to insert a break statement so you can get out of the
> loop.
>
Thanks for your reply, but I'm still not sure where to insert the
another try/endtry :)
The following is my try:
function! TASK1()
sleep 10
endfunction
function! TASK2()
sleep 20
endfunction
try
while 1
try
try
let command = input("Type a command: ")
catch /^Vim:Interrupt$/
break
endtry
catch /^Vim:Interrupt$/
break
endtry
try
if command == ""
continue
elseif command == "END"
break
elseif command == "TASK1"
call TASK1()
elseif command == "TASK2"
call TASK2()
else
echo "\nIllegal command:" command
continue
endif
catch /^Vim:Interrupt$/
echo "\nCommand interrupted"
break
" Caught the interrupt. Continue with next prompt.
endtry
endwhile
catch /^Vim:Interrupt$/
echo "\nCommand interrupted"
endtry
--
Dasn
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---