It's possible. Here is one way of doing it (replace the second and third call to add-hook
with this):
(defun java-autoindent ()
(when (and (eq major-mode 'java-mode) (looking-back "[{;]"))
(newline-and-indent)))
(add-hook 'post-self-insert-hook 'java-autoindent)
The way this works is that every time you type a character in a java-mode
buffer, Emacs will
- check if that character is
{
or;
, and if that's the case - run
newline-and-indent
.