简体   繁体   中英

Set TAB as shortcut for autocompletion in Emacs Haskell mode

I would like to use TAB to autocomplete things when I use Haskell REPL (GHCI) in Emacs (invoked with Cc Cb ). 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).

Expanding upon @chi's comment, you can find the name of the Lisp function using Ch 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)

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

Now we need name of major mode of Haskell REPL, I found out that we can get it with Ch 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM