Skip to content

Commit

Permalink
Using 'ns instead of 'in-ns to change namespace
Browse files Browse the repository at this point in the history
Fix Issue 484:	creating a new namespace and sending an defn expression from it to REPL results in CompilerException
  • Loading branch information
laurentpetit committed Dec 13, 2012
1 parent b50c4e9 commit 7121cc9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions ccw.branding/html/reference/preferences/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ <h1>Editor Preferences</h1>
</tr>
<tr>
<td valign="top">
On file launch, switch the REPL to the file namespace (calling 'in-ns)
On file launch, switch the REPL to the file namespace (calling 'ns)
</td>
<td valign="top">
<p>
When a Clojure file is loaded into the REPL, this option will automatically
call the <strong>in-ns</strong> function to allow direct calling of functions
call the <strong>ns</strong> macro to allow direct calling of functions
from the file just loaded, without the need to prefix the functions with the
namespace prefix.
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void run() {
String editorNamespace = editor.findDeclaringNamespace();
String replNamespace = repl.getCurrentNamespace();
if (editorNamespace != null && !editorNamespace.equals(replNamespace)) {
textToEvaluate = "(in-ns '" + editorNamespace + ")\n" + textToEvaluate + "\n(in-ns '" + replNamespace + ")";
textToEvaluate = "(clojure.core/ns " + editorNamespace + ")\n" + textToEvaluate + "\n(clojure.core/ns " + replNamespace + ")";
}

EvaluateTextUtil.evaluateText(repl, textToEvaluate, isReplExplicitLoggingMode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.eclipse.jface.action.Action;

import ccw.CCWPlugin;
import ccw.preferences.PreferenceConstants;
import ccw.repl.Actions;
import ccw.repl.REPLView;

Expand Down Expand Up @@ -40,7 +39,7 @@ public static void run(REPLView repl, ClojureEditor editor, boolean activateREPL
CCWPlugin.logError("Could not switch ns to: " + ns);
} else {
EvaluateTextUtil.evaluateText(repl, String.format(";; Switching to %s namespace", ns), isReplExplicitLoggingMode());
EvaluateTextUtil.evaluateText(repl, String.format("(in-ns '%s)", ns), false);
EvaluateTextUtil.evaluateText(repl, String.format("(clojure.core/ns %s)", ns), false);
Actions.ShowActiveREPL.execute(activateREPL);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ccw.core/src/java/ccw/preferences/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ClojureREPLPreferencePage_Description=REPL settings for Clojure development:
ClojurePreferencePage_description=Expand the tree to edit preferences for a specific feature.
ClojurePreferencePage_displayed_tab_width=Displayed tab width:
ClojurePreferencePage_highlight_matching_brackets=Highlight &matching brackets
ClojurePreferencePage_switch_to_ns_on_repl_startup=On file launch, switch the Repl to the file namespace (calling 'in-ns)
ClojurePreferencePage_switch_to_ns_on_repl_startup=On file launch, switch the Repl to the file namespace (calling 'ns)
ClojurePreferencePage_use_strict_structural_editing_mode_by_default=Start editors in strict/paredit Edit mode
ClojurePreferencePage_show_rainbow_parens_by_default=Start editors with rainbow parens
ClojurePreferencePage_use_tab_for_reindenting_line=[Tab] reindents the current line
Expand Down
7 changes: 6 additions & 1 deletion ccw.core/src/java/ccw/repl/REPLView.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private static void releaseSecondaryId (String id) {
}

private static final Keyword inputExprLogType = Keyword.intern("in-expr");
private static final Keyword errLogType = Keyword.intern("err");
private static final Pattern boostIndent = Pattern.compile("^", Pattern.MULTILINE);

// TODO would like to eliminate separate log view, but:
Expand Down Expand Up @@ -251,7 +252,11 @@ public void evalExpression (String s, boolean userInput, boolean logExpression)
try {
if (s.trim().length() > 0) {
if (logExpression) log.invoke(this, logPanel, s, inputExprLogType);
evalExpression.invoke(s, userInput);
if (evalExpression == null) {
log.invoke(this, logPanel, "Invalid REPL", errLogType);
} else {
evalExpression.invoke(s, userInput);
}
}
} catch (Exception e) {
CCWPlugin.logError(e);
Expand Down

0 comments on commit 7121cc9

Please sign in to comment.