'Function to evaluate haskell in ghci while editing source file using Emacs

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.



Solution 1:[1]

To use interactive-haskell-mode, I found a similar setting than the other answer:

(defun my-haskell-load-and-run ()
  "Loads and runs the current Haskell file main function."
  (interactive)
  (haskell-process-load-file)
  (haskell-interactive-mode-run-expr "main"))
(defun my-haskell-mode-hook ()
  (local-set-key (kbd "C-x C-r") 'my-haskell-load-and-run))
(add-hook 'haskell-mode-hook 'my-haskell-mode-hook)

But I have a small issue with it, it always jumps to the end of the source buffer... which can be annoying.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Miao ZhiCheng