If I have a long line in a javascript file such as:
let args = [options.loadRaw ? buffer : path.resolve(filePath)].concat(options.commands);
At some point when I keep adding to that line, it auto-formats into:
let args = [options.loadRaw ? buffer :
path.resolve(filePath)].concat(options.commands); // test
I'm trying to figure out what is causing this, because it's pretty jarring. I'd rather run this myself manually when I want to like with clang-format. I'm using js2-mode so I have a feeling it's that but I can't figure out what it may be or if it can be disabled.
I know it's pretty vague but I don't know what else to say. I'm mainly wondering if there's a way I can find out for myself. I did C-h k
before pressing the space key but it's just self-insert-command
, though I noticed that there's this in the help buffer for that function:
After insertion, the value of ‘auto-fill-function’ is called if the
‘auto-fill-chars’ table has a non-nil value for the inserted character.
But I checked and auto-fill-function
is nil, otherwise that definitely seemed like the culprit. Then I saw this at the end of the help buffer:
At the end, it runs ‘post-self-insert-hook’.
Whose value is:
(sp--post-self-insert-hook-handler helm-find-files--reset-level-tree electric-pair-post-self-insert-function electric-indent-post-self-insert-function blink-paren-post-self-insert-function)
I'm not sure if this is correct, but I did (setq post-self-insert-hook nil)
in the buffer and then pressed space and it still re-formatted the line, so maybe it's something else? I'm entirely at a loss.
I'm not sure if this is related, but to see if it was js2-mode buffers I also just noticed some other behavior when in the *stratch*
buffer. If I type out a sexp with just one
repeated over and over, once I get to the fill-column it starts adding spaces, like this:
(one one one one one one one one one one one one one one one one one one one one one one one one one)
^ fill column here (column 80)
That's certainly different from what happens in js2-mode buffers though, where the line is entirely re-formatted onto separate lines so that it fits within the fill-column.
I'm on emacs 25 in case that matters.
EDIT: Disabling auto-fill-mode fixes the issue. The problem is that I want to keep auto-fill-mode. It looks like js2-line-break
is the culprit:
(set (make-local-variable 'comment-line-break-function) #'js2-line-break)
My configuration of auto-fill-mode is:
(defun my-prog-auto-fill ()
(setq-local comment-auto-fill-only-comments t)
(auto-fill-mode 1))
(add-hook 'prog-mode-hook #'my-prog-auto-fill)
What I don't understand is why, if I setup auto-fill to only apply to comments, and the variable that js2-line-break is being assigned to is called comment-line-break-function
which gives the impression that it only applies when within a comment, why then is js2-line-break
being called despite not being within a comment?