Function editing with Vim throws IndentError

Asun Friere afriere at yahoo.co.uk
Tue Jul 22 21:39:22 EDT 2008


On Jul 23, 7:02 am, ptn <tn.pa... at gmail.com> wrote:
> Hi everybody,
>
> I have a weird problem.  Say I have a .py file with some functions in
> it, like this:
>
>     # (...)
>     def foo():
>         print("bar")
>
> When I open it and add a line to one of the functions,
>
>     # (...)
>     def foo():
>         troz = "bar"
>         print(troz)
>
> I get the following traceback from the interpreter:
>
>     Traceback (most recent call last):
>       File "SOMEWHERE/example.py", line ??
>         troz = "bar"
>                           ^
>     IndentationError: unindent does not match any outer indentation
> level
>
> And so I'm forced to rewrite the function entirely just to add the new
> line.
>
> I thought that my problem was the w option from formatoptions, so I
> changed my .vimrc file to this:
>
>     augroup filetype
>       autocmd BufNewFile,BufRead *.txt set filetype=human
>     augroup END
>     autocmd FileType human setlocal formatoptions+=ta2w
>     autocmd FileType lisp,scheme,python,c,java,vim setlocal
> formatoptions-=ta2w
>
> But the problem didn't go away.

It doesn't look like those formatoptions would be called when the
filetype is python.  Or am I missing something?

> I don't think this has anything to do
> with the tabs and spaces, because I have them set up like this:
>
>     set tabstop=4 shiftwidth=4 expandtab
>
> which is the standard way to handle them.

Did you actually search for tabs (/\t)?  If the file was orginally
edited without expandtabs and later expandtabs was used this is
exactly the sort of problem you would encounter.

Also you don't need to set tabstop if you in- and de-dented using
[ctrl]-[t] and [ctrl]-[d] in insert mode, and '>>' and '<<' in command
mode.

>
> The scripts I load are: qbuf, TagList, indent/python.vim and a reduced
> version of the standard python.vim
>
> Could someone provide some pointers?
>
> Thanks,
>
> Pablo Torres N.




More information about the Python-list mailing list