コード例 #1
0
def function_arguments(fun):
    try:
        args = robjects.r('do.call(argsAnywhere, list("%s"))' % fun)
        args = QString(str(args))
        if args.contains("function"):
            regexp = QRegExp(r"function\s\(")
            start = regexp.lastIndexIn(args)
            regexp = QRegExp(r"\)")
            end = regexp.lastIndexIn(args)
            args = args[start:end+1].replace("function ", "") # removed fun
        else:
            args = args.replace("\n\n", "").remove("NULL")
    except Exception: # if something goes wrong, ignore it!
        args = QString()
    return args
コード例 #2
0
 def textUnderCursor(self):
     """
     Return current word at cursor position
     """
     line, index = self.getCursorPosition()
     text = self.text(line)
     wc = self.wordCharacters()
     if wc is None:
         regexp = QRegExp('[^\w_]')
     else:
         regexp = QRegExp('[^{0}]'.format(re.escape(wc)))
     start = regexp.lastIndexIn(text, index) + 1
     end = regexp.indexIn(text, index)
     if start == end + 1 and index > 0:
         # we are on a word boundary, try again
         start = regexp.lastIndexIn(text, index - 1) + 1
     if start == -1: start = 0
     if end == -1: end = len(text)
     if end > start:
         word = text[start:end]
     else:
         word = ''
     return word