Skip to content

Unable to load Cabal project into Emacs Haskell-Mode #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
galderz opened this issue May 5, 2015 · 14 comments
Closed

Unable to load Cabal project into Emacs Haskell-Mode #631

galderz opened this issue May 5, 2015 · 14 comments

Comments

@galderz
Copy link

galderz commented May 5, 2015

I'm struggling to get Haskell-Mode working with a Cabal project.... :(

If I run with a simple non-cabal project, it all works fine. But after executing cabal init, answering the questions, then from Emacs calling C-c C-l, I get the message that the Haskell process has died. Here's the output of the process log:

("Starting inferior `cabal repl' process using cabal ..." "cis194" nil "cabal" "repl" "--ghc-option=-ferror-spans")
-> :set prompt "\4"
-> Prelude.putStrLn ""
-> :set -v1
<- Preprocessing library cis194-0.1.0.0...

Event: "finished
"

Process reset.

My cabal file looks like this:

name:                cis194
version:             0.1.0.0
synopsis:            cis194 examples and exercises
description:         cis194 examples and exercises
license-file:        LICENSE
author:              Galder Zamarreño
maintainer:          galder@zamarreno.com
build-type:          Simple
cabal-version:       >=1.10

library
  build-depends:       base >=4.8 && <4.9
  hs-source-dirs:      src
  default-language:    Haskell2010

As a result of this, I think my indention and other modes are not working correctly because after creating src/Week1.hs file like this and saving it, the editor says there's an error in first line and at the bottom I get an indentation failed message like this (Haskell failed Ind company)

module Week1 where

-- Declarations and variables
x :: Int
x = 3
--x = 4

Any ideas what's the problem here?

Here's some version information:

% cabal --version
cabal --version
cabal-install version 1.22.0.0
using version 1.22.0.0 of the Cabal library 
% ghc --version
ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.10.1
haskell-mode       20150504.233
@galderz
Copy link
Author

galderz commented May 5, 2015

My haskell configuration file can be found here: https://gist.github.com/galderz/74b2558f4fb1ddc97154

And finally, here are my custom-set-variables, any ideas:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-safe-themes
   (quote
    ("e80932ca56b0f109f8545576531d3fc79487ca35a9a9693b62bf30d6d08c9aaf" default)))
 '(haskell-process-auto-import-loaded-modules t)
 '(haskell-process-log t)
 '(haskell-process-suggest-remove-import-lines t)
 '(haskell-process-type (quote cabal-repl))
 '(haskell-tags-on-save t))

Any ideas what might be the problem or how to debug it further? The process log does not seem to give any clues on why it stopped :(((

@galderz
Copy link
Author

galderz commented May 5, 2015

One final detail: I'm using a master build of ghc-mod that gets around several issues that I was facing in my environment..., but I don't think it's relevant to this particular issue...

@cocreature
Copy link
Contributor

Can you run cabal repl (outside of emacs) in the directory without problems? Also could you try disabling external modes (modes≠haskell-mode), most notably ghc-mod and report what happens then?

@lukehoersten
Copy link
Member

Nothing stands out to me here so most likely there's an interaction problem with some other plugin. Can you turn everything else off and see if you can still replicate the problem? For example, others have had issues with company mode + haskell-process in the past.

If you're unable to reproduce the problem with nothing but haskell-mode enabled then just bisect your config until you find the culprit.

@galderz
Copy link
Author

galderz commented May 6, 2015

Thanks @cocreature and @lukehoersten for the quick replies! :)

I've tried to run cabal repl in the directory and I'm not sure it's running fine because it finishes immediately, shouldn't it start an interpreter session?

As you can see in the output, it goes straight back to the command line prompt after running very shortly.

/0/h/g/cis194-cabal git:master ❯❯❯ cabal repl
./cis194.cabal has been changed. Re-configuring with most recently used
options. If this fails, please run configure manually.
Resolving dependencies...
Configuring cis194-0.1.0.0...
Preprocessing library cis194-0.1.0.0...
~/0/h/g/cis194-cabal git:master ❯❯❯

Could it be cos I marked it to be a library instead of an executable?

@galderz
Copy link
Author

galderz commented May 6, 2015

I've tried another cabal project and it does indeed open an interpreter session... that might be the reason..., though I don't understand why it does not open an interpreter session in command line, could it be cos no main module has been given?

@cocreature
Copy link
Contributor

You need to have exposed-modules if you have a library. I fixed this bug in cabal a while ago but there has not been a release since.

@gracjan
Copy link
Contributor

gracjan commented May 6, 2015

Open repl even if there are no exposed modules: haskell/cabal@ddbd26c.

@gracjan
Copy link
Contributor

gracjan commented May 6, 2015

So this one seems to be (already fixed) bug in cabal. Should we do something in haskell-mode though, like inform a user that there was no prompt although prompt was expected? Would be great to detect if cabal repl fails to get to the prompt as there are multiple reasons this may fail (syntax error in cabal file, bad linking, bad PATH, wrong nix-shell setup, etc).

@lukehoersten
Copy link
Member

I think haskell-process does warn you and asks if you want to look at the log. So we might be OK already.

@galderz
Copy link
Author

galderz commented May 6, 2015

I've added exposed-modules and now the project gets loaded successfully.

I'm still seeing the (Haskell failed Ind company) message at the bottom though, any ideas about the failed indentation issue? Is it related to haskell-mode?

If it's not related, I'll close the issue.

Thanks a million for your help! Just getting started with Emacs + Haskell and I've had my fair share of bumps :(((

@cocreature
Copy link
Contributor

iirc failed comes from ghc-mod. Try disabling it and see if it still appears.

@galderz
Copy link
Author

galderz commented May 6, 2015

Yeah, it seems related to that... the number of options and interaction between different modules makes Emacs + Haskell quite difficult to get right. With so many options, it takes a while to get an env up :(

I'll close for now and open an issue in ghc-mod to figure out what's up...

Thanks again for all your help!

@geraldus
Copy link
Contributor

geraldus commented May 6, 2015

@galderz by the way, if you use ghc-mod from master, then you need to redirect its output. Check this out DanielG/ghc-mod#454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants