Cool. I'm changing the name to
@adhoc

Strikes me as 'macro' capability.
With almost no overhead, define a filter for selected text, and
persist it visually, no need for remembering!

I'll put it into myLeoSettings.leo

Thanks,
Kent

On Tue, Feb 14, 2012 at 8:34 PM, Terry Brown <terry_n_br...@yahoo.com> wrote:
> Ever find that you have a whole lot of:
>
> rec[f['analyte']] ... rec[f['sample_type']] ...
>
> expressions in your code, and now things have changed and you want them all
> to be:
>
> row.Analyte ... row.Sample_Type ...
>
> basically if str variable s was:
>
> rec[f['analyte']]
>
> then you want to perform:
>
> s = "row."+s.split("'")[1].title()
>
> on each one. In general it would be nice to be able to use a python
> expression when search and replace doesn't cut it.
>
> The button code below creates a button, fac, which, when pressed, creates
> another button, with some name you choose, which, when pressed, executes
> some python code to fix the selected text in the body.
>
> You can define the code to be executed in two ways, either in its own node:
>
> insert a new node with a headline which describes the refactor
> enter code in the node which modifies the string variable s, which is
> initially set to the selected text in the body
> press the fac button, which creates a new button named after this code node
> select each offending piece of text and press the button created in the
> previous step to fix
>
> or
>
> type some code modifying s right in the body you're working on
> press the fac button, which creates a new button named "fix"
> select each offending piece of text and press the button created in the
> previous step to fix
>
> Note:
>
> unlike regular button nodes, changing the code after the button's created
> (first option above) doesn't change the code executed by the button
> replacing selection text makes Leo reposition the insert point at the top of
> the window, this is annoying but unrelated to this code
>
> Here's the button code:
>
> @button fac
>   from leo.plugins.mod_scripting import scriptingController
>
>   sc = scriptingController(c)
>
>   if c.frame.body.hasSelection():
>       code = c.frame.body.getSelectedText()
>       heading = 'fix'
>   else:
>       code = p.b
>       heading = p.h
>
>   def transform(c=c, code=code):
>       s = c.frame.body.getSelectedText()
>       g.es(s)
>       exec code
>       g.es(s)
>       c.frame.body.deleteTextSelection()
>       i = c.frame.body.getInsertPoint()
>       c.frame.body.insert(i, s)
>       p.b = c.frame.body.getAllText()
>       c.frame.body.setInsertPoint(i)
>
>   b = sc.createIconButton(
>       heading,
>       command = transform,
>       shortcut = None,
>       statusLine = 'Make filter button',
>       bg = "LightBlue"
>   )
>
> --
> You received this message because you are subscribed to the Google Groups
> "leo-editor" group.
> To post to this group, send email to leo-editor@googlegroups.com.
> To unsubscribe from this group, send email to
> leo-editor+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/leo-editor?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to leo-editor@googlegroups.com.
To unsubscribe from this group, send email to 
leo-editor+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to