Skip to content

Instantly share code, notes, and snippets.

@lspitzner
Last active January 24, 2023 01:20
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lspitzner/097c33177248a65e7657f0c6d0d12075 to your computer and use it in GitHub Desktop.

my sublime setup for haskell includes:

  • SublimeHaskell, but with most features disabled. mostly for syntax highlighting. (as was pointed out, it is sufficient to grab the *theme file and omit the rest of the plugin. And even that is optional.)
  • for auto-formatting:
    • this (slightly modified) external-command plugin: https://github.com/lspitzner/SublimeExternalCommand
    • brittany (installed so that is on path)
    • the below keybind (you can open the user keybindings in sublime and merge the below)
    • you can either select some function and reformat that by pressing f9, or select nothing (whole file gets formatted)
  • for quick compilation feedback:
    • ghcid, invoked via some minimal bash script "run-ghcid": ghcid -o=ghcid.txt -c"cabal new-repl $@" which is used e.g. ./run-ghcid lib:myproject
    • ghcid is running in the background and continuously updates ghcid.txt, which we will tell sublime to read.
    • the below sublime "build system", placed where your sublime installation has those (.config/sublime-text-3/Packages/User/)
    • save your sublime project (at the root of your project) so that script looks for the ghcid.txt in the right place
    • select the "haskell-ghcid" as the "build system" and voila, ctrl-b gives compiler output and allows to jump-to-error via f4
    • remember to enable -Wall and -Werror with your cabal/stack/whatever setup
    • ctrl-b does not actually trigger re-compilation, but loads the current ghcid output. this is bad (if ghcid has not yet finished you can see old state and have to press ctrl-b again) (but ghcid is rather quick in general, especially compared to any no-ghci-based compilation) but also good (you can press ctrl-b whenever you want, and see the compilation output again instantly)
    • (rarely either sublime-text or ghcid get confused about file handles being simultanenously read and re-written and hick up. deleting ghcid.txt solves this, in my experience.)
    • ghcid can eat up a good chunk of memory. something in the order of maybe 100MB per 1k loc. If you keep ghcid running in background all time, and separately run compilations with optimizations as well from time to time, i'd recommend at least 16GB of ram. (depends on your project size of course.)
    • i rarely, but repeatedly, experience some (sublime?) bug that manifests in sublime ignoring the first n bytes of the ghcid.txt file. i think it comes down to some encoding problem, but i have not really investigated.
{
"working_dir": "${project_path:${folder}}",
"cmd": ["echo ${project_path:${folder}}; cat ghcid.txt"],
"shell": true,
"file_regex": "^(\\S*?):(?|(\\d+):(\\d+)(?:-\\d+)?|\\((\\d+),(\\d+)\\)-\\(\\d+,\\d+\\)):([^\n]*)"
}
#!/bin/bash
CABALPKGNAME=myproject # if you don't set this, reloading on .cabal changes does not work.
ghcid -o=ghcid.txt -c"cabal new-repl --restart "./$CABALPKGNAME.cabal" $@"
[
{
"keys": ["f9"],
"command": "filter_through_command",
"args": { "cmdline": "brittany" }
}
]
@moodmosaic
Copy link

moodmosaic commented Dec 10, 2017

Interesting! I'm curious why you use Sublime Haskell only for syntax highlighting(?) After all, you can just grab it's *theme file.

@lspitzner
Copy link
Author

the answer probably is simply "never fix a running system" - at some point i used more of the sublime-haskell features; then they broke (or i was annoyed by slow compilation feedback and switched to ghcid) and never bothered to clean up. Also i might be used to certain features without being aware..

But indeed I probably would be fine with just the theme. I use global search in projectdir/src,*.hs to "jump to definitions" and ctrl-d (multiple-cursor) for easy refactoring. But those are basic sublime features.

@moodmosaic
Copy link

Also, you don't use/need auto-completion and type-info when hovering into types and function bindings?

@lspitzner
Copy link
Author

(do you get notified for these comments? i was not. and i don't regularly check my gists for new comments.. maybe adding a @moodmosaic helps?)

I do use the simple context-based auto-completion. Not sure if that is from the plugin or from the sublime itself. (i.e. i get auto-completions for words in the current file, but not for, e.g. wild-card imports or any such haskell-specific stuff.)

i don't have any on-hover infos. Typed holes go a long way for this already ("order of arguments of foldr?" insert _ foldr -> ghci(d): _ :: ((a0 -> b0 -> b0) -> b0 -> t0 a0 -> b0) -> IO ()) and otherwise haddock of relevant libs is just an alt-tab to the browser away. (in firefox you can add a shortcut-enabled bookmark for hayoo search, so alt-tab,ctrl-t,h somefunc<enter> brings me here). Of course a proper IDE can still improve on such workflows, but it needs to be reliable. Perhaps haskell-ide-engine will be that reliable IDE backend in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment