Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically reloading ghci & running hlint on file updates

I was thinking about my ideal haskell editing workflow:

  • I open three terminals (split using iterm2).
  • Terminal 1 runs vim for editing the haskell source files.
  • Terminal 2 automatically runs hlint on the changed files whenenver a file in the current directory or subdirectory updates or is created
  • Terminal 3 runs ghci, automatically loading/reloading the changed files.

Has anyone set up anything like this? The goal is to have hlint constantly watch my code for styling problems and for ghci be available for quick changes, without having to do anything other than saving the file in vim.

I was thinking of using something like watchr for the automation.

like image 271
Joe Van Dyk Avatar asked Oct 09 '11 18:10

Joe Van Dyk


1 Answers

You can run arbitrary shell commands in vim using the BufWrite autocommand:

For example, put this in your ~/.vimrc:

au BufWrite *.hs !echo % >> ~/saves.txt 

This will run echo <CURRENT FILENAME> >> ~/saves.txt every time you save a haskell file.

So this is an easy way to trigger external scripts.

Now you can write some iterm scripts to relay commands to your other terminals. Something like:

tell my_ghci_terminal
  write text ":r\n"
end tell
tell my_hlint_terminal
  write text "<RUN HLINT ON WHATEVER>"
end tell

So you can use the vim autocommand to trigger the appropriate iterm script (passing the current file name so the script can tell ghci and hlint which file to process).

You'll probably want to toggle this on and off (you may not want to do this for EVERY haskell file), so think about wrapping the functionality in a vim function that lets you toggle it (as well as set arguments for how iterm should find your ghci and hlint terminals).

like image 188
rampion Avatar answered Oct 03 '22 20:10

rampion