Emmanuel Goldstein
Emmanuel Goldstein

Reputation: 363

Avoid comment-line to move cursor to beginning of heading (ORGMODE)

Everytime I use "comment-line" in a elisp bunch of code, the cursor moves up. This is annoying. Is there a way to comment line by line in Elisp so that the cursor stays in the very same line?

This happens in OrgMode blocks, but not in Emacs Lisp.

Upvotes: 0

Views: 238

Answers (2)

Roney Gomes
Roney Gomes

Reputation: 507

That happens because electric-indent-mode affects the behavior of comment-line when in org-mode, and possibly other modes as well.

To fix it you can disable electric-indent-mode entirely.

(electric-indent-mode -1)

Upvotes: 0

Thomas
Thomas

Reputation: 17422

Unfortunately, this behavior is hard-baked into the code of comment-line. However, it's easy enough to create a variation of that function that leaves point in place, either by adivising comment-line or by writing a separate function like so:

(defun comment-line-leave-point (n)
  (interactive "p")
  (save-excursion
    (comment-line n)))

Upvotes: 1

Related Questions