Emacs : Redefining command in Haskell-mode (haskell-mode-hook)
What you want to do is run the function that C-x C-s
runs followed by running the function C-c C-l
does. You can find out what function is run by some key binding via C-h k
. That is, first type C-h k
then the key command you're interested in.
This gives us (save-buffer &optional ARGS)
for C-x C-s
and (inferior-haskell-load-file &optional RELOAD)
for C-c C-l
. The &optional
means exactly what you think it does--that argument is optional, so we don't care about it.
Now write the function that does both of them:
(defun my-haskell-mode-save-buffer ()
(interactive)
(save-buffer)
(inferior-haskell-load-file))
Now you can bind this function to C-x C-s
in haskell mode exactly how you've been doing it:
(add-hook 'haskell-mode-hook (lambda ()
(local-set-key (kbd "C-x C-s") 'my-haskell-mode-save-buffer)))
EDIT: It seems C-c C-l
saves your file by default before loading it. This means you can just write
(add-hook 'haskell-mode-hook (lambda ()
(local-set-key (kbd "C-x C-s") 'inferior-haskell-load-file)))
and have exactly the same effect without writing your own function. However, I think writing it my way is a good learning exercise :P. That approach works whenever you want to combine multiple different key bindings into one.