Last active
August 29, 2015 14:22
-
-
Save fabioz/d398cfa30960285c869c to your computer and use it in GitHub Desktop.
Example command to create a 'surround with' action in PyDev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if False: | |
from org.python.pydev.editor import PyEdit #@UnresolvedImport | |
cmd = 'command string' | |
editor = PyEdit | |
systemGlobals = {} | |
if cmd == 'onCreateActions': | |
assert editor is not None | |
MySurroundAction = systemGlobals.get('MySurroundAction') | |
if MySurroundAction is None: | |
Action = editor.getActionClass() #from org.eclipse.jface.action import Action #@UnresolvedImport | |
class MySurroundAction(Action): | |
def __init__(self, editor): | |
self.editor = editor | |
def run(self): | |
editor = self.editor | |
sel = editor.createPySelection() | |
txt = sel.getSelectedText() | |
doc = sel.getDoc() | |
sel = sel.getTextSelection() | |
doc.replace(sel.getOffset(), sel.getLength(), 'my_func(%s)' % (txt,)) | |
systemGlobals['MySurroundAction'] = MySurroundAction | |
# Change these constants if the default does not suit your needs | |
ACTIVATION_STRING = 'x' | |
WAIT_FOR_ENTER = False | |
# Register the extension as an ActionListener. | |
editor.addOfflineActionListener(ACTIVATION_STRING, MySurroundAction(editor), 'Surround with function', WAIT_FOR_ENTER) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment