I'd like to have an emacs-lisp function that comments or uncomments the line the cursor is on.
At the very least, it needs to work in latex-mode and emacs-lisp-mode, as well as in org-mode inside latex and emacs-lisp source code blocks. Of course, it would be nice if the function worked generally, but as a stopgap, just the above situations would be helpful.
There's a built in function, comment-line, whose documentation suggests that it would perform this function, but it's too buggy to be useful.
I've found about a dozen attempts in forum posts and blogs, but none of them works correctly.
I wrote my own comment function that seems to work generally to comment lines. However, it doesn't uncomment. I'd rather not have to take the time to write the uncomment functionality if someone out there has already done it.
To elaborate on what I mean by "too buggy to be useful", if in an org mode latex source block with
\commandA \commandB \commandC I position my cursor on \commandB and execute comment-line, the following results:
\commandA % \commandB % \ commandC There are numerous other anomalies, and this kind of strange behavior seems to occur more than half the time, so I don't consider comment-line a useful command.