Reputation: 2417
I don't know elisp, but I'm trying to do something like the following:
(add-hook
'scala-mode-hook
(lambda ()
(define-key scala-mode-map (kbd "RET") (lambda ()
(scala-newline)
(scala-indent-line)))))
Goal is to call the two functions each time I hit the ENTER key. How do I actually do this?
Upvotes: 4
Views: 1179
Reputation: 10533
Just type C-j it will call the newline-and-indent
command and do exactly what you ask.
Upvotes: 0
Reputation: 17327
You need an (interactive)
form after the lambda
in your define-key
.
EDIT:
To be clear, the inner form should look like:
(lambda ()
(interactive)
(scala-newline)
(scala-indent-line))
Upvotes: 7
Reputation: 7003
I do essentially this in so many modes that I've squashed them all together:
(mapcar (lambda (hooksym)
(add-hook hooksym
(lambda ()
(local-set-key (kbd "C-m") 'newline-and-indent)
)))
'(
clojure-mode-hook
emacs-lisp-mode-hook
erlang-mode-hook
java-mode-hook
js-mode-hook
lisp-interaction-mode-hook
lisp-mode-hook
makefile-mode-hook
nxml-mode-hook
python-mode-hook
ruby-mode-hook
scheme-mode-hook
sh-mode-hook
))
Just stick scala-mode-hook
in there somewhere and it'll work for you too :)
Upvotes: 8
Reputation: 87224
In hook you can use local-set-key, for example
(add-hook 'scala-mode-hook
(lambda ()
(local-set-key [return]
(lambda ()
(scala-newline)
(scala-indent-line)))))
although, maybe it will be easier to use something like standard newline-and-indent?
(add-hook 'scala-mode-hook
(lambda ()
(local-set-key [return] 'newline-and-indent)))
Upvotes: 2