0
votes

I would like to use TAB to autocomplete things when I use Haskell REPL (GHCI) in Emacs (invoked with C-c C-b). M-/ is good enough for me, but I don't know name of this function to bind TAB to it (TAB works for tabulation (surprised?) in interactive mode and I found it completely useless).

I wish these changes applied only to interactive mode, not to general editing, when TAB works for indentation (and possibly for other things, I haven't completely understood everything yet).

2
IIRC, C-h k M-/ should tell you the name of the Lisp function which is bound to M-/. After discovering that name, you have to bind TAB to it when you are in the interactive mode. I am not fluent enough in elisp to recall how to do this, though. - chi

2 Answers

1
votes

Expanding upon @chi's comment, you can find the name of the Lisp function using C-h k M-/ which gives hippie-expand function.

To bind TAB in ghci interactive mode, use the following elisp code:

(define-key haskell-interactive-mode-map (kbd "TAB") 'hippie-expand)

Or if you want to bind it in normal haskell-mode then:

(define-key haskell-mode-map (kbd "TAB") 'hippie-expand)
0
votes

OK, using great comment by chi, I found out that name of the function bound to M-/ is dabbrev-expand (via C-h k M-/).

Now we need name of major mode of Haskell REPL, I found out that we can get it with C-h v major-mode, it is actually inferior-haskell-mode.

Then, I guess there is inferior-haskell-mode-hook, which we can use to tweak something when REPL frame gets created.

To add local shortcut binding one should use define-key. Value of parameter keymap can be obtained via current-local-map.

Knowing these facts, we can write:

(add-hook 'inferior-haskell-mode-hook
          (lambda ()
            (define-key (current-local-map) (kbd "<tab>") 'dabbrev-expand)))

As far as I can tell it works perfectly, now TAB works for autocompletion in REPL mode and for indentation in others.