I’ve installed Haskell on my Mac using Homebrew, that is brew install ghc haskell-platform.
I’m looking for a way to generate a ctags file of the standard Haskell Platform libraries (modules) so I could browse the source while coding in Vim. I specifically need Prelude and the other most popular modules, like Data.List and such.
I am aware that the source is available on the web via Hoogle, but It’ll be easier for me to jump-to-source whenever I need to, for learning purposes.
- Where is the source located when installing the Haskell Platform?
- Is the source even installed when installing the Haskell Platform, or just the compiled binaries or something of the sort?
- How can I make the source available for browsing in Vim? As in put the generated
tagsfile somewhere and tell Vim to read from it. I also understand there’s no need to re-generate thetagsfile, since these modules are pretty much static and don’t get updated very often.
1) and 2) were answered by permeakra in comments. I’ll try to cover 3) by describing setup similar to the one I’m using. First simple solution for base libraries, then more generic solution for whatever Haskell source package in general.
As a prerequisites we will need a tool which generates tags file for Haskell:
Instead of
hothasktagsyou might use your favourite one. See for example https://github.com/bitc/lushtags page which enumerates some of these.Then we need to have sources for base libraries available. Here I’m using the ones from GitHub:
Optionally we might switch to particular branch. E.g.:
Run
git branch -ato see all possibilities.Now let’s generate tags for the base libraries (I do not have Mac available and thus have to assume the command works there or you are able to tweak it appropriately):
(Note about sort: My Vim complains when I do not use the sort. For
LC_ALLexplanation see for example this blog post)Now we need to let the Vim know about the tags we generated. The easiest way is probably to put the following line into your
$HOME/.vimrc:This way the tags for base libraries will be set for each Haskell file we open. If this is not desirable we can put following Vim command into
.vimrc:and call
:SetGHCTagson demand.For more generic solution which works with all Haskell sources packages we can use the following function (put into
.vimrcor into Vim file dedicated to Haskell filetype):Utilizing it for example for
Shelly.hslibrary:In Vim just call:
There is space for improvement –
SetHaskellTagscould generate tags if not exist, or could even fetch the sources, configurable Haskell source code storage, directory completion, etc. But works good enough for me now. So at least sharing the solution I have. Will come back here if I get to some of these improvement done.[1]: It’s better to store
regenerate-haskell-tagsin your$PAHT.