On Thu, Jul 06, 2006 at 06:15:21PM +0100, J Alan Brogan wrote:
> Hi all,
>
> I have a problem when scripting vim with python which is not covered by the
> FAQ (http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl), and would be
> grateful for help (or perhaps a redirect to a list more directly connected
> to vim scripting ?)
>
> I am using vim 7.0, and python 2.4.2
>
> I have vim (or gvim) running with a python script in the current buffer and
> try to parse it. When parse errors occur I would like to move to the line
> with the error, and then ask the user what to do about it (or maybe just
> explain what the error is if I ain't no clue what to do).
>
> So, bypassing a few key-redirects, and extra scripting what happens is
> essentially:
[snip]
> ie: compile the contents of current buffer, if there is an error, find
> row/col, go to that row, then if the error is a missing colon, ask whether
> it should be added.
It looks as though you have already put a lot of work into this
approach, but have you considered using quickfix mode?
:help quickfix
[snip]
> I have also seen the same effect with output, for example
> normal('%dG0%dl' % (row,col))
> # other stuff
> print "hello world"
> and
> normal('%dG0%dl' % (row,col))
> # other stuff
> print >> sys.stderr, "hello world"
> it can be seen that the (error) message is printed first, and later the
> cursor moves.
>
> Any suggestions as to where I might be going wrong, and how I can get the
> instructions to appear back in the right order ?
Ah, now this is an example I can handle. I think that the cursor
is moving before the print command, but you do not see it until the
screen is redrawn, which happens later. I tried
:python << EOF
import vim
def normal(command):
vim.command('normal %s' % command)
cw = vim.current.window
print cw.cursor
normal('1G01l')
print cw.cursor
EOF
and I got
(97,1)
(1,1)
Can you construct a similarly simple example with a more convincing
problem?
HTH --Benji Fisher