haskell在emacs中复制 [英] haskell repl in emacs
问题描述
我有 haskell-mod
和 ghc-mod
最新的 emacs 24.3.1
。 GHC是 7.6.3
我已经创建了一个haskell文件first.hs,当我做 Cc Cl
它询问:
启动一个名为haskell的新项目? y或n
我的目录名是haskell。我按y
设置cabal目录
我已尝试使用〜/ .cabal和我当前的目录名为 haskell
设置当前目录
只需按下Enter即可有haskell目录
它显示错误消息:
haskell过程-start:cl-ecase failed:cabal-rep,(ghci quote cabal-repl quote cabal-ghci quote cabal-dev quote)
我如何获得副本?
我看到我可能需要降级ghc版本才能使其工作。
这是一个很好的解决方案吗?
解决方案:
init.el中的多个 custom-set-variables
,导致问题。
更新2017
现在我们有 Intero 我建议您尝试Intero / Stack - 它的效果非常好。
随着它的配置更加细微:
;; -------------------------------------------------- --------------------
;; HASKELL
(require'haskell-mode)
(require'intero)
(add-hook'haskell-mode-hook'intero-mode)
(require'flycheck)
(setq flycheck-check-syntax-automatically'(保存新行))
(flycheck-add-next-checker'intero'(warning。haskell-hlint))
关于 REPL ,您基本上只是加载文件,然后加载 Cc Cl
到repl(你可以随时在
Cc Cz
之间切换两个窗口,您可以使用 Cc清除repl-buffer Ck
(内部时)。
唯一的缺点是Intero通常安装在您的项目本地,所以首次启动进入新项目将需要一段时间才能下载/编译/启动 - 但这并不重要,您会获得很多收益。
更新
现在, stack
出来并运行得很好,我建议设置 haskell -process-type
to auto
,也许安装 ghc-mod
使用堆栈。
这里是我使用的当前设置:
(require'haskell-mode)
(add-hook' haskell-mode-hook'on-haskell-doc-mode)
(add-hook'haskell-mode-hook'turn-on-haskell-indentation)
(add-hook'haskell-模式钩子'linum模式)
(add-to-list'exec-path〜/ .local / bin)
(eval-after-load'haskell-mode'(progn
(define-key haskell-mode-map(kbdCc Cl)'haskell-process-load-file)
(define-key haskell-mode-map(kbdCc Cn Ct)'haskell -process-do-type)
(define-key haskell-mode-map(kbdCc Cn Ci)'haskell-process-do-info)
(define-key haskell-mode-map \C-ch'haskell-hoogle)))
(eval-after-load'haskell-cabal'(progn
(define-key haskell-cabal-mode-map(kbdCc Ck)'haskell-interactive-ode-clear)
(define-key haskell-cabal-mode-map(kbdCc Cc)'haskell-process- cabal-build)
(define-key haskell-cabal-mode-map(kbdCc c)'haskell-process-cabal))
(require'company-ghci)
(push'company-ghci company-backends)
(add-hook'haskell-mode-hook'company-mode)
(add-hook'haskell-interactive-mode-hook'公司模式)
正如你所看到的,我基本上摆脱了所有的 ghc -mod
相关的东西( stack 的工作原理与当前 haskell-mode
)并替换为公司
后端(虽然这一个很慢,我希望找到更好的东西)
变量
您通常在Emacs / Haskell模式配置中设置的论文
(custom-set-variables
;;这里有更多的这些 - 这些是Haskell相关的:
'(haskell-font-lock-symbols(quote unicode))
'(haskell-hoogle-command nil)
' (haskell-mode-hook
(quote
(linum-mode turn-on-haskell-indentation turn-on-haskell-doc-mode))t)
'(haskell-process- auto-import-loaded-modules t)
'(haskell-process-load-or-reload-prompt t)
'(haskell-process-log t)
'(haskell-process -suggest-language-pragmas nil)
'(haskell-process-suggest-no-warn-orphans t)
'(haskell-process-type(quote auto))
'(haskell -process-use-presentation-mode t)
'(haskell-tags-on-save t)
'(lower-haskell-wait-and-jump t)
'(safe-局部变量值
(报价
((haskell-process-use-ghci。t)
(haskell-indent-spaces。4))))
(uniquify) ))
这些是我添加的包:
- haskell-mode
- 公司(不是Haskell-rel
- 公司名称
- company-ghci
- ghci-completion
- 莎士比亚模式(对于Yesod)
- company-quickhelp(为了很好的显示
:i
)
首先
如果它要求您的 cabal目录 - 它想知道你的 myProject.cabal
文件的位置 - 如果你没有一个只是拿起文件夹的文件夹(默认 - 我认为默认/找到从来没有让我失望,直到现在)。
如果你需要一些sample-.emacs-setup
这里是我的 .emacs
文件中适用于我的部分:
(autoload'ghc-initghcnil t)
(autoload'ghc-debugghcnil t)
(add- hook'haskell-mode-hook(lambda()(ghc-init)))
(add-hook'haskell-mode-hook'turn-on-haskell-indentation)
eval-after-load'haskell-mode'(progn
(define-k haskell-mode-map(kbdCcCl)'haskell-process-load-or-reload)
(define-key haskell-mode-map(kbdC-`)'haskell-interactive-带来)
(define-key haskell-mode-map(kbdCc Cn Ct)'haskell-process-do-type)
(define-key haskell-mode-map(kbdCc Cn (kCc Cn Cc)'haskell-process-cabal-build'
(define-key hascell-process-do-info)
haskell-mode-map(kbdCc Cn c)'haskell-process-cabal))
(eval-after-load'haskell-cabal'(progn
(define-key haskell-cabal -mode-map(kbdC-`)'haskell-interactive-bring)
(define-key haskell-cabal-mode-map(kbdCc Ck)'haskell-interactive-ode-clear)
(define-key haskell-cabal-mode-map(kbdCc Cc)'haskell-process-cabal-build)
(define-key haskell-cabal-mode-map(kbdCc c)'haskell-process-cabal)))
(custom-set-variables
'(haskell-interactive-mode-hide-multi-line-errors nil)
'(haskell- process-log t)
'(haskell-process-type(quote cabal-repl)))
请注意与(引用cabal-repl)
的部分 - 这应该与cabal沙箱配合使用。
此外,还将向名为 haskell-process-log 的缓冲区添加更多日志信息,您可以在其中找到有关您的问题的更多信息。
我使用这个与GHC 7.8.3 和GHC 7.8.3编译的 ghc-mod版本5.1.0.2。
当然,您必须确保您的 .cabal
文件夹和 ghc-mod
的位置在您的路径(我认为您可以在emacs设置中的某个地方进行配置,但这样做会更容易)。
备注
- 您必须在emacs中安装软件包
ghc
不是ghc-mod
。 - 我有不同版本的ghc-mod和emacs包之前的问题 - 所以请确保您获得最新的cabal-install,然后重新安装emacs-package只有解决ghc输出的问题,虽然在我身上)
进一步信息
如果这不能帮助你请自由
- 添加评论
- 看看 happy haskell programming page
- 有一个查看 emacs上的ghc wiki
在我的机器上运行的示例
我编辑了一个这样的示例文件:
然后我打Cc Cl并按y:
并接受文件夹(这是文件所在的位置)和任何其他问题与Ret - 现在你应该看到 * haskell *
缓冲区带有友好的邮件/ lambda:
最后我可以检查该文件是否有adid:
Hi i am starting with haskell and trying to set up my emacs for its development.
I have haskell-mod
and ghc-mod
latest in emacs 24.3.1
. GHC is 7.6.3
i have created a haskell file first.hs and when i do C-c C-l
It asks :
start a new project named haskell ? y or n
my directory name is haskell. I press y
Set the cabal directory
I have tried with both ~/.cabal and my current directory named haskell
Set the current directory
Just pressed enter as it has haskell directory
It shows error messages :
haskell-process-start: cl-ecase failed: cabal-rep, (ghci quote cabal-repl quote cabal-ghci quote cabal-dev quote)
How can i get the repl ?
I read that i may need to downgrad the ghc version to make it work. Is that good solution ?
Solution :
I had multiple custom-set-variables
in init.el and it led to the problem.
UPDATE 2017
now that we have Intero I would suggest you try Intero/Stack - it works rather well.
With it my config is slimmed even more down:
;; ----------------------------------------------------------------------
;; HASKELL
(require 'haskell-mode)
(require 'intero)
(add-hook 'haskell-mode-hook 'intero-mode)
(require 'flycheck)
(setq flycheck-check-syntax-automatically '(save new-line))
(flycheck-add-next-checker 'intero '(warning . haskell-hlint))
Concerning the REPL you basically just load the file and then C-c C-l
into the repl (you can always switch between the two windows with C-c C-z
and you can clear out the repl-buffer with C-c C-k
(when inside).
The only drawback is that Intero is usually installed locally in your project, so the first startup into a new project will take a while for Intero to download/compile/boot-up - but it's no big deal and you gain much.
UPDATE
Now that stack
is out and running great I would recommend setting the haskell-process-type
to auto
and maybe installing ghc-mod
using stack.
here is the current setup I am using:
(require 'haskell-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'linum-mode)
(add-to-list 'exec-path "~/.local/bin")
(eval-after-load 'haskell-mode '(progn
(define-key haskell-mode-map (kbd "C-c C-l") 'haskell-process-load-file)
(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 "\C-ch" 'haskell-hoogle)))
(eval-after-load 'haskell-cabal '(progn
(define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-ode-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)))
(require 'company-ghci)
(push 'company-ghci company-backends)
(add-hook 'haskell-mode-hook 'company-mode)
(add-hook 'haskell-interactive-mode-hook 'company-mode)
As you can see I basically got rid of all ghc-mod
related stuff (stack works as is with the current haskell-mode
) and replaced the company
backend (although this one is really slow and I hope to find something better)
variables
Theses you usually set within Emacs/Configuration of Haskell-Mode
(custom-set-variables
;; there is of course more in here - these are the Haskell related:
'(haskell-font-lock-symbols (quote unicode))
'(haskell-hoogle-command nil)
'(haskell-mode-hook
(quote
(linum-mode turn-on-haskell-indentation turn-on-haskell-doc-mode)) t)
'(haskell-process-auto-import-loaded-modules t)
'(haskell-process-load-or-reload-prompt t)
'(haskell-process-log t)
'(haskell-process-suggest-language-pragmas nil)
'(haskell-process-suggest-no-warn-orphans t)
'(haskell-process-type (quote auto))
'(haskell-process-use-presentation-mode t)
'(haskell-tags-on-save t)
'(inferior-haskell-wait-and-jump t)
'(safe-local-variable-values
(quote
((haskell-process-use-ghci . t)
(haskell-indent-spaces . 4))))
(uniquify)))
These are the packages I added:
- haskell-mode
- company (not Haskell-related as is but a dependency)
- company-cabal
- company-ghci
- ghci-completion
- shakespeare-mode (for Yesod)
- company-quickhelp (for nice display of
:i
)
First
if it asks for your cabal directory - it wants to know where your myProject.cabal
file is - if you don't have one just take the folder where your file is (the default - I think the default/find never failed me till now).
in case you need some sample-.emacs-setup
Here are parts from my .emacs
file that works for me:
(autoload 'ghc-init "ghc" nil t)
(autoload 'ghc-debug "ghc" nil t)
(add-hook 'haskell-mode-hook (lambda () (ghc-init)))
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(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-`") 'haskell-interactive-bring)
(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-`") 'haskell-interactive-bring)
(define-key haskell-cabal-mode-map (kbd "C-c C-k") 'haskell-interactive-ode-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)))
(custom-set-variables
'(haskell-interactive-mode-hide-multi-line-errors nil)
'(haskell-process-log t)
'(haskell-process-type (quote cabal-repl)))
Please note the part with (quote cabal-repl)
- this should work with cabal sandboxes.
Also this will add more logging information to a buffer named haskell-process-log where you might find more about your problem.
I use this with ghc-mod version 5.1.0.2 compiled by GHC 7.8.3
and GHC 7.8.3 obviously.
Of course you have to make sure that your .cabal
folder and the place where ghc-mod
is in your path (I think you can configure this somewhere in the emacs settings too - but it's much easier this way).
remarks
- you have to install the package
ghc
in emacs notghc-mod
. - I had problems with different version of ghc-mod and the emacs package before - so make sure that you get the latest with cabal-install and then reinstall the emacs-package (was only problems with parsing of the ghc-output on my part though)
further information
If this does not help you please feel free to
- add a comment
- have a look at the happy haskell programming page
- have a look at the ghc wiki on emacs
sample run on my machine
I edited a sample file like this:
Then I hit C-c C-l and press y:
And accept the folder (this is where the file is located) and any other questions with Ret - now you should see the *haskell*
buffer with a friendly message/lambda:
Finally I can check that the file got loaded:
这篇关于haskell在emacs中复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!