使用Emacs编辑源文件时,在ghci中评估haskell的功能 [英] Function to evaluate haskell in ghci while editing source file using Emacs

查看:161
本文介绍了使用Emacs编辑源文件时,在ghci中评估haskell的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编辑一个haskell源文件。我想在我的下面的haskell缓冲区中运行我的主要功能(已经在不同的框架中打开),并继续编辑我的源文件。为了做到这一点,我做了



Cc Cl ,更改框架, main< ret> ,更改回原始框架



这似乎效率很低。我想要一个emacs功能/键一次。

解决方案

实际上有一个功能来做这个已经定义在 inf-haskell.el lower-haskell-load-and-run 。这将加载您当前的文件并运行:main



您可以通过添加到Haskell模式将其绑定到一个键一个钩子:

 (defun my-haskell-mode- hook()
(local-set-key(kbdCx Cr)'lower-haskell-load-and-run)
(add-hook'haskell-mode-hook'my-haskell -mode-hook)

然而,玩这个有一点,似乎有一个奇怪在我的电脑上出现问题:有时,当它弹出 * haskell * 缓冲区时,它不会移动到最后。我觉得这很烦人。您可以通过自己移动点来轻松解决问题:

 (defun my-haskell -load-and-run()
加载并运行当前的Haskell文件
(interactive)
(lower-haskell-load-and-run inferior-haskell-run-command )
(sleep-for 0 100)
(结束缓冲区))

我相信 sleep-for 是必要的,因为Haskell命令是异步运行的,需要一点时间才能返回。这整个事情是一个黑客,但它似乎工作。



另外,你可能想要定制什么 lower-haskell- run-command 是。默认情况下,它是:main 。但是,对于我来说,我认为只有 main 会更好,因为 main 的影响:设置args ... 其中:main 不是。



如果你想留在您当前的Haskell缓冲区中,您可以这样做:

 (defun my-haskell -load-and-run()
加载并运行当前的Haskell文件
(interactive)
(let((start-buffer(current-buffer)))
(lower-haskell-load-and-run inferior-haskell-run-command)
(sleep-for 0 100)
(end-of-buffer)
(pop-to-缓冲区启动缓冲区)))


I'm editing a haskell source file. I want to run my main function in my inferior-haskell buffer (already opened in a different frame) and continue editing my source file. To do this, I do

C-c C-l, change frame, main<ret>, change back to original frame

This seems quite inefficient. I'd like an emacs function/key that does it one shot.

解决方案

There is actually a function to do this already defined in inf-haskell.el: inferior-haskell-load-and-run. This loads your current file and runs :main.

You can bind it to a key in Haskell mode by adding a hook:

(defun my-haskell-mode-hook ()
  (local-set-key (kbd "C-x C-r") 'inferior-haskell-load-and-run))
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)

However, playing around with this for a bit, it seems to have an odd issue on my computer: sometimes, when it pops to the *haskell* buffer, it doesn't move the point to the end. I find this rather annoying. You can easily fix it by moving the point to the end yourself:

(defun my-haskell-load-and-run ()
  "Loads and runs the current Haskell file."
  (interactive)
  (inferior-haskell-load-and-run inferior-haskell-run-command)
  (sleep-for 0 100)
  (end-of-buffer))

I believe the sleep-for is necessary because the Haskell command is run asynchronously and takes a little bit of time to return. This whole thing is something of a hack, but it seems to work.

Also, you might want to customize exactly what the inferior-haskell-run-command is. By default, it's :main. However, for me, I think just main would be better because main is affected by :set args ... where :main isn't.

If you want to stay in your current Haskell buffer, you can just do this:

(defun my-haskell-load-and-run ()
  "Loads and runs the current Haskell file."
  (interactive)
  (let ((start-buffer (current-buffer)))
    (inferior-haskell-load-and-run inferior-haskell-run-command)
    (sleep-for 0 100)
    (end-of-buffer)
    (pop-to-buffer start-buffer)))

这篇关于使用Emacs编辑源文件时,在ghci中评估haskell的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆