if DEBUG and cmd == "onSave": from org.python.pydev.jython import JythonPlugin # @UnresolvedImport # We want a fresh interpreter if we're debugging this script! editor.pyEditScripting.interpreter = JythonPlugin.newPythonInterpreter() cmd = "onCreateActions" # Force it to recreate things # We don't need to add the same assist proposal more than once. if cmd == "onCreateActions": # # Interesting stuff starts here! # assist_proposal = systemGlobals.get("assist_proposal") if assist_proposal is None: import assist_proposal systemGlobals["assist_proposal"] = assist_proposal assist_regex_based_proposal = systemGlobals.get("assist_regex_based_proposal") if assist_regex_based_proposal is None: import assist_regex_based_proposal systemGlobals["assist_regex_based_proposal"] = assist_regex_based_proposal if DEBUG and cmd == "onSave": reload(assist_regex_based_proposal) o = assist_regex_based_proposal.AssignValueToVarIfNone() assist_proposal.register_proposal(o, DEBUG)
def isValid(self, selection, current_line, editor, offset): opener_offset, opener, closer = find_expression_opener(selection, offset) if opener_offset is None: return False closer_offset, has_commas, _ignored = get_closer_offset(selection.getDoc().get(), opener_offset, closer) if closer_offset < 0: if DEBUG_WRAP_EXPRESSION: print "expression is not closed" return False if not has_commas: if DEBUG_WRAP_EXPRESSION: print "expression does not have commas" return False if selection.getLineOfOffset(opener_offset) == selection.getLineOfOffset(closer_offset): if DEBUG_WRAP_EXPRESSION: print "expression is already single line" return False self.store_data(opener_offset, closer_offset) return True def apply(self, document): lines = [] text = document.get()[self.opener_offset+1:self.closer_offset] replacement_text = re.sub(r'\s*\n *', ' ', text.replace('\r', '')).strip() length = self.closer_offset - self.opener_offset - 1 document.replace(self.opener_offset + 1, length, replacement_text) register_proposal(WrapExpression(), DEBUG_WRAP_EXPRESSION) register_proposal(UnwrapExpression(), DEBUG_WRAP_EXPRESSION)
# namespace provided for pydev scripts: if False: from org.python.pydev.editor import PyEdit #@UnresolvedImport cmd = 'command string' editor = PyEdit assert cmd is not None assert editor is not None True, False = 1,0 # We don't need to add the same assist proposal more than once. if not (cmd == 'onCreateActions' or (DEBUG and cmd == 'onSave')): from org.python.pydev.jython import ExitScriptException #@UnresolvedImport raise ExitScriptException() # We want a fresh interpreter if we're debugging this script! if DEBUG and cmd == 'onSave': from org.python.pydev.jython import JythonPlugin #@UnresolvedImport editor.pyEditScripting.interpreter = JythonPlugin.newPythonInterpreter() # # Interesting stuff starts here! # import assist_proposal import assist_regex_based_proposal if DEBUG and cmd == 'onSave': reload(assist_regex_based_proposal) o = assist_regex_based_proposal.AssignValueToVarIfNone() assist_proposal.register_proposal(o, DEBUG)
return False closer_offset, has_commas, _ignored = get_closer_offset( selection.getDoc().get(), opener_offset, closer) if closer_offset < 0: if DEBUG_WRAP_EXPRESSION: print "expression is not closed" return False if not has_commas: if DEBUG_WRAP_EXPRESSION: print "expression does not have commas" return False if selection.getLineOfOffset( opener_offset) == selection.getLineOfOffset(closer_offset): if DEBUG_WRAP_EXPRESSION: print "expression is already single line" return False self.store_data(opener_offset, closer_offset) return True def apply(self, document): lines = [] text = document.get()[self.opener_offset + 1:self.closer_offset] replacement_text = re.sub(r'\s*\n *', ' ', text.replace('\r', '')).strip() length = self.closer_offset - self.opener_offset - 1 document.replace(self.opener_offset + 1, length, replacement_text) register_proposal(WrapExpression(), DEBUG_WRAP_EXPRESSION) register_proposal(UnwrapExpression(), DEBUG_WRAP_EXPRESSION)