20

I installed haskel-mode in emacs. Then I write in my .emacs:

(load "~/.emacs.d/haskell-mode/haskell-site-file")
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'haskell-font-lock-symbols t)
(put 'downcase-region 'disabled nil)

What must I add in my conf file that emacs could autocomplete for Haskell? Or Haskell mode there is no such possibility?

nbro
  • 15,395
  • 32
  • 113
  • 196
0xAX
  • 20,957
  • 26
  • 117
  • 206

6 Answers6

18

When there is no language-specific support, you can use tags. This is a generic completion mechanism.

  1. Generate a TAGS file, which contains a list of identifiers and where they are defined. Emacs comes with the etags program to do this in many languages, but not Haskell; ghc comes with hasktags.

  2. Load the TAGS file with M-x visit-tags-table.

Tags are not context-dependent, so they'll indiscriminately suggest types, values, constructors, etc everywhere. They also won't provide advanced features such as easily showing the type of a value. The most important tags commands are:

  • M-TAB (complete-symbol) completes an identifier according to the loaded list of tags.

  • M-. (find-tag) goes to the place where the identifier at point is defined, opening the containing file if necessary.

  • M-* (pop-tag-mark) goes back where you were before M-..

  • M-x tags-apropos shows a list of identifiers matching a regexp.

For more information, look under "Tags" in the Emacs manual.


For an even cruder, but fully automatic mechanism, there is the dynamic abbrev feature. C-M-/ (dabbrev-completion) looks in most open buffers for a completion; this is completely language-independent, so it'll even find words in strings, comments, whatever. M-/ (dabbrev-expand) is similar, but directly completes to the nearest match before point.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
11

ghc-mod provides some completion for Haskell within Emacs, as well as checking with hlint and ghc. In combination with M-/, it's good enough for me.

danlei
  • 14,121
  • 5
  • 58
  • 82
8

haskell-mode currently provides no such possibility. There is some work on implementation of haskell parser for CEDET - in this case, users will get autocompletion features automatically. But this work had started not so much time ago...

nbro
  • 15,395
  • 32
  • 113
  • 196
Alex Ott
  • 80,552
  • 8
  • 87
  • 132
7

My setup is a little more complicated. It uses the auto-complete infrastructure which shows a dropdown list of candidates automatically similar to traditional IDEs. I downloaded this script that hardcodes all the keywords. In addition to that, I use ghc-mod to generate module names.

Wei Hu
  • 2,888
  • 2
  • 27
  • 28
6

As a "cheap and cheerful" autocompletion mechanism, don't overlook M-/. It's completely heuristic and language-independent, but surprisingly effective.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
2

Besides autocompletion for your own code, you can also get autocompletion (with apidocs even) for the standard library, import names, and pragma names using company-ghc. I found this guide to be very helpful. Note, I didn't get it to work fully for myself yet, but I can feel I'm close :-)

Emmanuel Touzery
  • 9,008
  • 3
  • 65
  • 81