[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Comments within Org src block move point unexpectedly
From: |
Jean Louis |
Subject: |
Re: Comments within Org src block move point unexpectedly |
Date: |
Fri, 9 Apr 2021 17:27:30 +0300 |
User-agent: |
Mutt/2.0.6 (2021-03-06) |
* excalamus--- via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> [2021-04-09 16:14]:
>
> The usual behavior of comment-line is to move point to the next line.When
> commenting code within an Org source block, however, the point will jump to
> some previous line.
>
>
> For example, say that point is at |:
>
> #+begin_src emacs-lisp (defun hello () "Say hi." (interactive)|
> (message "Hello, world!"))#+end_src
Well, isn't your formatting somehow misaligned?
I have placed this in Org:
#+begin_src emacs-lisp
(defun hello ()
"Say hi."
(interactive)
(message "Hello, world!"))
#+end_src
Then I have marked the Lisp inside and have press TAB, here is what I get:
#+begin_src emacs-lisp
(defun hello ()
"Say hi."
(interactive)
(message "Hello, world!"))
#+end_src
Then if I wish to comment out some line I mark it first, like on (interactive)
and press M-;
#+begin_src emacs-lisp
(defun hello ()
"Say hi."
;; (interactive)
(message "Hello, world!"))
#+end_src
And if I call M-x comment-line with cursor after (interactive), cursor jumps up
on the "S" in Say hi.
#+begin_src emacs-lisp
(defun hello ()
"Say hi."
;; (interactive)
(message "Hello, world!"))
#+end_src
> When comment-line is called, the current line is commented, but
> point also moves to the indent of the previous line:
But if I put cursor after () and do M-x comment-line, it jumps down to first
quote of "Say".
#+begin_src emacs-lisp
;; (defun hello ()
"Say hi."
;; (interactive)
(message "Hello, world!"))
#+end_src
> The point will jump near the top of the block when the block
> contains more code (i.e. will jump entire screen heights).
That I cannot replicate.
> Ideally, I would like point to stay put (relative to the adjacent
> characters prior to (un)commenting). I would at least expect
> comment-line to behave in a source block like it does outside of
> one.
Try this:
(defun my-comment-line ()
(interactive)
(let ((point (point)))
(comment-region (point-at-bol) (point-at-eol))))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://rms-support-letter.github.io/