Skip to content
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

Does ghci mode recognize cabal sandboxes? #398

Closed
fosskers opened this issue Dec 13, 2014 · 22 comments
Closed

Does ghci mode recognize cabal sandboxes? #398

fosskers opened this issue Dec 13, 2014 · 22 comments

Comments

@fosskers
Copy link

Forgive me if this has been asked before, or if the solution is trivial. I'd like to be able to install libraries in a sandbox, then play with them in an emacs session without making a full cabal project (similar to this post on stackoverflow).

Is this possible?

@purcell
Copy link
Member

purcell commented Dec 13, 2014

Just tried this now:

  • cabal sandbox init in a fresh dir
  • cabal install whatever as needed
  • create a foo.hs file in that directory, but no foo.cabal file
  • Use C-c C-l to load the foo.hs file, forcing haskell-mode to create an inferior haskell process

The result: haskell-mode prompts to start a cabal repl in that directory, and just hitting return to accept the defaults got me a repl in which the installed library was accessible.

So yes, it's possible.

@purcell purcell closed this as completed Dec 13, 2014
@fosskers
Copy link
Author

Configured emacs to have haskell-process-type as auto by default. When I try the same thing as you did above I get (from my haskell-process-log):

Starting inferior `cabal repl' process using cabal ...
-> :set prompt "\4"
-> Prelude.putStrLn ""
-> :set -v1
<- Package has never been configured. Configuring with default flags. If this
   fails, please run configure manually.

<- cabal:
<-  No cabal file found.
   Please create a package description file <pkgname>.cabal

Event: "exited abnormally with code 1                                                                                                                          
"                                                                                                                                                              

Process reset.

@purcell
Copy link
Member

purcell commented Dec 13, 2014

Hmm, not sure why you saw different results. I'll reopen this, then, until we've figured it out.

My process log looks similar, but without the abnormal exit:

Starting inferior `cabal repl' process using cabal ...
-> :set prompt "\4"
-> Prelude.putStrLn ""
-> :set -v1
<- GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help

<- Loading package ghc-prim ... linking ... done.
   Loading package integer-gmp ... linking ... done.

<- Loading package base ... linking ... done.

<- Prelude> 
<- �
   ��
-> :load "/tmp/cabalfu/Foo.hs"
<- [1 of 1] Compiling Foo              ( /tmp/cabalfu/Foo.hs, interpreted )

<- Ok, modules loaded: Foo.
   �
-> :load "/tmp/cabalfu/Foo.hs"
<- [1 of 1] Compiling Foo              ( /tmp/cabalfu/Foo.hs, interpreted )
   Ok, modules loaded: Foo.
   �
-> :!cd /private/tmp/cabalfu/ && cabal build
<- Package has never been configured. Configuring with default flags. If this
   fails, please run configure manually.

<- cabal: No cabal file found.
   Please
<-  create a package description file <pkgname>.cabal
   �
-> :load "/tmp/cabalfu/Foo.hs"
<- [1 of 1] Compiling Foo              ( /tmp/cabalfu/Foo.hs, interpreted )

   /tmp/cabalfu/Foo.hs:3:1: Warning:
       The qualified import of ‘Text.Regex.PCRE.Light’ is redundant
         except perhaps to import instances from ‘Text.Regex.PCRE.Light’
       To import instances alone, use:

@purcell purcell reopened this Dec 13, 2014
@fosskers
Copy link
Author

I'm working with a fresh git clone, too. From my .emacs. Nothing looks amiss:

;; Haskell mode                                                              
  (add-to-list 'load-path "/usr/share/emacs/site-lisp/haskell-mode/")
  (require 'haskell-mode-autoloads)
  (add-to-list 'Info-default-directory-list "/usr/share/emacs/site-lisp/haskell-mode/")
;;  (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)                    
  (add-hook 'haskell-mode-hook 'interactive-haskell-mode)
  (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  (custom-set-variables
  '(haskell-process-suggest-remove-import-lines t)
  '(haskell-process-auto-import-loaded-modules t)
  '(haskell-process-log t))
;;  '(haskell-process-type 'ghci))                                             
  (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
  (define-key haskell-mode-map (kbd "C-c h b") 'haskell-interactive-bring)
  (define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
  (define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
  (define-key haskell-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
  (define-key haskell-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
  (define-key haskell-mode-map (kbd "C-c c") 'haskell-process-cabal)
  (define-key haskell-mode-map (kbd "SPC") 'haskell-mode-contextual-space)

I specify the load path at the top because it's a -git version of the haskell-mode Arch linux package, and it won't work unless I do.

@fosskers
Copy link
Author

Steps:

  1. Made a sandbox in a fresh directory.
  2. Did cabal install shelly.
  3. Made the following file:
module ShellyTest where

import Shelly
  1. Checked haskell-process-type. It is auto.
  2. C-c C-l
    • Start a new project named "haskell"? y
    • RET to the next three questions.
  3. Haskell process dies. Log is:
Starting inferior `cabal repl' process using cabal ...
Starting inferior `cabal repl' process using cabal ...
-> :set prompt "\4"
-> Prelude.putStrLn ""
-> :set -v1
<- Package has never been configured. Configuring with default flags. If this
   fails, please run configure manually.

<- cabal
<- : No cabal file found.
   Please create a package description file <pkgname>.cabal

Event: "exited abnormally with code 1"                                                                              

Process reset.
  1. haskell-process-type is still auto. Switched it to ghci.
  2. Haskell process starts, but can't find the library.

@ivan-m
Copy link
Contributor

ivan-m commented Dec 16, 2014

Did you do a cabal configure like the error suggested?

And do you have a .cabal file listing Shelly as a dependency?

@fosskers
Copy link
Author

No to both. The idea is that I just want to be able to make a new directory, lay down a sandbox, install some one-shot libraries, and play with them with ghci as the haskell-process-type and not worry about .cabal files. This seemed to work fine for @purcell but not for me.

@ivan-m
Copy link
Contributor

ivan-m commented Dec 17, 2014

OK, I just tried it, and it works for me (and I have haskell-process-type set to cabal-repl because I forgot to put it on auto after that was introduced; but putting it back to auto didn't change anything.)

Maybe try with a minimal config for emacs to check this?

As a comparison, here's my log:

Starting inferior `cabal repl' process using cabal ...
-> :set prompt "\4"
-> Prelude.putStrLn ""
-> :set -v1
<- GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help

<- Loading package ghc-prim ... 
<- linking ... done.
   Loading package integer-gmp ... linking ... done.
   Loading package base ... linking ... done.
   Prelude> �
-> :load "/tmp/testing/test.hs"
<- 

<- ��[1 of 1] Compiling Testing          ( /tmp/testing/test.hs, interpreted )

<- 
   /tmp/testing/test.hs:3:1: Warning:
       The import of ‘Shelly’ is redundant
         except perhaps to import instances from ‘Shelly’
       To import instances alone, use: import Shelly()
   Ok, modules loaded: Testing.
   �

@fosskers
Copy link
Author

Still isn't working, and this is all I have in my .emacs:

(add-to-list 'load-path "/usr/share/emacs/site-lisp/haskell-mode/")
(require 'haskell-mode-autoloads)
(add-to-list 'Info-default-directory-list "/usr/share/emacs/site-lisp/haskell-mode/")
;;  (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)                    
(add-hook 'haskell-mode-hook 'interactive-haskell-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(custom-set-variables
 '(haskell-process-suggest-remove-import-lines t)
 '(haskell-process-auto-import-loaded-modules t)
 '(haskell-process-log t))
(define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
(define-key haskell-mode-map (kbd "C-c h b") 'haskell-interactive-bring)
(define-key haskell-mode-map (kbd "C-c C-t") 'haskell-process-do-type)
(define-key haskell-mode-map (kbd "C-c C-i") 'haskell-process-do-info)
(define-key haskell-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
(define-key haskell-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
(define-key haskell-mode-map (kbd "C-c c") 'haskell-process-cabal)
(define-key haskell-mode-map (kbd "SPC") 'haskell-mode-contextual-space)
(global-set-key (kbd "C-c h r") 'haskell-process-restart)

@fosskers
Copy link
Author

Any word on this?

@ivan-m
Copy link
Contributor

ivan-m commented Dec 30, 2014

Just to confirm: by a "fresh git clone" you mean of the haskell-mode repository?

What I've done:

  • Copy your init setup into a fresh file; change the haskell-mode directories to being to where mine is (/home/ivan/.emacs.d/elpa/haskell-mode-20141223.1144).
  • Change the require to load (as it didn't work otherwise)
  • emacs -Q test.emacs.el &
  • cd /tmp/ && mkdir test-shelly && cd test-shelly
  • cabal sandbox init && cabal install shelly
  • In emacs, C-x C-f /tmp/test-shelly/Test.hs
  • Put in the contents of the file, save
  • Hit C-c C-l
  • Choose y, then hit Enter three times
  • Prompt appears
  • Can now successfully do stuff with Shelly

How are you installing your haskell-mode? You sure you don't have an old version? I'm using MELPA (haven't updated for a while if you notice my load-path change above) and it works.

@fosskers
Copy link
Author

Okay, changing require to load didn't do anything for me. Still dies with the same error. I install this via the Arch Linux AUR package emacs-haskell-mode-git, which has the following install script:

pkgname=emacs-haskell-mode-git
pkgver=20120523
pkgrel=1
_gitname="haskell-mode"
_gitnamebranch="haskell-mode"
_gitroot="git://github.com/haskell/$_gitname"
pkgdesc="Haskell syntax highlighting, etc. for GNU Emacs"
arch=('any')
url="https://github.com/haskell/$_gitname"
depends=('emacs')
makedepends=('git')
license=('GPL')
provides=('emacs-haskell-mode')
conflicts=('emacs-haskell-mode')
install=$pkgname.install

build() {
  # create persistent build directory
  mkdir -p $startdir/src

  cd $startdir/src

  if [[ -d $_gitnamebranch ]]; then
    cd $_gitnamebranch
    git clean -dxf
    git reset --hard
    msg "Pulling from GIT server..."
    git pull --rebase
  else
    git clone --depth 1 $_gitroot $_gitnamebranch
    cd $_gitnamebranch
    git pull --rebase
  fi

  # generate the haskell-mode-autoloads.el file and also execute byte compilation
  make all
}

package() {
  # create destination path
  install -d $pkgdir/usr/share/emacs/site-lisp/$_gitnamebranch
  # copy over all files into path
  cp -r $startdir/src/$_gitnamebranch/* $pkgdir/usr/share/emacs/site-lisp/$_gitnamebranch
}

@fosskers
Copy link
Author

Also just tried your method, by uninstalling the Arch package and linking instead to my elpa version.

  ;; Haskell mode                                                                                                                                              
  (add-to-list 'load-path "/home/colin/.emacs.d/elpa/haskell-mode-20141230.1141")
  (load "haskell-mode-autoloads.el")
  (add-to-list 'Info-default-directory-list "/home/colin/.emacs.d/elpa/haskell-mode-20141230.1141")
;; etc ...

... and it still dies with the same error, following the same steps you did.

@purcell
Copy link
Member

purcell commented Dec 30, 2014

So do you have a different cabal / ghc version to us? What have you got there?

@ivan-m
Copy link
Contributor

ivan-m commented Dec 30, 2014

@fosskers just to be sure, you tried it with emacs -Q (so it didn't use any Arch-specific config settings)?

@fosskers
Copy link
Author

I'm on 1.18.1.3 for cabal and 7.8.3 for ghc.

@fosskers
Copy link
Author

emacs -Q then doesn't load any of my Haskell stuff, as that's all in my .emacs. Should it be elsewhere?

@ivan-m
Copy link
Contributor

ivan-m commented Dec 31, 2014

If you follow what I did, I did emacs -Q, opened the file and then M-x eval-buffer (which I just realised I forgot to mention); this makes sure that it's only that fragment of config that's being used and not something else interfering.

@fosskers
Copy link
Author

fosskers commented Jan 4, 2015

I've managed to succeed in following your instructions, in that I can open my test file with a minimal config (I can tell because a lot of my customisations are missing) but unfortunately C-c C-l still dies with the same error.

@fosskers
Copy link
Author

fosskers commented Jan 4, 2015

Interesting, when I run the program cabal repl in a directory without a cabal file I get exactly the text we've been seeing:

Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
cabal: No cabal file found.
Please create a package description file <pkgname>.cabal

The exit code is also coming out as 1.

What do you see?

@ivan-m
Copy link
Contributor

ivan-m commented Jan 4, 2015

Just to double-check: what does cabal -V say? I have 1.20.0.4.

$cabal repl
GHCi, version 7.8.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> 

@fosskers
Copy link
Author

fosskers commented Jan 4, 2015

Solution: Have the latest cabal-install.

The Arch cabal-install package was at 1.18.x but I made a sandbox, updated cabal in there (it pulls down other libs to compile, which I didn't want clobbering my global haskell environment), then added it to my path ahead of /usr/bin. I'm now on 1.20.0.6, and everything works. Calling cabal repl in the shell opens the repl as it should, and I can load Shelly as desired in emacs.

Note: I had to restart my emacs daemon once to (I assume) get it to "see" the newer cabal binary.

Thanks a lot for your help and patience guys.

@fosskers fosskers closed this as completed Jan 4, 2015
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

3 participants