emacs Haskell配置

Interactive commands

As usual, enabling a new feature in the Haskell mode involves changing some configuration file. In particular, we need to enable the interactive features and also define the key bindings to be used. Opening the configuration file is becoming normal for you now, so do so and add:

(custom-set-variables
  '(haskell-process-suggest-remove-import-lines t)
  '(haskell-process-auto-import-loaded-modules t)
  '(haskell-process-log t))
(eval-after-load 'haskell-mode '(progn
  (define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-or-reload)
  (define-key haskell-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)
  (define-key haskell-mode-map (kbd "C-c C-n C-t") 'haskell-process-do-type)
  (define-key haskell-mode-map (kbd "C-c C-n C-i") 'haskell-process-do-info)
  (define-key haskell-mode-map (kbd "C-c C-n C-c") 'haskell-process-cabal-build)
  (define-key haskell-mode-map (kbd "C-c C-n c") 'haskell-process-cabal)))
(eval-after-load 'haskell-cabal '(progn
  (define-key haskell-cabal-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)
  (define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-mode-clear)
  (define-key haskell-cabal-mode-map (kbd "C-c C-c") 'haskell-process-cabal-build)
  (define-key haskell-cabal-mode-map (kbd "C-c c") 'haskell-process-cabal)))

Note that the key bindings deviates from the ones in the wiki. The reason to do so is to avoid conflicts with key bindings in ghc-mode and HaRe.

A piece of advice: if you are using a modern version of Cabal (more than 1.18), you should use its integrated REPL capabilities instead of ghci. This will ensure that your projects stay sandboxed, instead of polluting the global database. To enable it, add

(custom-set-variables '(haskell-process-type 'cabal-repl))

to your personal configuration file. If you are using Stack as your build tool, you can also choose to use it for the REPL by writing instead:

(custom-set-variables '(haskell-process-type 'stack-ghci))

In both cases, if your personal configuration file already has a custom-set-variables command, you'll need to instead add a blank space and then '(haskell-process-type 'chosen-process-type) before its closing parenthesis.

As always, once you're done editing this file, save it and M-x eval-buffer RET to apply the changes to your running Emacs session.

In order to use the rest of the features in haskell-mode, you need to establish a connection with an interpreter, which can be then queried for information about your file. This is called loading a file, and it's done by running C-c C-l in the file. You will be asked about the root of the Cabal project, which should be auto-configured for you anyway, and then you will get a interpreter window with a λ> prompt.

https://github.com/serras/emacs-haskell-tutorial/blob/master/tutorial.md
--------------------------------
One reason for the error `The Haskell process `haskell' has died. Restart?'
is that Emacs cannot find the location of the GHCi executable. The
following fix will find this location and add it to the Emacs path.

Note that the solution given is only for OS X / Linux, and it has only
been tested on OS X. Windows installations of Haskell don't seem to have
this problem - if yours does, try the same fix, but with "where" in place
of "which". Also note that any number of problems seem to produce the same
error, so this is not guaranteed to work (but when done correctly seemed
to work for most students at the session on Friday).

  *   Open a terminal.
  *   execute the following command:

which ghci

  *   If you get an error from this command, Haskell has not been installed
      correctly. Otherwise, note the response given (eg. `/opt/local/bin/ghci')
  *   The path that must be added to the Emacs path is the above response,
      but with `/ghci' removed (eg. `/opt/local/bin').
  *   Copy the following two lines to the end of your Emacs config file:

(setenv "PATH" (concat (getenv "PATH") ":HERE"))
(setq exec-path (append exec-path '("HERE")))

  *   Replace HERE with the path described above.
  *   Restart Emacs.

Note that the Emacs config file is usually located at the path `~/.emacs'.
You can also access the Emacs config file by executing the following within
Emacs:

M-: (find-file user-init-file)
(setq haskell-program-name "/some/where/ghci.exe")


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值