Hacker News new | ask | show | jobs
by klibertp 4569 days ago
I don't want to hit different keys for commenting and uncommenting! What I want is to have one key which does all this:

1. if there is no region active and current line is not commented - comment it

2. if there is no region active and current line is commented - uncomment it

3. if there is region active and it's fully commented - uncomment that region

4 otherwise comment the full region

And it's this easy to do this:

    (defun comment-or-uncomment-region-or-line ()
      "Comments or uncomments the region or the current line if
    there's no active region."
      (interactive)
      (let (beg end)
        (if (region-active-p)
            (setq beg (region-beginning)
                  end (region-end))
          (setq beg (line-beginning-position)
                end (line-end-position)))
        (comment-or-uncomment-region beg end)))
So I see absolutely no reason for not coding this up and using it :) (Other than, heck, it really is my first ELisp function and it shows :D)
1 comments

Evil-nerd-commenter does the same thing, but if I didn't use email I would have the same thing in my init. It's pretty great.