Reputation: 1027
I've been attempting to use Haskell for running a simple production process. Like many production processes, it involves changing the states of things all over the place. For this reason, it would be really handy for me to have a script file where I could keep track of things and selectively run commands into interactive Haskell, something like
-- to start the process
process <- startProcess
-- to stop process
stopProcess
-- to check how things are going
summary <- checkStuff
summary
-- optionally restart bad processes
restartProcesses (getBadProcesses summary)
-- send summary emails
sendSummaryEmails summary ["[email protected]", "[email protected]",
"[email protected]" "[email protected]",
"[email protected]"]
-- set up something big that I don't want to have to retype/paste every time
studentGrades <- getStudentGrades "John Peterson"
gen <- getStdGen
let (randomTest, gen') = generateRandomTest studentGrades gen
compilePdf randomTest
answers <- getAnswers
gradeTest randomTest answers "John Peterson"
It would be really cool if, like with ESS (Emacs speaks statistics) in R, if you could press a button to send these lines to the repl process. Maybe seperate buttons for line, paragraph, region. Is there already a way to do this?
For example with ESS, C-Ret
sends the line, C-c C-c
sends a paragraph, and C-c C-r
sends a region.
Upvotes: 4
Views: 650
Reputation: 3256
This emacs lisp function will send a command to haskell's repl
(defun haskell-send-command (cmd)
(process-send-string (inferior-haskell-process) (concat cmd "\n")))
and this will call the previous one with the current selection
(defun haskell-send-selection ()
(interactive)
(haskell-send-command (x-selection)))
You can assign it a keyboard shortcut with global-set-key
. Then you need to figure out how to quickly select what you want to send. For instance M-h
is mark-paragraph. Or just recode the ESS functions you like :
(defun haskell-send-paragraph ()
(interactive)
(mark-paragraph)
(haskell-send-selection))
I actually used those to build a small debugging GUI for Haskell in emacs. I have shortcuts for setting breakpoints and stepping, and the position of the debugger highlights directly in the haskell code.
Upvotes: 1