Beispiel #1
0
def macroexpand1(ns, code):
    ret = switch_to_ns(ns)
    if not ret.success:
        return ret.to_scratch_buf()

    code = "(macroexpand-1 (quote\n%s))" % (code, )
    ret = ReplEval(code, eval_value=False, echo_code=True)
    return ret.to_scratch_buf()
Beispiel #2
0
def run_tests(ns, code):
    if ns is not None:
        ret = switch_to_ns(ns)
        if not ret.success:
            return ret.to_scratch_buf()

    ret = ReplEval(code, echo_code=True, eval_value=True)
    return ret.to_scratch_buf()
Beispiel #3
0
def _eval(ns, code):
    if ns is not None:
        ret = switch_to_ns(ns)
        if not ret.success:
            return ret.to_scratch_buf()

    ret = ReplEval(code, echo_code=True)
    return ret.to_popup()
Beispiel #4
0
def doc(ns, symbol):
    ret = switch_to_ns(ns)
    if not ret.success:
        return ret.to_popup()

    code = "(with-out-str (clojure.repl/doc %s))" % (symbol, )
    ret = ReplEval(code, eval_value=True)
    return ret.to_popup()
Beispiel #5
0
def cljfmt(code):
    require_cljfmt_code = "(require 'cljfmt.core)"
    ret = ReplEval(require_cljfmt_code,
                   eval_value=False,
                   echo_code=True,
                   silent=True)
    # if not ret.success:
    #     return ret.to_scratch_buf()

    template = "(with-out-str (print (cljfmt.core/reformat-string %s nil)))"
    code = template % (code, )
    ret = ReplEval(code, eval_value=True, echo_code=False, silent=True)
    return ret.to_value()
Beispiel #6
0
def process_command_from_vim(obj):
    LAST_COMMAND = ""
    LAST_COMMAND_SUCCESSFUL = True

    msg_id, msg = obj
    verb = msg[0]
    args = msg[1:]

    if verb == "init":
        out = [";; connected to nREPL"]
        get_existing_sessions(out)
        acquire_root_session(out)
        ReplEval.set_root_session(ROOT_SESSION)
        plasmaplace_repl_eval.start_repl_read_dispatch_loop()
        setup_repl(out)
        to_vim(msg_id, {"lines": out})
        start_keepalive_loop()
    elif verb == "delete_other_nrepl_sessions":
        for session_id in EXISTING_SESSIONS:
            TO_NREPL.put({"op": "close", "session": session_id})
        to_vim(msg_id, {"lines": []})
    elif verb == "exit":
        return False
    else:
        start_time = time.time()

        f = plasmaplace_commands.dispatcher[verb]
        ret = f(*args)
        if isinstance(ret, dict):
            if (LAST_COMMAND == "require" and LAST_COMMAND_SUCCESSFUL
                    and verb == "require" and not ret["ex_happened"]):
                ret["skip_center"] = True
            else:
                ret["skip_center"] = False

            LAST_COMMAND_SUCCESSFUL = not ret["ex_happened"]
        else:
            LAST_COMMAND_SUCCESSFUL = False
        LAST_COMMAND = verb

        end_time = time.time()
        duration = end_time - start_time
        duration = int(duration * 1000)
        do_async = False
        if duration > TIMEOUT_MS:
            do_async = True
        to_vim(msg_id, ret, do_async)
    return True
Beispiel #7
0
def switch_to_ns(ns):
    code = "(in-ns %s)" % ns
    ret = ReplEval(code)
    return ret
Beispiel #8
0
def require(ns, reload_level):
    code = "(clojure.core/require %s %s)" % (ns, reload_level)
    ret = ReplEval(code, eval_value=False, echo_code=True, silent=True)
    return ret.to_scratch_buf()