[rkward-cvs] SF.net SVN: rkward:[3539] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Sun May 8 10:44:23 UTC 2011
Revision: 3539
http://rkward.svn.sourceforge.net/rkward/?rev=3539&view=rev
Author: tfry
Date: 2011-05-08 10:44:23 +0000 (Sun, 08 May 2011)
Log Message:
-----------
Also show argument hints after pressing ',', and simplify some of the ugly ancient code.
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/rkconsole.cpp
trunk/rkward/rkward/rkconsole.h
trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
trunk/rkward/rkward/windows/rkcommandeditorwindow.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2011-05-07 12:15:49 UTC (rev 3538)
+++ trunk/rkward/ChangeLog 2011-05-08 10:44:23 UTC (rev 3539)
@@ -1,3 +1,4 @@
+- Fixed: Function argument hints would not be shown in some corner cases
- Added function rk.print.code() to write highlighted R code to the output window # TODO: Next, implement the 'carbon copy' feature
- Box plot plugin gains support for grouped outcome data
- Fixed: Pressing Ctrl+C would not reset syntactically incomplete commands in the R console
Modified: trunk/rkward/rkward/rkconsole.cpp
===================================================================
--- trunk/rkward/rkward/rkconsole.cpp 2011-05-07 12:15:49 UTC (rev 3538)
+++ trunk/rkward/rkward/rkconsole.cpp 2011-05-08 10:44:23 UTC (rev 3539)
@@ -331,20 +331,18 @@
return false;
}
-bool RKConsole::provideContext (unsigned int line_rev, QString *context, int *cursor_position) {
+QString RKConsole::provideContext (int line_rev) {
RK_TRACE (COMMANDEDITOR);
- if (line_rev > 1) return false;
-
- if (line_rev == 0) {
- *cursor_position = currentCursorPositionInCommand ();
- *context = currentEditingLine ();
- } else {
- *cursor_position = -1;
- *context = incomplete_command;
+ QString ret;
+ if (line_rev == 0) ret = currentEditingLine ().left (currentCursorPositionInCommand ());
+ else if (!incomplete_command.isEmpty ()) {
+ QStringList lines = incomplete_command.split ("\n");
+ if (lines.size () > line_rev) {
+ ret = lines[lines.size () - line_rev - 1];
+ }
}
-
- return true;
+ return ret;
}
void RKConsole::insertCompletion (int line_num, int word_start, int word_end, const QString &completion) {
Modified: trunk/rkward/rkward/rkconsole.h
===================================================================
--- trunk/rkward/rkward/rkconsole.h 2011-05-07 12:15:49 UTC (rev 3538)
+++ trunk/rkward/rkward/rkconsole.h 2011-05-08 10:44:23 UTC (rev 3539)
@@ -60,7 +60,7 @@
/** Returns the current cursor position, within the current command (without taking into account the prefix). Returns -1 if the cursor is not on the line containing the command. */
int currentCursorPositionInCommand ();
void doTabCompletion ();
- bool provideContext (unsigned int line_rev, QString *context, int *cursor_position);
+ QString provideContext (int line_rev);
static RKConsole *mainConsole () { return main_console; };
static void setMainConsole (RKConsole *console) { main_console = console; };
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-05-07 12:15:49 UTC (rev 3538)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.cpp 2011-05-08 10:44:23 UTC (rev 3539)
@@ -576,22 +576,17 @@
}
}
-bool RKCommandEditorWindow::provideContext (unsigned int line_rev, QString *context, int *cursor_position) {
+QString RKCommandEditorWindow::provideContext (int line_rev) {
RK_TRACE (COMMANDEDITOR);
KTextEditor::Cursor c = m_view->cursorPosition();
- uint current_line_num=c.line(); uint cursor_pos=c.column();
+ int current_line_num=c.line(); int cursor_pos=c.column();
- if (line_rev > current_line_num) return false;
+ if (line_rev > current_line_num) return QString ();
- if (line_rev == 0) {
- *cursor_position = cursor_pos;
- } else {
- *cursor_position = -1;
- }
- *context = m_doc->line (current_line_num - line_rev);
-
- return true;
+ QString ret = m_doc->line (current_line_num - line_rev);
+ if (line_rev == 0) ret = ret.left (cursor_pos);
+ return ret;
}
void RKCommandEditorWindow::paste (const QString& text) {
@@ -828,68 +823,42 @@
void RKFunctionArgHinter::tryArgHintNow () {
RK_TRACE (COMMANDEDITOR);
- int line_rev;
- int cursor_pos;
- QString current_context;
- QString current_line;
-
- // fetch the most immediate context line. More will be fetched later, if appropriate
- bool have_context = provider->provideContext (line_rev = 0, ¤t_line, &cursor_pos);
- RK_ASSERT (have_context);
- RK_ASSERT (cursor_pos >= 0);
- current_context = current_line;
-
- // find the corrresponding opening brace
- int matching_left_brace_pos;
+ // find the active opening brace
+ int line_rev = -1;
int brace_level = 1;
- int i = cursor_pos;
+ int potential_symbol_end = -1;
+ QString full_context;
+ while (potential_symbol_end < 0) {
+ QString context_line = provider->provideContext (++line_rev);
+ if (context_line.isNull ()) break;
- // fix up seems to be needed
- if (current_context.isEmpty ()) {
- hideArgHint ();
- return;
- }
- if (i >= current_context.size ()) i = current_context.size () -1;
- if (i < 0) i = 0;
-
- while (true) {
- if (current_context.at (i) == QChar (')')) {
- brace_level++;
- } else if (current_context.at (i) == QChar ('(')) {
- brace_level--;
- if (!brace_level) break;
+ full_context.prepend (context_line);
+ int pos = context_line.length ();
+ while (--pos >= 0) {
+ QChar c = full_context.at (pos);
+ if (c == ')') ++brace_level;
+ else if (c == '(') {
+ --brace_level;
+ if (brace_level == 0) {
+ potential_symbol_end = pos - 1;
+ break;
+ }
+ }
}
-
- --i;
- if (i < 0) {
- bool have_context = provider->provideContext (++line_rev, ¤t_line, &cursor_pos);
- if ((!have_context) || (current_line.isEmpty ())) break;
-
- RK_ASSERT (cursor_pos < 0);
- current_context.prepend (current_line);
- i = current_line.length () - 1;
- }
}
- if (!brace_level) matching_left_brace_pos = i;
- else {
- hideArgHint ();
- return;
- }
-
- // now find where the symbol to the left ends
+ // now find out where the symbol to the left of the opening brace ends
// there cannot be a line-break between the opening brace, and the symbol name (or can there?), so no need to fetch further context
- int potential_symbol_end = matching_left_brace_pos - 1;
- while ((potential_symbol_end >= 0) && current_context.at (potential_symbol_end).isSpace ()) {
+ while ((potential_symbol_end >= 0) && full_context.at (potential_symbol_end).isSpace ()) {
--potential_symbol_end;
}
- if (potential_symbol_end < 0) {
+ if (potential_symbol_end <= 0) {
hideArgHint ();
return;
}
// now identify the symbol and object (if any)
- QString effective_symbol = RKCommonFunctions::getCurrentSymbol (current_context, potential_symbol_end+1);
+ QString effective_symbol = RKCommonFunctions::getCurrentSymbol (full_context, potential_symbol_end+1);
if (effective_symbol.isEmpty ()) {
hideArgHint ();
return;
@@ -937,10 +906,8 @@
tryArgHint ();
} else {
QString text = k->text ();
- if (text == "(") {
+ if ((text == "(") || (text == ")") || (text == ",")) {
tryArgHint ();
- } else if (text == ")") {
- tryArgHint ();
}
}
}
Modified: trunk/rkward/rkward/windows/rkcommandeditorwindow.h
===================================================================
--- trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-05-07 12:15:49 UTC (rev 3538)
+++ trunk/rkward/rkward/windows/rkcommandeditorwindow.h 2011-05-08 10:44:23 UTC (rev 3539)
@@ -65,11 +65,10 @@
RKScriptContextProvider () {};
virtual ~RKScriptContextProvider () {};
- /** to be implemented in subclasses. Provide some context (probably a line, but you may provide chunks in arbitrary size). If line_rev is 0, provide the line, the cursor is in. If line_rev is greater than 0, provide context before that.
+ /** to be implemented in subclasses. Provide some context, i.e. text *preceding* the cursor position (probably a line, but you may provide chunks in arbitrary size). If line_rev is 0, provide the line, the cursor is in. If line_rev is greater than 0, provide context before that.
@param context Place the context here
- @param cursor_position if line_rev is 0, set this to the current column of the cursor, else set to -1
- @returns whether context was available or not */
- virtual bool provideContext (unsigned int line_rev, QString *context, int *cursor_position) = 0;
+ @returns a chunk of context. A null QString(), if no context was available. */
+ virtual QString provideContext (int line_rev) = 0;
};
class RObject;
@@ -187,7 +186,7 @@
/** Return current url */
KUrl url ();
- bool provideContext (unsigned int line_rev, QString *context, int *cursor_position);
+ QString provideContext (int line_rev);
QString currentCompletionWord () const;
public slots:
/** update Tab caption according to the current url. Display the filename-component of the URL, or - if not available - a more elaborate description of the url. Also appends a "[modified]" if appropriate */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list