Run haskell program in emacs without typing "main" in the ghci buffer.

Hello, Is it possible to run haskell program in emacs without typing "main" in the ghci buffer? Assuming "main" function exists of course. Or, maybe automate sending "main\n" string to ghci buffer input. In other words, I want edit/run/see result style session. Thanks in advance, Zura -- View this message in context: http://old.nabble.com/Run-haskell-program-in-emacs-without-typing-%22main%22... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

On 27 April 2010 05:43, Zura_
Is it possible to run haskell program in emacs without typing "main" in the ghci buffer? Assuming "main" function exists of course. Or, maybe automate sending "main\n" string to ghci buffer input. In other words, I want edit/run/see result style session.
This is probably possible if you have enough elisp-fu (which I don't, but have a look at Flymake Haskell). If so, it would be better to have this as a different emacs keybinding rather than the default haskell-load-file one, as 1) you won't always have a main action and 2) you won't always want to _run_ your main action (e.g. it launches nuclear missiles and you don't want to run that when you're just testing your countdown function...). However, by using ":main" in the ghci session you have a bit more control as it allows you to specify command-line flags and inputs, which running just "main" doesn't. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Zura_
Hello,
Is it possible to run haskell program in emacs without typing "main" in the ghci buffer? Assuming "main" function exists of course. Or, maybe automate sending "main\n" string to ghci buffer input. In other words, I want edit/run/see result style session.
Assuming you're using haskell-mode, does M-x inferior-haskell-load-and-run do what you want? You can of course define a shortcut for it: (define-key haskell-mode-map "\C-l" 'inferior-haskell-load-and-run) If you don't want to load the file, just run main: (defun haskell-main () (interactive) (inferior-haskell-send-command (inferior-haskell-process) ":main")) (This a very simple version; there're many possible variations; for instance, adding (swith-to-haskell) at the end). HTH, jao

Jose A. Ortega Ruiz-2 wrote:
Assuming you're using haskell-mode, does
M-x inferior-haskell-load-and-run
This seems to be exactly what I want. Added couple of things: (defun haskell-run-preserve-focus () "Load and run but preserve focus." (interactive) (let ((buf (current-buffer))) (inferior-haskell-load-and-run inferior-haskell-run-command) (end-of-buffer) (switch-to-buffer-other-window buf))) Despite the end-of-buffer call for ghci buffer, couple of lines are always hidden after subsequent invoking of the haskell-run-preserve-focus function, albeit it is possible to scroll down with mouse. Thank you and all who replied! Zura -- View this message in context: http://old.nabble.com/Run-haskell-program-in-emacs-without-typing-%22main%22... Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

On Mon, 26 Apr 2010 12:43:39 -0700 (PDT), Zura_
Hello,
Hello,
Is it possible to run haskell program in emacs without typing "main" in the ghci buffer? Assuming "main" function exists of course. Or, maybe automate sending "main\n" string to ghci buffer input. In other words, I want edit/run/see result style session.
This is not directly related but I use :cmd in order to :reload and call main in only one GHCi command (easier for redoing it again and again). :cmd (return":reload\n :main") -- Nicolas Pouillard http://nicolaspouillard.fr
participants (4)
-
Ivan Miljenovic
-
Jose A. Ortega Ruiz
-
Nicolas Pouillard
-
Zura_