Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a single function to preprocess code #79

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/eval.jl
@@ -1,6 +1,7 @@
using CodeTools, LNR, Media
import CodeTools: getthing

preprocess = identity
ends_with_semicolon(x) = Base.REPL.ends_with_semicolon(split(x,'\n',keep = false)[end])

LNR.cursor(data::Associative) = cursor(data["row"], data["column"])
Expand Down Expand Up @@ -43,6 +44,7 @@ const evallock = ReentrantLock()
handle("eval") do data
@dynamic let Media.input = Editor()
@destruct [text, line, path, mod] = data
text = preprocess(text)
mod = getthing(mod)

lock(evallock)
Expand All @@ -61,6 +63,7 @@ end
handle("evalall") do data
@dynamic let Media.input = Editor()
@destruct [setmod = :module || nothing, path || "untitled", code] = data
code = preprocess(code)
mod = Main
if setmod ≠ nothing
mod = getthing(setmod, Main)
Expand All @@ -87,6 +90,7 @@ end
handle("evalrepl") do data
@dynamic let Media.input = Console()
@destruct [mode || nothing, code, mod || "Main"] = data
code = preprocess(code)
mod = getthing(mod)
if mode == "shell"
code = "Base.repl_cmd(`$code`, STDOUT)"
Expand Down