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 custom REPL prompt #176

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ name = "MATLAB"
uuid = "10e44e05-a98a-55b3-a45b-ba969058deb6"
repo = "https://github.com/JuliaInterop/MATLAB.jl.git"
license = "MIT"
version = "v0.7.0"
version = "v0.8.0"

[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
ReplMaker = "b873ce64-0db9-51f5-a568-4457d8e49576"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[extras]
Expand Down
9 changes: 9 additions & 0 deletions src/MATLAB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module MATLAB

using Base.Sys: islinux, iswindows, isapple
using Libdl
using ReplMaker
using SparseArrays

import Base: eltype, close, size, copy, ndims, unsafe_convert
Expand Down Expand Up @@ -166,6 +167,14 @@ function __init__()
mat_put_variable[] = matfunc(:matPutVariable)
mat_get_dir[] = matfunc(:matGetDir)


if isinteractive()
initrepl(str -> Meta.parse("MATLAB.replmat\"$str\"");
prompt_text = ">> ",
start_key = ">",
mode_name = "MATLAB-Mode",
)
end
end


Expand Down
12 changes: 9 additions & 3 deletions src/matstr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function check_assignment(interp, i)
return (assigned, used)
end

function do_mat_str(ex)
function do_mat_str(ex, interactive=false)
# Hack to do interpolation
interp = Meta.parse(string("\"\"\"", replace(ex, "\"\"\"" => "\\\"\"\""), "\"\"\""))
if isa(interp, String)
Expand Down Expand Up @@ -151,7 +151,9 @@ function do_mat_str(ex)

# Add a semicolon to the end of the last statement to suppress output
isa(interp[end], String) && (interp[end] = rstrip(interp[end]))
push!(interp, ";")
if !interactive || !isempty(assignedvars)
push!(interp, ";")
end

# Figure out if `ans` exists in code to avoid an error if it doesn't
push!(interp, "\nmatlab_jl_has_ans = exist('ans', 'var');")
Expand All @@ -164,7 +166,7 @@ function do_mat_str(ex)
# Clear variables we created
:(eval_string($(string("clear ", join(union(usedvars, assignedvars), " "), ";"))))
end)
if get_variable(:matlab_jl_has_ans) != 0
if $(!interactive) && get_variable(:matlab_jl_has_ans) != 0
# Return ans if it was set
get_variable(:ans)
end
Expand All @@ -174,3 +176,7 @@ end
macro mat_str(ex)
do_mat_str(ex)
end

macro replmat_str(ex)
do_mat_str(ex, true)
end