When I'm writing a comment and press
M-j to continue the comment on the next line (using single-line comments), if I press it multiple times say because I want to leave the next comment line "empty" for separation, the cursor ends up appearing right after the comment delimiter. Instead, I always want the cursor to be separated from the comment delimiter by one space. I'd like this to be the case in every mode, globally if possible.
As an example, if I have this:
If I press
M-j I get this:
;; comment ;; |
It's correctly separated from the comment delimiter by one space.
If without doing anything else I press
M-j again, I get this:
;; comment ;; ;;|
So from then on there is no space added between the comment delimiter and the cursor. I want there to always be a space of separation.
By comparison, in c++-mode I always get the space.
I'd like to know if there's a way to get this in other modes (or even all other modes) before I resort to hacking it in by wrapping the function myself.
EDIT: I ended up advising
comment-indent-new-line to add one space if there aren't any spaces following the comment-start:
(define-advice comment-indent-new-line (:after (&optional soft) at-least-one-space) "Ensure that at least one space is added after the comment-start." (let ((start (regexp-quote comment-start))) (when (and (nth 4 (syntax-ppss)) (looking-back start (+ (point) (length start))) (not (looking-back " " (+ (point) 1)))) (insert " "))))