Friday, March 25, 2011

Execute script commands after ctrl-C?

Hi,

I wrote a little script that launces a browser or email client for the word
under the cursor, after checking that the word is, indeed an email address or
URL. Works fine, if you exit the browser or email normally.

But if you interrupt the shell with ctrl-C when in the browser, I reenter my
vim session, with the error message, ``exiting via interrupt 2'' , and the
screen ls blanked out. i must hit ctrl-l or :redraw! to see the contents of
the buffer.

My problem is how to get vim to automatically execute ctrl-l or :redraw!
after the shell command, or after a ctrl-C. For reasons better left unsaid,
this is for vim version 6.4 which does not include the autocommand,
ShellCmdPost. It seems that if I define a function with a shell command, vim
does not execute added commands in this function that are placed after the
shell command. I tried to use FileChangedShell with touch. But vim does not
execute this autocommand after a ctrl-C (see below). Any suggestions?

Here is the function:

function! Browser ()
let word0 = expand("<cWORD>")
let word0 = escape (word0, "#?&;|%")
let word = matchstr(word0, '^\(http\|www\|ftp\)[^ ]\+')
let program = "/opt/csw/bin/lynx -show_cursor"
:if word == ''
let word = matchstr(word0, '^[^ ]\+@[^ ]\+')
let program = "pine"
:endif
:if word == ''
echo word0 'is not a URL or email address'
let program = ''
else
:au FileChangedShell * :redraw!
:silent exec "!" program word
:silent ! touch -f %
:endif
endfunction
nmap ,x :call Browser ()^M

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment