[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT - trivial programming language

"s. keeling" <keeling@spots.ab.ca> writes:

> Incoming from Faheem Mitha:
>> well. The bottom line is that in Python whitespace is syntatically
>> meaningful, in C etc. it is not.
>> This has the consequence that in C, emacs is able to correctly indent
>> the code, using the built-in syntax rules it knows about. This is very
>> useful since it shows up trivial syntax bugs right away.
> ... which is one of the reasons I truly enjoy coding in emacs.
>> On the other hand, much of the time emacs does not know what to do
>> with Python code (when in python mode, that is), since part of the
> This is surely a deficiency in emacs' python mode?

Well, Emacs can't read your mind.  Consider the following code:

    if a<b:
        print "foo"
    print "bar"

I have no idea whether this is real Python code, but I'm sure you
understand what I mean.  Now, if you hit TAB on the bar line, should
that move the line right or not?

It is clear that Emacs can't know.  Only the programmer can know.

>> synax info is encoded in the whitespace. Blindly hitting tab, which
>> works fine with C/C++ and probably most of the other languages out
>> there, can really mess up Python code.
> The same is true for shell-mode and perl-mode.

But for those modes, it's just a matter of parsing them correctly.
(CPerl-mode does a very good job for Perl, FWIW.)

For Python, it's an essential property of the language that
syntax-driven indentation can't work.  The reason is that
syntax-driven indentation means that the indentation is driven by the
syntax, but for Python, it's the other way round: the syntax is
driven by the indentation.


Reply to: