How to quickly and easily configure GHC integration for Emacs?

In the past, I tried to get more IDEs, for example, the experience of developing Haskell in Emacs, but I always came across not quite working integration.

Is there a way to get the basic GHC features (like looking for an identifier type or instant compilation using flymake) that just works *. By simple work, do I mean that it integrates well with the rest of the ecosystem (e.g. haskell-mode, cabal)?

* Just working here basically means: only the basic configuration in init.el is required and, possibly, installing the package from Hackage.

+8
emacs haskell ghc
source share
2 answers

For built-in error checking, hdevtools is the best I have found. This is the background server that GHC runs on to speed up program analysis.

It is actually very simple to install: you need one Haskell package:

cabal install hdevtools 

and two Emacs packages, both through Mx list-packages : flycheck and flycheck-hdevtools .

After installing it, you just need to enable it with something like Mx global-flycheck-mode (which you can also place in .emacs .) You can go to the next error with Cx ` . You probably also want to change the facets of the errors and warnings you can do with the Mx customize-group flycheck-faces .

Unfortunately, Emacs mode contains only errors and warnings (including hlint); it does not provide an identifier type choice which, in my opinion, is supported by hdevtools . It also sometimes gives me random parsing errors when running into Unicode names or some extensions; however, if I just ignore them, everything else works. I should probably write a bug report or something else.

+7
source share

Check out Tim's excellent setup:

http://tim.dysinger.net/posts/2014-02-18-haskell-with-emacs.html

UPDATE:

This is what I do:

 (defmacro hcRequire (name &rest body) `(if (require ',name nil t) (progn ,@body) (warn (concat (format "%s" ',name) " NOT FOUND")))) (hcRequire haskell-mode-autoloads (autoload 'ghc-init "ghc" nil t) (add-hook 'haskell-mode-hook (lambda () (ghc-init) (flymake-mode))) (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation) (setq haskell-stylish-on-save t) (setq haskell-process-args-cabal-repl '("--ghc-option=-ferror-spans" "--with-ghc=ghci-ng")) (define-key haskell-mode-map (kbd "Cx Cd") nil) (define-key haskell-mode-map (kbd "Cc Cz") 'haskell-interactive-switch) (define-key haskell-mode-map (kbd "Cc Cl") 'haskell-process-load-file) (define-key haskell-mode-map (kbd "Cc Cb") 'haskell-interactive-switch) (define-key haskell-mode-map (kbd "Cc Ct") 'haskell-process-do-type) (define-key haskell-mode-map (kbd "Cc Ci") 'haskell-process-do-info) (define-key haskell-mode-map (kbd "Cc M-.") nil) (define-key haskell-mode-map (kbd "Cc Cd") nil) (define-key haskell-mode-map (kbd "Cc vc") 'haskell-cabal-visit-file) ;; Do this to get a variable in scope (auto-complete-mode) (defun hc-ac-haskell-candidates (prefix) (let ((cs (haskell-process-get-repl-completions (haskell-process) prefix))) (remove-if (lambda (c) (string= "" c)) cs))) (ac-define-source haskell '((candidates . (hc-ac-haskell-candidates ac-prefix)))) (defun hc-haskell-hook () (add-to-list 'ac-sources 'ac-source-haskell)) (add-hook 'haskell-mode-hook 'hc-haskell-hook) ;; auto-complete-mode so can interact with inferior haskell and popup completion ;; I don't always want this. Just turn on when needed. ;;(add-hook 'haskell-mode-hook (lambda () (auto-complete-mode 1))) ) ;; I'm not using this (YET) ;;(hcRequire shm ;; (add-hook 'haskell-mode-hook 'structured-haskell-mode)) 
+7
source share

All Articles