Macros

23 views
Skip to first unread message

Sadi

unread,
Jan 2, 2012, 8:27:13 AM1/2/12
to editra
Could any one offer a little help with writing a Python macro under
Editra MacroLauncher plugin, which will simply perform several plain
text and RegEx replacements in an open file?
I've done a lot of searching and quick reading but as an outsider to
the scripting world, it seems almost impossible to make some progress.
The plugin somehow hasn't come together with all those sample macros
shown either.
Thanks...

Cody

unread,
Jan 2, 2012, 10:25:50 PM1/2/12
to edi...@googlegroups.com
Hi,

I personally haven't used that plugin much before since it is kind of
difficult to use due to there being no building block methods to work
with when creating a script to abstract it from internal Editra APIs.
Thus, in its current form it requires you to have a fair amount of
knowledge of the inner workings of Editra to get very far.

I can give some rough starting points to get you towards a script to
do what you want though.

First I will point you towards the API manual, I am working on a
better version that will be out in the near future but most every
function / object can be found in there.
(http://editra.org/docs/editra_api/annotated.html)

The following code should get you most of the way towards the task you
want to do:

# 1. Import the regular expression module
import re

# 2. Get the current text buffer
textCtrl = wx.GetApp().GetCurrentBuffer()

# 3. Get the Unicode text from the control
text = textCtrl.GetText()

# 4. Do your regex search/replacements on the text using the standard
python 're' module.
...

# 5. Update the modified text in the control (retaining current caret position)
currentPosition = textCtrl.GetCurrentPos()
textCtrl.SetText(text)
textCtrl.SetCurrentPos(currentPosition)

Cody

Reply all
Reply to author
Forward
0 new messages