
Hi all, I had been using hasktags for tag generation previously, however, I recently discovered that using GHCi with cabal new-repl λ:> :ctags creates a tags file that actually works with preprocessors (e.g. c2hs or alex or happy). Is there any way to run this semi-automatically? echo ':ctags' | cabal new-repl seems to work in the shell, but I'd like a vim integration if possible (also, it's slow). Cheers, Vanessa McHale

While there is probably a better way, my limited knowledge of vimscript had
me write this and it works well enough
function! UpdateHaskellTags()
if filereadable("tags")
execute "silent !grep -v '" . bufname("%") . "' ./tags > __newtags"
execute "silent !rm tags"
execute "silent !mv __newtags tags"
execute "silent !fast-tags " . bufname("%")
endif
endfunction
autocmd BufWritePost *.hs :call UpdateHaskellTags()
autocmd BufWritePost *.hsc :call UpdateHaskellTags()
This uses fast-tags to regenerate tags for the current file on every save,
but will only work if you are operating from the root of your project (or
wherever you keep your tags). I use ctrlp for navigation so that's never
been a problem for me
Nathan Merkley
On Mon, Apr 1, 2019 at 9:26 AM Vanessa McHale
Hi all,
I had been using hasktags for tag generation previously, however, I recently discovered that using GHCi with
cabal new-repl λ:> :ctags
creates a tags file that actually works with preprocessors (e.g. c2hs or alex or happy).
Is there any way to run this semi-automatically?
echo ':ctags' | cabal new-repl
seems to work in the shell, but I'd like a vim integration if possible (also, it's slow).
Cheers, Vanessa McHale
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Here is a very useful bash script to have lying around:
#!/usr/bin/env bash
shopt -s nullglob
while true; do
if [[ "$PWD" == "$HOME"
|| "$PWD" == /
|| -f "$PWD/package.yaml"
|| -f "$PWD/stack.yaml"
|| -n "$(echo -n ./*.cabal)" ]]; then
exec "$@"
else
cd ..
fi
done
Name this something like "run-in-project-root", and then you can prefix any
command you run with "run-in-project-root" in order for it to run in the
project's root, as defined by the existence of a package.yaml or stack.yaml
or *.cabal file. (Of course you can customize the exact condition to your
tastes.) So running "run-in-project-root fast-tags filename" is exactly
like running "fast-tags filename" except that fast-tags will execute in the
project root. (And the same for all the other shell commands that you run.)
Of course, this works both when running fast-tags (or any other command)
directly in the shell, and when running a bash snippet in vim with :!, so
long as the "run-in-project-root" script is in a directory that's in your
$PATH.
On Mon, Apr 1, 2019 at 5:56 PM Nathan Merkley
While there is probably a better way, my limited knowledge of vimscript had me write this and it works well enough
function! UpdateHaskellTags() if filereadable("tags") execute "silent !grep -v '" . bufname("%") . "' ./tags > __newtags" execute "silent !rm tags" execute "silent !mv __newtags tags" execute "silent !fast-tags " . bufname("%") endif endfunction
autocmd BufWritePost *.hs :call UpdateHaskellTags() autocmd BufWritePost *.hsc :call UpdateHaskellTags()
This uses fast-tags to regenerate tags for the current file on every save, but will only work if you are operating from the root of your project (or wherever you keep your tags). I use ctrlp for navigation so that's never been a problem for me
Nathan Merkley
On Mon, Apr 1, 2019 at 9:26 AM Vanessa McHale
wrote: Hi all,
I had been using hasktags for tag generation previously, however, I recently discovered that using GHCi with
cabal new-repl λ:> :ctags
creates a tags file that actually works with preprocessors (e.g. c2hs or alex or happy).
Is there any way to run this semi-automatically?
echo ':ctags' | cabal new-repl
seems to work in the shell, but I'd like a vim integration if possible (also, it's slow).
Cheers, Vanessa McHale
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Unfortunately, fast-tags doesn't work with happy/alex/c2hs preprocessors :( Cheers On 4/1/19 10:56 AM, Nathan Merkley wrote:
While there is probably a better way, my limited knowledge of vimscript had me write this and it works well enough
function! UpdateHaskellTags() if filereadable("tags") execute "silent !grep -v '" . bufname("%") . "' ./tags > __newtags" execute "silent !rm tags" execute "silent !mv __newtags tags" execute "silent !fast-tags " . bufname("%") endif endfunction
autocmd BufWritePost *.hs :call UpdateHaskellTags() autocmd BufWritePost *.hsc :call UpdateHaskellTags()
This uses fast-tags to regenerate tags for the current file on every save, but will only work if you are operating from the root of your project (or wherever you keep your tags). I use ctrlp for navigation so that's never been a problem for me
Nathan Merkley
On Mon, Apr 1, 2019 at 9:26 AM Vanessa McHale
mailto:vanessa.mchale@iohk.io> wrote: Hi all,
I had been using hasktags for tag generation previously, however, I recently discovered that using GHCi with
cabal new-repl λ:> :ctags
creates a tags file that actually works with preprocessors (e.g. c2hs or alex or happy).
Is there any way to run this semi-automatically?
echo ':ctags' | cabal new-repl
seems to work in the shell, but I'd like a vim integration if possible (also, it's slow).
Cheers, Vanessa McHale
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Benjamin,
Thanks for that, that should come in very handy
Vanessa,
While I haven't tried it, you should be able to replace fast-tags with any
tool of your choice, as the script is just running a sequence of shell
commands. The one caveat is that the script I sent generates tags on a
per-file basis, so if generating them from the repl doesn't merge the tags
file, you will have to change it to instead generate tags for the entire
project directory
Nathan Merkley
On Mon, Apr 1, 2019, 12:10 PM Vanessa McHale
Unfortunately, fast-tags doesn't work with happy/alex/c2hs preprocessors :(
Cheers On 4/1/19 10:56 AM, Nathan Merkley wrote:
While there is probably a better way, my limited knowledge of vimscript had me write this and it works well enough
function! UpdateHaskellTags() if filereadable("tags") execute "silent !grep -v '" . bufname("%") . "' ./tags > __newtags" execute "silent !rm tags" execute "silent !mv __newtags tags" execute "silent !fast-tags " . bufname("%") endif endfunction
autocmd BufWritePost *.hs :call UpdateHaskellTags() autocmd BufWritePost *.hsc :call UpdateHaskellTags()
This uses fast-tags to regenerate tags for the current file on every save, but will only work if you are operating from the root of your project (or wherever you keep your tags). I use ctrlp for navigation so that's never been a problem for me
Nathan Merkley
On Mon, Apr 1, 2019 at 9:26 AM Vanessa McHale
wrote: Hi all,
I had been using hasktags for tag generation previously, however, I recently discovered that using GHCi with
cabal new-repl λ:> :ctags
creates a tags file that actually works with preprocessors (e.g. c2hs or alex or happy).
Is there any way to run this semi-automatically?
echo ':ctags' | cabal new-repl
seems to work in the shell, but I'd like a vim integration if possible (also, it's slow).
Cheers, Vanessa McHale
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to:http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On Mon, Apr 1, 2019 at 11:09 AM Vanessa McHale
Unfortunately, fast-tags doesn't work with happy/alex/c2hs preprocessors :(
Oh I guess it doesn't. Support wouldn't be hard to add though, I think it just needs to understand LINE pragmas. Then you'd have to do some editor hackery to get it to run on the generated output when you edit the source file, e.g. if expand('%') =~ *.chs; then "fast-tags build/chs/" + expand('%'); else ... Substitute build/chs/ for wherever your build puts the generated .hs files of course. Add a feature request if you think you'd use such a feature. Also note that fast-tags directly supports cabal files, I do a `fast-tags --cabal **/*.cabal` on a hackage snapshot to get tags for all of hackage and ghc, and then make that be the secondary tags file, so I can jump to any definition, internal or external.

On Mon, Apr 1, 2019 at 8:56 AM Nathan Merkley
While there is probably a better way, my limited knowledge of vimscript had me write this and it works well enough
function! UpdateHaskellTags() if filereadable("tags") execute "silent !grep -v '" . bufname("%") . "' ./tags > __newtags" execute "silent !rm tags" execute "silent !mv __newtags tags" execute "silent !fast-tags " . bufname("%") endif endfunction
autocmd BufWritePost *.hs :call UpdateHaskellTags() autocmd BufWritePost *.hsc :call UpdateHaskellTags()
If I'm reading it right, this goes to a lot of work to defeat (or reimplement?) the default incremental tagging. Why not just 'execute fast-tags %'? I use a script like "if [[ -r tags ]]; then fast-tags -R; else fast-tags $1; fi" for that first generate, and put 'rm tags' in the merge posthook.
participants (4)
-
Benjamin Fox
-
Evan Laforge
-
Nathan Merkley
-
Vanessa McHale