Closed Eason0210 closed 1 year ago
I am not sure, but it seems the logic of newline-and-indent is changed. I changed it to (global-set-key (kbd "RET") 'newline), everything works fine for me.
Hmm, I can't reproduce the initially-reported issue locally, with Emacs 28.1.
I can confirm this issue is still happening. I noticed this problem in cperl-mode
, c-mode
, and js-mode
. I assume it happens in all prog-modes that use braces for blocks.
I'm providing the steps that I used to reproduce as well, in case it helps (Emacs 28.2, clean clone of the repo):
|
, which represents where the cursor should be):
int main()
{
if (a >= b) {|}
}
<return>
(or M-x newline-and-indent
).Expected behavior
int main()
{
if (a >= b) {
|
}
}
Actual behavior
int main()
{
if (a >= b) {
|
}
}
I am running into the same behavior with doom emacs running on 28.2. As usual, it's easier to patch around a problem than figure out what's going on:
(defun my/fix-indentation-after-newline ()
(save-excursion
(next-line)
(beginning-of-line)
(if (looking-at "^[})]") (indent-according-to-mode))))
(advice-add 'newline-and-indent :after 'my/fix-indentation-after-newline)
@purcell ,
I found that the indentation of close brace (
}
) and backet (]
) is wrong innix-code
,c/c++-mode
,js-mode
and so on.You can reproduce it by input the code
programs = { };
, and then press Enter inside the{ }
innix-mode
.for example, this is my darwin.nix:
And I found that it is the new line behavior affect the indentation. https://github.com/purcell/emacs.d/blob/85ce2603e1b891bfa98f40ed3b9018024c62dc14/lisp/init-editing-utils.el#L79