wuub/SublimeREPL — pull request #133 by lionandoil (2013-02-13 14:09:19+00:00)
Title: Adding support for Repls to load files directly from disk

Up until now "Eval file in repl" would simply send the current file's contents to the repl, adding a command-postfix. If something goes wrong this can lead to not very useful error messages like this:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: foo in this context, compiling:(NO_SOURCE_PATH:1927)
Even worse, when there's a syntax problem the repl might be waiting for more input and become unresponsive, as is the case when you load a lisp file with an unmatched parens a la

(foo
which would simply block the repl without a message until the user enters a ")", which results in delayed execution or an error message.

A better approach seems to be using language-specific load commands (Python's execfile(), Clojure's (load-file) etc). Probably the best way to do this would be by adding a load_file() method to the Repl-class, but this would also lead to a lot of overhead in terms of creating new subclasses. So instead I duplicated the SENDERS infrastructure in text_transfer.py to add custom FILELOADERS for different languages, defaulting to the old approach of just sending the file's contents to the repl. So far I've only added custom treatments for Clojure and Python but adding new ones is easy, the only thing that has to be watched out for is how filenames have to be escaped differently for different languages. That's what the above error message looks like now:

CompilerException java.lang.RuntimeException: Unable to resolve symbol: foo in this context, compiling:(/home/kevin/foo/src/core.clj:5)
and instead of waiting for a user-supplied ):

CompilerException java.lang.RuntimeException: EOF while reading, starting at line 212, compiling:(/home/kevin/foo/src/core.clj:7)