朱莉娅REPL在Sublime Text中的实现

3
我正在尝试在Sublime Text中使用Julia REPL。然而,在此过程中,我在Julia方面遇到了一些问题。基本上我的嵌入式Julia REPL可以正常运行,但交互元素(如提示符)没有显示出来。因为各种原因,我不想使用Sublime-IJulia。
当我从xterm运行时,我的REPL可以正常工作。
据我所知,我需要找到一种方法在从Sublime中运行Julia时让其使用基本的REPL,但是我不确定应该如何操作。
从xterm运行Base.active_repl会给我以下输出:
LineEditREPL(
    TTYTerminal("xterm-256color",TTY(open, 0 bytes waiting),TTY(open, 0 bytes waiting),TTY(open, 0 bytes waiting)),
    true,
    "\e[1m\e[32m",
    "\e[1m","\e[1m",
    "\e[1m\e[31m",
    "\e[1m\e[33m",
    false,
    false,
    false,
    true,
    false,
    nothing,
    ModalInterface(TextInterface["Prompt(\"julia> \",...)","Prompt(\"shell> \",...)","Prompt(\"help?> \",...)",HistoryPrompt{REPLHistoryProvider}(REPLHistoryProvider(String["5","exit","exit()","Pkg.status()","Pkg.add(\"ZMQ\")","Pkg.add(\"IJulia\")","Pkg.status()","Pkg.remove(\"IJulia\")","Pkg.rm(\"IJulia\")","Pkg.status()""import REPL","import Base..REPL","Base.BasicRepl","Base.BasicREPL","Base.REPL","Base.REPL.BasicREPL","Base.active_repl = Base.REPL.BasicREPL()","Base.active_repl","exit()","Base.active_repl"],IOStream(<file .julia_history>),62,-1,IOBuffer(data=Uint8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1),"Prompt(\"julia> \",...)",[:help=>"Prompt(\"help?> \",...)",:shell=>"Prompt(\"shell> \",...)",:julia=>"Prompt(\"julia> \",...)"],[:julia,:julia,:julia,:julia,:julia,:julia,:julia,:julia,:julia,:julia  …  :julia,:julia,:julia,:julia,:julia,:julia,:julia,:julia,:julia,:julia]),LatexCompletions(),(anonymous function))]),
    REPLBackendRef(RemoteRef(1,1,0),RemoteRef(1,1,1)))

在SublimeRepl中运行会返回以下错误:ERROR: active_repl未定义

简而言之,是否有一种方法可以允许我编辑当我从Sublime运行时julia启动的REPL类型?如果这是可能的,我需要使用哪种类型的REPL?

1个回答

1
我在 Reddit 上发现了一个解决方法:https://www.reddit.com/r/SublimeText/comments/5jtnj7/sublimerepl_is_it_possible_to_mimic_commandline/ 特别是:

Found a (really) hacky solution to see the julia> prompts!

In Preferences > Browse Packages > SublimeREPL/sublimerepl.py, add these two lines under the else: statement of handle_repl_packet():

if self.repl.name() == 'julia' :
    self.write_prompt('julia>')

For reassurance, the method in its entirety will look like this:

def handle_repl_packet(self, packet):
        if self.repl.apiv2:
            for opcode, data in packet:
                if opcode == 'output':
                    self.write(data)
                elif opcode == 'prompt':
                    self.write_prompt(data)
                elif opcode == 'highlight':
                    a, b = data
                    regions = self._view.get_regions('sublimerepl')
                    regions.append(sublime.Region(a, b))
                    self._view.add_regions('sublimerepl', regions, 'invalid',
                                           '', sublime.DRAW_EMPTY | sublime.DRAW_OUTLINED)
                else:
                    print('SublimeREPL: unknown REPL opcode: ' + opcode)
        else:
            if self.repl.name() == 'julia' :
                self.write_prompt('julia>')
            self.write(packet)

This does fail on the first line - I'll see if I can fix that.

EDIT: I failed to mention that I have previously changed sublimerepl.py as described here: SublimeREPL's Slow Printing/Freezing - A Solution. In my experience, it makes SublimeREPL's printing much faster... and is needed to make this julia> fix work as is.

自那时以来,我还没有找到更强大的解决方案。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接