Consider the following line of Lisp code:
(some-function 7 8 | 9) ;; some comment. note the extra indentation
The point is placed between ‘8’ and ‘9’. If I perform (move-beginning-of-line), the point will be placed at the absolute beginning of the line, rather than at ‘(‘.
Same for move-end-of-line: I’d find it more desirable for it to place the point at ‘)’ if I perform it once, and at the absolute end of the line if I perform it a second time. Some IDEs behave like that.
I tried to implement this but got stuck, my solution behaves particularly bad near the end of a buffer, and on the minibuffer as well. Is there a library that provides this functionality?
I don’t know of any library, but it can be done in a few lines of Elisp.
For the beginning of line part, the bundled functions
beginning-of-line-textandback-to-indentation(M-m) move to the beginning of the “interesting” part of the line.back-to-indentationignores only whitespace whereasbeginning-of-line-textskips over the fill prefix (in a programming language, this is typically the comment marker, if in a comment). See Smart home in Emacs for how to flip between the beginning of the actual and logical line.For the end of line part, the following function implements what you’re describing. The function
end-of-line-codemoves to the end of the line, except for trailing whitespace and an optional trailing comment. The functionend-of-line-or-codedoes this, except that if the point was already at the target position, or if the line only contains whitespace and a comment, the point moves to the end of the actual line.