Webdev: the times, they are a changin'

Levi Pearson levipearson at gmail.com
Thu Apr 19 12:43:19 MDT 2012

On Thu, Apr 19, 2012 at 12:04 PM, Andrew McNabb <amcnabb at mcnabbs.org> wrote:
> Indeed, auto-indent in Python makes about as much sense as
> auto-write-my-whole-program.

It's not quite that bad.  A Python-aware editor ought to be able to
reliably recognize when a block is expected and auto-insert an
appropriate block-opening token when you press enter, if you would
like it to.  It also ought to be able to determine the current indent
level of any line, even if the whitespace used to generate the indents
was inconsistent.  There's really no reason to get this stuff wrong
except for assumptions built into the code of existing editors that
would make it difficult.

>> I'm sorry that vim sucks at editing Python code.  This is not Python's
>> fault, though.
> Vim really doesn't suck for Python.  I use shift-v and > to indent a
> block and shift-v and < to dedent.  How is this any harder than going
> and adding the close brace?  The hard part is figuring out where your
> block ends, and you have to do that in any editor.

There's no fundamental reason that an editor shouldn't be able to find
the block delimiters of a currently well-formed program.  The problem
of Python is that some of its semantically-signficant tokens have
printed representations that consist entirely of whitespace
characters, and a variable but constrained number of them at that.
These are hard for humans to distinguish at a glance, and so operating
on a Python program on a purely textual basis can introduce errors
somewhat more easily than in a language that uses block delimiters
that are more easily textually-distinguished by humans and naive
editing scripts.

Apparently no one has bothered to implement the requisite smarts for
vim, and I'm not sure the vim editing model really has room for the
concept of higher-level constructs like blocks/paragraphs/etc. that
differ from one language to the next.  Vi and its kin excel at editing
documents at the purely textual level, and even editing at the regular
language level, but it does not make any generalized attempt to
recognize formal structure in documents beyond those matched by
whichever regex matcher it uses.  At least not that I'm aware of.


More information about the PLUG mailing list