Re: Some "how to do it" questions

From: Jeremy Cowgar <jeremy_at_cowgar.com>
Date: Sun, 20 Jul 2008 23:13:45 -0400

Eric S. Johansson wrote:
> I'm trying to increase the speech recognition friendliness of minimum
> profit,
> especially for Python. There are two things which are really very
> important.
> They may not seem like it but, they do help cut down on how much you
> have to say
> for this particular bit of functionality. these should work
> identically whether
> or not you're using tab characters or spaces for indentation
>
> 1) indent according to the indentation rules as defined by the
> previous line
> (the same level of indentation for ordinary lines, indent one further for
> conditionals, outdent by one for block termination)
I would say you would have to create your own function that would handle
the enter key and look back at the existing code to determine a line of
code's indentation level. This is not a trivial task to complete, but I
believe all the functionality in the scripting language exists in order
to accomplish it. Now, since you are speaking of Python, indentation
cannot always be found correctly just by looking back at the code. For
instance, you will indent after an if statement, but at some point in
time the user is going to have to manually out-dent inorder to end the
if statement. Minimum Profit will have no way of knowing when the user
may wish to do that. I guess that's why you are asking about numbers 2
and 3 though.
> 2) outdent the current line by one tab.
> bonus functions
I do not currently have this function, but I want it.
> 3) indent/outdent region or selected area.
I do have an indent block function. It is not well tested, but works for
me when I have used it. It is:

/* indent selected block */
sub indent_block(d) {
    if (d.txt.mark == NULL) {
        mp.move(d, mp.move_bol);
        mp.insert_tab(d);
        return (NULL);
    }
   
    local currentY = d.txt.y;
   
    mp.set_y(d, d.txt.mark.by);
   
    while (d.txt.y <= d.txt.mark.ey) {
        mp.move(d, mp.move_bol);
        mp.insert_tab(d);
        mp.move(d, mp.move_down);
    }
   
    mp.set_y(d, currentY);
}
mp.actions['indent_block'] = indent_block;
mp.actdesc['indent_block'] = "Indent block";
> If this is something that could be accomplished with the scripting
> language for
> mp, some pointers of how to approach the problem would be welcome.

Sorry I didn't have all the answers, but maybe others will chime in with
information too.

Jeremy

-- 
To unsubscribe, send mail to mp-unsubscribe_at_lists.triptico.com.
Received on Mon Jul 21 2008 - 05:13:45 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 21 2008 - 06:04:33 CEST