Get julia to run in sublimeREPL?

2,033 views
Skip to first unread message

Jacob Quinn

unread,
Feb 28, 2013, 4:44:50 PM2/28/13
to julia...@googlegroups.com
After spending most of my day trying to get some kind of hack working, I'm turning here. I started using sublime text 2 recently and have really started to enjoy it. There are a ton of functionality tricks, but also the ease of plugins, packages, and snippets make syntax highlighting and code autocomplete extremely easy. (Note, a thanks to epitron for his work on julia syntax already; we should add this to the homepage. https://github.com/epitron/Julia-sublime)

My problem today is trying to get the julia REPL up and running within a sublime package called sublimeREPL. It's used to run quite a few REPLs including R, Ruby, Python, etc. The problem may just be that I'm on windows and we need a standalone executable for it to work, but I feel like it's really close. I launch cmd.exe to point at the 'julia.bat' file and it loads the banner just fine, but that's where the magic ends. I can type commands into the repl, but upon hitting enter, it echos (because this is turned on explicitly) the command back, returns a newline, but no output is shown. I've tried to dig into the internals, but I don't know python or its subprocess/repl modules well enough. With all the research I did today, I think all that's needed is a basic tweak to julia's repl.c file, but again, I'm very new to shell commands, repls, and all that jazz.

Don't want to be a burden on anyone, but if anyone has any ideas, would like to take a stab at it, or can point me in another direction, I'd really appreciate it. I'd love to be able to code and run in the same window.

Here's an image to show what's going on with the repl:


Patrick O'Leary

unread,
Feb 28, 2013, 4:48:54 PM2/28/13
to julia...@googlegroups.com
Are you running the -basic REPL?

Rahul Dave

unread,
Feb 28, 2013, 4:49:09 PM2/28/13
to julia...@googlegroups.com
This is on a mac, but perhaps it helps?
In ~/Library/Application Support/Sublime Text 2/Packages/SublimeREPL/config
I made a Julia folder and:

[
    {
        "caption": "SublimeREPL: Julia",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_julia",
            "file": "config/Julia/Main.sublime-menu"
        }
    }
]
IN 
Default.sublime-commands 

AND

[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "r",
            "id": "SublimeREPL",
            "children":
            [
                {"command": "repl_open",
                 "caption": "Julia",
                 "id": "repl_julia",
                 "mnemonic": "o",
                 "args": {
                    "type": "subprocess",
                    "encoding": "utf8",
                    "cmd": ["/Users/rahul/Learning/julia/usr/bin/julia-release-basic"],
                    "cwd": "$file_path",
                    "external_id": "julia",
                    "syntax": "Packages/Julia/Julia.tmLanguage"
                    }
                }
            ]
        }]
    }
]

IN
Main.sublime-menu


The only problem I had is with this incantation, the julia process would die when i exited the REPL.

Rahul
-- 
Rahul Dave
Sent with Sparrow

Jacob Quinn

unread,
Feb 28, 2013, 4:51:06 PM2/28/13
to julia...@googlegroups.com
I believe it's the -readline because it comes bundled with the julia.bat file. I can try switching.

Jacob Quinn

unread,
Feb 28, 2013, 4:57:53 PM2/28/13
to julia...@googlegroups.com
That seems to have done the trick. I thought it would be a pretty basic fix. Thanks! I'll write up a post for those interested in getting this up and running themselves.

Cheers,

-Jacob


On Thursday, February 28, 2013 3:48:54 PM UTC-6, Patrick O'Leary wrote:

Jacob Quinn

unread,
Feb 28, 2013, 5:14:48 PM2/28/13
to julia...@googlegroups.com
You can download sublime text 2 here: http://www.sublimetext.com/2

Next open up the python console and paste the following in to download and install the package manager:
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')

Type "ctrl+shift+p" ("cmd+shift+p" I think for mac) to open the 'GoTo anything' menu: start typing 'install' and hit enter. Once the list of repos pops up, start typing 'julia' to download julia syntax highlighting.
Follow same steps as above but in the list of repos, search for 'sublimerepl' to download/install. You may have to restart.
Next, you need to navigate to your sublime package folder (see Rahul's code above for Mac, on Windows, it's in Appdata/Roaming/Sublime Text 2/Packages/SublimeREPL). Then enter the 'config' folder.
Create a new Julia folder.
Create a new file named 'Default.sublime-commands'. Paste the following in:
[
    {
        "caption": "SublimeREPL: Julia",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_julia",
            "file": "config/Julia/Main.sublime-menu"
        }
    }
]

Next create a file in the same Julia folder named 'Main.sublime-menu'. Paste the following inside; *Note: You need to map to your own julia.bat file
[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "r",
            "id": "SublimeREPL",
            "children":
            [
                {"command": "repl_open", 
                 "caption": "Julia",
                 "id": "repl_julia",
                 "mnemonic": "s",
                 "args": {
                    "type": "subprocess",
                    "suppress_echo": false, 
                    "external_id": "julia",
                    "cmd": {"windows": ["C:/Users/quinnj/Documents/Julia/julia0.1-3c8b901b59-WINNT-i686/julia-3c8b901b59/julia - Copy.bat"],
                            "linux": [],
                            "osx": []},
                    "cwd": "$file_path",
"cmd_postfix": "\n", 
                    "env": {},
                    "encoding": {"windows": "$win_cmd_encoding",
                                 "linux": "utf-8",
                                 "osx": "utf-8"},
                    "syntax": ""
                    }
                }
            ]   
        }]
    }
]


Finally, find your 'julia.bat' file and open it using a text editor (why not sublime?) change the line that reads:
call "%JULIA_HOME%julia-release-readline.exe" %*
To:
call "%JULIA_HOME%julia-release-basic.exe" %*

As you can see above, I saved this edited file as a new file (to not mess up other instances of julia) and referenced the new file from my 'Main.sublime-menu' file.

Now you can go to Tools>SublimeREPL>Julia and a new tab should pop up with a functioning Julia REPL. Enjoy!

I'll try to track and bugs I run into. 2 'nice-to-haves' I'll try to figure out will be fixing the key bindings to send code to the REPL (I believe this only works for the python and ruby repls) and console syntax.

Thanks again Patrick for the help.

-Jacob




Jacob Quinn

unread,
Apr 22, 2013, 5:17:44 PM4/22/13
to julia...@googlegroups.com
I know this is extremely delayed, but I finally got my act together and put all my working SublimeREPL stuff into it's own repo. Feel free to check it out and let me know if you have any questions. Should work on Windows and Linux at least.


Cheers,

-Jacob


On Wednesday, March 6, 2013 5:12:16 AM UTC-6, Ceyhun Can ÜLKER wrote:
Hello, 

For the sake of completeness let me ask about linux. :)

I just tried your tutorial on Linux, in my case I needed to put the files into following paths:
/home/<username>/.config/sublime-text-2/Packages/SublimeREPL/config/Julia/Default.sublime-commands
/home/<username>/.config/sublime-text-2/Packages/SublimeREPL/config/Julia/Menu.sublime-menu

And here is the contents:

Default.sublime-commands
[
    {
        "caption": "SublimeREPL: Julia",
        "command": "run_existing_window_command", "args":
        {
            "id": "repl_julia",
            "file": "config/Julia/Main.sublime-menu"
        }
    }
]

Menu.sublime-menu
[
     {
        "id": "tools",
        "children":
        [{
            "caption": "SublimeREPL",
            "mnemonic": "r",
            "id": "SublimeREPL",
            "children":
            [
                {"command": "repl_open", 
                 "caption": "Julia",
                 "id": "repl_julia",
                 "mnemonic": "s",
                 "args": {
                    "type": "subprocess",
                    "encoding": "utf-8",
                    "cmd": "/home/ceyhun/Applications/julia/usr/bin/julia-release-basic",
                    "cwd": "$file_path",
                    "external_id": "julia",
                    "syntax": "Packages/Julia/Julia.tmLanguage",
                    "suppress_echo": false, 
                    "cmd_postfix": "\n", 
                    "env": {}
                    }
                }
            ]   
        }]
    }
]


Even though I can see an item in ctrl+shift+p as "SublimeREPL: Julia", nothing happens when I select it. Also there is no menu item for Julia in the list of available REPLs. And yes I retried restarting. 

Can I see what is wrong with what I am doing?
Thanks.
Ceyhun

Ceyhun Can ÜLKER

unread,
Apr 23, 2013, 8:32:38 AM4/23/13
to julia...@googlegroups.com
Hello,

I was silently waiting for this, didn't want to rush anybody. Thanks for making this. After creating a user settings and giving the bin path to env, it worked like a charm on my Linux. 

Cheers,
Ceyhun

Jacob Quinn

unread,
Apr 24, 2013, 11:40:40 AM4/24/13
to julia...@googlegroups.com
Randall, 

To confirm, 

/Applications/Julia.app/Contents/Resources/julia/bin/

is where your "julia-release-basic" executable is located? (Equivalent to /home/username/julia/usr/bin on linux?) If so, I'll add that to the repo README.

-Jacob
 

On Tuesday, April 23, 2013 3:45:44 PM UTC-5, Randall wrote:
It also works great in OS X with the installer for Julia adding the path:

/Applications/Julia.app/Contents/Resources/julia/bin/

Randall

unread,
Apr 24, 2013, 12:21:16 PM4/24/13
to julia...@googlegroups.com
Jacob,

Yes.

To be more clear though, the 'installer' for Julia on Google Code is just an application that you drag to the Applications directory. The "Julia.app" itself is just a directory, like other osx applications. (Double clicking launches Julia in a terminal window, right-clicking gives you an option to explore the contents). The directory acts like a self-contained environment, and is not added to the system's path. However, I use a symbolic link from /Applications/Julia.app/Contents/Resources/julia/bin/julia to /usr/local/bin/julia so that I can type it from any terminal and it works fine.

Other methods of getting Julia than the installer on Google Code may have put julia and julia-release-basic in a different location, but I think this is the most common place that people will find it unless they built it. In rare cases ti may be found in /Users/$USER/Applications/Julia.app/Contents/Resources/julia/bin/, but the default behavior of dragging an application to the Applications folder is to put it in the main directory rather than the user-specific one.

Here's an idea of the layout if it helps:

-Randall

Randall

unread,
Apr 24, 2013, 12:58:33 PM4/24/13
to julia...@googlegroups.com


I'm not sure what happened with posting the image. Here's the same thing:

http://i.imgur.com/hSQ9tEd.png
Reply all
Reply to author
Forward
0 new messages