At the end of one of my files for loops stop being highlighted, aren't automatically indented when I enter them, and TAB won't indent four spaces either. I don't have this issue in any other of my python buffers. How do I figure out what's wrong, and how do I fix it?
If syntax highlighting or indentation suddenly stops working as expected at some point in your buffer/file, there's a very good chance you have a syntax error somewhere above it.
In these situations, the most straightforward way to identify the offending lines is to bisect your buffer/file recursively. What that means is to comment out all the material above the lines that are giving you problems. Uncomment one half. If the problem comes back, the error is probably somewhere in that half. Repeat the procedure in the offending half by uncommenting one half of the half until you isolate the error.
Note that this procedure is a common remedy for a problems in your init file, but the principle is similar for any source code.