Skip to content

Instantly share code, notes, and snippets.

@jpemberthy
Created November 5, 2014 19:36
Show Gist options
  • Save jpemberthy/2d1f358dfa6c6469bfaf to your computer and use it in GitHub Desktop.
Save jpemberthy/2d1f358dfa6c6469bfaf to your computer and use it in GitHub Desktop.
(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)))
(global-set-key (kbd "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