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 <nathanmerkley@gmail.com> 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 <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.