special editor support for indentation needed.

Aaron Brady castironpi at gmail.com
Fri Nov 14 22:08:38 EST 2008


On Nov 14, 8:01 pm, "Eric S. Johansson" <e... at harvee.org> wrote:
> drobi... at gmail.com wrote:
> >  I don't understand. If you don't want to terminate the "if", why do
> > you hit backspace? What is it that you would like to have happen?
>
> the goal is to make some aspects of indentation behave the same without context
> dependency.  this goal exists for many features of programming assistance
> because it's a prerequisite for lowering the vocal load for this aspect of
> programming by voice
>
> I want three indentation adjustment tools.  Indent to where a class should be,
> indent to where a method should be, and outdent n levels (close block
> (once|twice|thrice)).  This is probably best shown by example although, I'm not
> guaranteeing my example will make it any clearer.  :-)
>
> the current outdent capability conflates multiple outdent events.  The outdent
> events are, at a minimum,:
>
> Close block
> close method
> close class
>
> Another way to look at these events are start method, start class and close
> block.  Now using these events, let's compare a use case against the outdent
> mechanism.
>
> starting with an example of a previous message,
>
> class pet (object):
>     """
>     """
>     def cat(self):
>         """
>         """
>         if food in bowl:
>             self.empty = True
>
>     def dog(self):
>
> to start the dog method, after ending the Method, I would need to say something
> like:
>
> newline tab key Close block close block delta echo foxtrot dog left paren self
> close paren colon...
>
> But if the method ended like:
>
>     ...
>
>     def cat(self):
>         """
>         """
>         self.empty = True
>
>     def dog(self):
>
> I would only want to use a single "close block" to outdent.  unfortunately, this
>  context dependent behavior is frustratingly wrong when it comes to creating
> speech driven macros to enter templates.  it requires user intervention to tell
> you how may times to outdent and that's counterproductive at best and physically
> damaging at worst for a disabled user.
>
> any clearer?

Greetings, Eric, great to read your posts.

You'll acknowledge that there is no deterministic way to add newlines
to a string of Python code.  That is, the following are all equivalent
up to whitespace, syntactically correct, and distinct.

def cat(self):
    ""
    if food in bowl:
        self.empty = True
def dog(self):
    ...

def cat(self):
    ""
    if food in bowl:
        self.empty = True
    def dog(self):
        ...

def cat(self):
    ""
    if food in bowl:
        self.empty = True
        def dog(self):
            ...

def cat(self):
    ""
if food in bowl:
    self.empty = True
def dog(self):
    ...

def cat(self):
    ""
if food in bowl:
    self.empty = True
    def dog(self):
        ...

You noticed that the second-to-last one uses a variable that isn't
guaranteed to be defined.

You instructed the audience to imagine reading with its eyes closed.
I imagined concluding the "self.empty= True" line, saying 'close
block' aloud, and hearing a verbal prompt in response.

'Close block def or block if?'

Uttering 'if' in response, results in a dedent by one level, and 'def'
causes a dedent by two levels.  If these statements are occurring in a
class statement, you could expect a prompt:

'Close block class, block def, or block if?'

A more elaborate program structure might require this prompt:

'Close block class, first block def, second block def, or block if?'

As your examples suggest, you'd have to omit doc strings when scanning
blocks, so that you don't get caught on something that might only be a
comment, and not executed.



More information about the Python-list mailing list