New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[HOWTO] Not add trailing whitespaces on newlines in js2-mode? #1679
Comments
And why is this not working? (defun +javascript/newline-and-indent ()
"TODO"
(interactive)
(doom/backward-kill-to-bol-and-indent)
(newline-and-indent)
)
(map! :map js2-mode-map [remap newline] #'+javascript/newline-and-indent)
|
This is the only thing that works: (defun +javascript/newline-and-indent ()
"TODO"
(doom/backward-kill-to-bol-and-indent))
(advice-add #'newline-and-indent :before #'+javascript/newline-and-indent) But it overrides EDIT: Oh and it kills the line if the cursor is not at the first character =\ |
Try this instead: (map! :map js2-mode-map [remap newline-and-indent] #'+javascript/newline-and-indent) |
That said, Doom enables ws-butler-global-mode by default. It will clean up trailing whitespace (on lines you've touched) when you save, so is manually cleaning it up necessary? |
Well it leaves that trailing red block behind, as if it's telling "something is wrong", until I save, or manually go there and |
This worked for me: |
You can detect if the current line is empty with: (save-excursion
(beginning-of-line)
(looking-at-p "[ \t]*$")) ; returns non-nil if the line is just whitespace Or use the |
Wait! It's this override that's causing the issue! It doesn't call |
I could've sworn there was a good reason for that, but the advise was written so many years ago I don't remember anymore. I've added the |
What I want to achieve
elisp mode (good):
js2-mode (bad):
How can I achieve the same behavior in js2-mode as in elisp? I want enter key to add newlines at the same indentation level but don't keep the trailing whitespace on the previous.
System information
The text was updated successfully, but these errors were encountered: