[Sciviews-commits] r439 - in komodo/SciViews-K-dev: . R components pylib
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Feb 21 14:27:42 CET 2012
Author: prezez
Date: 2012-02-21 14:27:42 +0100 (Tue, 21 Feb 2012)
New Revision: 439
Added:
komodo/SciViews-K-dev/sciviewsk-1.1.3dev-ko.xpi
Modified:
komodo/SciViews-K-dev/R/completion.R
komodo/SciViews-K-dev/components/svUtils.py
komodo/SciViews-K-dev/install.rdf
komodo/SciViews-K-dev/pylib/lang_r.py
Log:
Code intelligence-2 for R: completion of items in '[', and par(graphical parameters)
added xpi version 1.1.3dev
Modified: komodo/SciViews-K-dev/R/completion.R
===================================================================
--- komodo/SciViews-K-dev/R/completion.R 2012-02-20 21:46:57 UTC (rev 438)
+++ komodo/SciViews-K-dev/R/completion.R 2012-02-21 13:27:42 UTC (rev 439)
@@ -13,7 +13,8 @@
# argument for the generic function.
# 'completeSpecial' prints newline separated completions for some special cases.
-# currently package and namespace list
+# currently package, namespace, graphical parameters, and quoted items for
+# use with `[` or `[[`
# "imports":
@@ -74,14 +75,14 @@
ret <- unique(unlist(ret, FALSE, FALSE))
}
} else ret <- character(0L)
- ret <- unique(c(ret, names(formals(fun))))
+ ret <- unique(c(ret, names(formals(args(fun)))))
if (length(ret) > 1L && (FUNC.NAME == "[" || FUNC.NAME == "[["))
ret <- ret[-1L]
return(ret[ret != "..."])
}
# provide special completions
-`completeSpecial` <- function(what) {
+`completeSpecial` <- function(what, object = NULL) {
res <- switch(what, search = {
res <- search()
res[!(res %in% c(".GlobalEnv", "package:tcltk", "package:utils",
@@ -89,14 +90,17 @@
"package:base"))]
}, library = {
res <- unique(unlist(lapply(.libPaths(), dir), use.names = FALSE))
+ }, par = {
+ res <- names(par())
+ }, "[" = {
+ res <- tryCatch(paste("\"", names(object), "\"", sep = ""),
+ error = function(e) "")
}, return(invisible(NULL)))
- cat(res, sep='\n')
+ cat(res, sep = '\n')
return(invisible(NULL))
}
-
-
# From svMisc::completion (simplified)
`completion` <- function (code, field.sep = "\x1e", sep = "\n",
Modified: komodo/SciViews-K-dev/components/svUtils.py
===================================================================
--- komodo/SciViews-K-dev/components/svUtils.py 2012-02-20 21:46:57 UTC (rev 438)
+++ komodo/SciViews-K-dev/components/svUtils.py 2012-02-21 13:27:42 UTC (rev 439)
@@ -381,6 +381,7 @@
indentstr = ' ' * indent
lines = re.findall(re_line, text)
indent_len = map(lambda line: len(string.expandtabs(line[0], tabwidth)), lines)
+ ## XXX: indent_len = [ len(string.expandtabs(line[0], tabwidth)) for line in lines ]
baseind = min(indent_len)
if (baseind == 0 and indent == 0): return text
return eol.join(map(lambda nspaces, line: \
Modified: komodo/SciViews-K-dev/install.rdf
===================================================================
--- komodo/SciViews-K-dev/install.rdf 2012-02-20 21:46:57 UTC (rev 438)
+++ komodo/SciViews-K-dev/install.rdf 2012-02-21 13:27:42 UTC (rev 439)
@@ -5,7 +5,7 @@
<em:unpack>true</em:unpack>
<em:id>sciviewsk at sciviews.org</em:id>
<em:name>SciViews-K</em:name>
- <em:version>1.1.2dev</em:version>
+ <em:version>1.1.3dev</em:version>
<em:description>Edit R code with Komodo</em:description>
<em:creator>Philippe Grosjean</em:creator>
<em:contributor>Romain Francois</em:contributor>
Modified: komodo/SciViews-K-dev/pylib/lang_r.py
===================================================================
--- komodo/SciViews-K-dev/pylib/lang_r.py 2012-02-20 21:46:57 UTC (rev 438)
+++ komodo/SciViews-K-dev/pylib/lang_r.py 2012-02-21 13:27:42 UTC (rev 439)
@@ -39,7 +39,7 @@
#---- Globals
lang = "R"
log = logging.getLogger("R-codeintel")
-log.setLevel(logging.DEBUG)
+log.setLevel(logging.WARNING)
# These keywords and builtin functions are copied from "Rlex.udl".
# Reserved keywords
@@ -190,20 +190,18 @@
ch = acc.char_at_pos(pos)
prv_ch = acc.char_at_pos(last_pos)
- #print 'w = "%s", ' % (w, ch, )
log.debug('w = "%s", ch = "%s", prv_ch = "%s", pos = %d, curr_pos = %d ' \
% (w, ch, prv_ch, pos, curr_pos, ))
if style in self.word_styles:
if self._is_bquoted(w):
return None
s2, e2, w2 = self._get_word_back(s - 1, acc)
- #print 'w2 = "%s" ' % (w2, )
log.debug( 'w2 = "%s" ' % (w2, ) )
if w2[-1] in ',(':
infun = self._in_func(last_pos, acc)
if infun is not None:
- print 'complete variable or argument "%s" for "%s"' % ( w, infun[2], )
+ #print 'complete variable or argument "%s" for "%s"' % ( w, infun[2], )
s2, e2, funcname, nargs, argnames, firstarg = infun
return Trigger(self.lang, TRG_FORM_CPLN, "args", s, False,
funcname = funcname, firstarg = firstarg, nargs = nargs,
@@ -213,33 +211,37 @@
else:
vr = self._get_var_back(last_pos, acc)
if vr is not None:
- print 'complete variable "%s"' % ( ''.join(vr[2]), )
+ #print 'complete variable "%s"' % ( ''.join(vr[2]), )
return Trigger(self.lang, TRG_FORM_CPLN, "variable", vr[4],
False, obj_name = ''.join(vr[2]), cutoff = vr[3])
+ return None
if w[-1] in ',(':
- infun = self._in_func(s + 1, acc)
+ infun = self._in_func(pos, acc)
if infun is not None:
s2, e2, funcname, nargs, argnames, firstarg = infun
print 'arguments for "%s"' % ( infun[2], )
return Trigger(self.lang, TRG_FORM_CPLN, "args", \
- pos, False, funcname = funcname, firstarg = firstarg,
+ pos, False, funcname = funcname, firstarg = firstarg, \
nargs = nargs, argnames = argnames)
- elif w[-1] in '@$:' or style in self.word_styles:
+ elif w[-1] in '@$:':
vr = self._get_var_back(last_pos, acc)
if vr is not None:
v = ''.join(vr[2])
print 'complete "%s"' % ( v, )
- return Trigger(self.lang, TRG_FORM_CPLN, "variable", vr[4],
+ return Trigger(self.lang, TRG_FORM_CPLN, "variable", vr[4], ### pos + 1
False, obj_name = v, cutoff = vr[3])
elif w in ('[', '[['):
infun = self._in_func(pos, acc)
if infun is not None:
+ log.debug( 'w = "%s", in_func = "%s" ' % (w, str(infun), ) )
s2, e2, funcname, nargs, argnames, firstarg = infun
log.debug('arguments for "%s"' % ( infun[2], ))
return Trigger(self.lang, TRG_FORM_CPLN, "args", \
- pos, False, funcname = funcname, firstarg = firstarg,
+ pos, False, funcname = funcname, firstarg = firstarg, \
nargs = nargs, argnames = argnames)
+ else:
+ log.debug( 'w = "%s", in_func is None' % (w, ) )
log.debug( 'None? w = "%s" ' % (w, ) )
@@ -298,40 +300,42 @@
def _get_completions_args(self, fname, frstarg, nargs, argnames):
fname = self._unquote(fname)
log.debug("fname = '%s'" % (fname, ) )
+# XXX: this can be simpler:
if fname in ('library', 'require', 'base::library', 'base::require') \
and nargs == 1:
- #cmd = "cat(unique(unlist(lapply(.libPaths(), dir, pattern='%s'))), sep='\\n')" \
- #% (('^' + frstarg if(frstarg) else ''), )
- cmd = 'completeSpecial("library")'
- types = 'module'
- sfx = ''
+ optlist = [ ('completeSpecial("library")', 'module', '') ]
argnames = ''
elif fname in ('detach', 'base::detach') and nargs == 1:
- #cmd = "cat(unique(unlist(lapply(.libPaths(), dir, pattern='%s'))), sep='\\n')" \
- #% (('^' + frstarg if(frstarg) else ''), )
- cmd = 'completeSpecial("search")'
- types = 'namespace'
- sfx = ''
+ optlist = [ ('completeSpecial("search")', 'namespace', '') ]
argnames = ''
+ elif fname == 'par':
+ optlist = [('completeSpecial("par"); cat(getFunArgs("par"), sep="\\n")',
+ 'argument', ' =') ]
+ elif fname in ('[', '[['):
+ optlist = [ ('cat(getFunArgs("%s", %s), sep="\\n")' % (fname, frstarg, ),
+ 'argument', ' =') ]
+ if fname == '[[' or nargs == 2:
+ optlist += [ ('completeSpecial("[", %s)' % (frstarg, ), '$variable', ''), ]
+ else:
+ optlist = [ ('cat(getFunArgs("%s", %s), sep="\\n")' % (fname, frstarg, ),
+ 'argument', ' =') ]
+ ret = []
+ for opt in optlist:
+ cmd, types, sfx = opt
+ res = R.execInR(cmd, "json h", .5).strip()
+ if len(res):
+ if res.startswith(u'\x03'):
+ return ('error', res.strip("\x02\x03\r\n"))
+ if len(argnames):
+ ret += [(types, x + sfx) for x in res.splitlines() if x not in argnames ]
+ else:
+ ret += [(types, x + sfx) for x in res.splitlines() ]
- else:
- cmd = 'cat(getFunArgs("%s", %s), sep = "\\n")' % (fname, frstarg, )
- types = 'argument'
- sfx = ' ='
- res = R.execInR(cmd, "json h", .5)
- if not len(res.strip()):
+ if not len(ret):
return ('none found', 'no completions found')
+ return ('success', ret, )
- if res.startswith(u'\x03'):
- return ('error', res.strip("\x02\x03\r\n"))
- if len(argnames):
- return ('success', [(types, x + sfx) for x in res.splitlines()
- if x not in argnames ])
- else:
- return ('success', [(types, x + sfx) for x in res.splitlines() ])
-
-
def _get_completions_default(self, text, cutoff):
if not text.strip(): return None
cmd = 'completion("%s")' % text.replace('"', '\\"')
@@ -370,6 +374,7 @@
style = acc.style_at_pos(s)
if style in self.word_styles:
token += [ w ]
+ s0 = s
cutoff = e0 - s
trg_pos = s
s, e, w = self._get_word_back(s - 1, acc)
@@ -384,6 +389,7 @@
style = acc.style_at_pos(s)
if style in self.word_styles:
token += [ w, w2 ]
+ s0 = s
else:
break
else:
@@ -397,17 +403,17 @@
style = acc.style_at_pos(s)
if style == self.variable_style:
token += [ w, w2 ]
+ s0 = s
else:
return None
- elif style not in ( self.identifier_style, self.keyword_style ):
+ elif not style in ( self.identifier_style, self.keyword_style ):
return None
+ print s, s0
+
token.reverse()
+ return (s0, e0, token, reduce(lambda v, x: v + len(x), token, 0) - cutoff,
+ trg_pos)
- cutoff = reduce(lambda v, x: v + len(x), token, 0) - cutoff
-
- return (s, e0, token, cutoff, trg_pos)
-
-
def _in_func(self, pos, acc):
p = pos - 1
p_min = max(0, pos - 200)
@@ -424,6 +430,7 @@
#elif ch in "[{":
elif ch == "{":
return None
+
elif ch == "[":
fn_start, fn_end, fn_word = self._get_word_back(p, acc)
# _get_var_back ===> (s, e0, token, cutoff, trg_pos)
@@ -435,6 +442,7 @@
argnames.reverse()
return (fn_start, p, fn_word, arg_count, argnames, ''.join(word) )
return None
+
elif ch == "(":
# function name:
fn_start, fn_end, fn_word = self._get_word_back(p - 1, acc)
Added: komodo/SciViews-K-dev/sciviewsk-1.1.3dev-ko.xpi
===================================================================
(Binary files differ)
Property changes on: komodo/SciViews-K-dev/sciviewsk-1.1.3dev-ko.xpi
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the Sciviews-commits
mailing list