Sublime Forum

One use for showInputPanel: interactive Haskell prompt

#1

Saw this function in the changelog for the latest beta and couldn’t find any examples yet on how to use it yet, so I played around a little:

class GhcExpressionCommand(sublimeplugin.TextCommand): def run(self, view, args): view.window().runCommand("save") runexpr = lambda e: view.window().runCommand("exec","","ghc.exe -e \"" + e.replace("\"","\\\"") + "\" \"" + view.fileName() + "\""]) view.window().showInputPanel("Run Ghc expression:", "", runexpr, lambda s:s, 0)
Bind with something like

<binding key="F8" command="ghcExpression"> <context name="selector" value="source.haskell"/> </binding>
and voila, an interactive Haskell prompt in Sublime text. Useful for things like checking types or quickly testing the output of a function.
It should work for other languages as well, assuming they can run commands on a file from the command line.

Very useful addition, thanks jps!

0 Likes

#2

Definitely. With the input panel and the quick panel, we’ve got some really nice tools for adding interactivity. Thumbs up from me, too!

0 Likes

#3

This would also be useful for vi emulation; pop up a panel and type “s/search/replace” to do a vi-style search-and-replace. Our man vim will be very happy, I suspect…

0 Likes

#4

:smiley:

0 Likes