Skip to content

Instantly share code, notes, and snippets.

@ivey
Created August 8, 2010 13:23
Show Gist options
  • Save ivey/514019 to your computer and use it in GitHub Desktop.
Save ivey/514019 to your computer and use it in GitHub Desktop.
(defun comment-or-uncomment-region-or-line (&optional lines)
"If the line or region is not a comment, comments region
if mark is active, line otherwise. If the line or region
is a comment, uncomment."
(interactive "P")
(if mark-active
(if (< (mark) (point))
(comment-or-uncomment-region (mark) (point))
(comment-or-uncomment-region (point) (mark)))
(comment-or-uncomment-line lines)))
(global-set-key "\M-\\" 'comment-or-uncomment-region-or-line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment