serras / emacs-haskell-tutorial

Tutorial on setting up Emacs to do Haskell programming
690 stars 100 forks source link

Controlling the errors/warnings reported by ghc-mod #10

Closed timbod7 closed 9 years ago

timbod7 commented 9 years ago

How do I configure the ghc emacs mode to run ghc-mod with flags of my choosing? I'd like to disable the warnings related to shadowing of bindings.

A google search has failed to point me in the right direction. Once I find out, I'll update this documentation...

serras commented 9 years ago

You cannot configure ghc-mod itself, since it takes the options from your Cabal configuration. Being in no way particular to ghc-mod, here are two ways in which you can proceed:

{-# GHC_OPTIONS -fno-warn-name-shadowing #-}
timbod7 commented 9 years ago

Hmm. If I add

{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

to the file, then this works ok (But I don't want to put this in every file). Adding

ghc-options: -fno-warn-name-shadowing

to the cabal file doesn't seem to work. Cabal seems to honour this, but ghc-mod does not.

If ghc-mod is meant to read the cabal file, why does ghc-mod give different errors and warnings to a normal cabal build? If I run "cabal build" normally, I see no warnings. If I add:

executable test
     ghc-options: -fWall

to the cabal file, and then run cabal build, I see warning about shadowing. This is as I expect.

However when I run

ghc-mod check <file>

it always shows the warnings. To get the output I want, I need to run:

ghc-mod -g -fno-warn-name-shadowing check <file>

But I don't know how to make the ghc package in emacs do this.

(I am using a cabal sandbox, if that makes any difference)

serras commented 9 years ago

Definitely, you are right. ghc-mod check does not use the information in the Cabal file, but instead always runs the check with the -Wall option. As far as I know, the only way to disable the warnings is in a per-file basis with the {-# LANGUAGE #-} pragma.

serras commented 9 years ago

Closing the issue as it relates to functionality of ghc-mod rather than the tutorial itself.