On Monday, August 11, 2014 11:02:56 AM UTC-5, Edward K. Ream wrote:
>
> On Mon, Aug 11, 2014 at 10:54 AM, Kent Tenney <[email protected]> wrote:
> > V visual select line
> > P paste on new line above
> > O put cursor on new line above, enter insert mode
>
Done.
Today I've created a new style of programming, using vc.do, a thin wrapper
for k.simulateCommand. Take a look at the new code. You will instantly see
the difference::
def vim_O(vc):
'''Open a new line above the current line N times.'''
if vc.in_tree(vc.w):
c = vc.c
c.bodyWantsFocusNow()
vc.w = c.frame.body.bodyCtrl
if vc.is_text_widget(vc.w):
vc.do(['beginning-of-line','insert-newline','back-char'])
vc.done()
else:
vc.quit()
def vim_P(vc):
'''Paste text at the cursor or paste a node before the present node.'''
if vc.in_tree(vc.w):
vc.do(['goto-prev-visible','paste-node'])
vc.done()
elif vc.is_text_widget(vc.w):
vc.do(['back-char','paste-text'])
vc.done()
else:
vc.quit()
And here is my favorite. It would be very hard to get right using widget
methods::
def vim_V(vc):
'''Visually select line.'''
if vc.is_text_widget(vc.w):
if vc.state == 'visual':
bx = 'beginning-of-line-extend-selection'
ex = 'end-of-line-extend-selection'
s = vc.w.getAllText()
i = vc.w.getInsertPoint()
if vc.on_same_line(s,i,vc.vis_mode_i):
vc.do([bx,ex])
else:
vc.do(ex if vc.vis_mode_i < i else bx)
else:
vc.do([bx,ex])
vc.done()
else:
vc.quit()
All the vc key-handlers use this style. The switch happened earlier today.
This is a style I heartily recommend to anyone writing scripts that could
be based on Leo's commands.
Edward
P.S. vc.do now can take either a single command name or a list of command
names. Here it is::
def do(vc,o):
'''Do one or more Leo commands by name.'''
if isinstance(o,(tuple,list)):
for z in o:
vc.c.k.simulateCommand(z,event=vc.event)
else:
vc.c.k.simulateCommand(o,event=vc.event)
To make this work, k.simulateCommand now takes an optional event keyword
arg.
EKR
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.