Skip to content

Instantly share code, notes, and snippets.

@hub-cap
Created July 10, 2014 18:03
Show Gist options
  • Save hub-cap/1324d00b01c5bd9fe1bd to your computer and use it in GitHub Desktop.
Save hub-cap/1324d00b01c5bd9fe1bd to your computer and use it in GitHub Desktop.
;; Original idea from
;; http://www.opensubscriber.com/message/[email protected]/10971693.html
(defun comment-dwim-line (&optional arg)
"Replacement for the comment-dwim command.
If no region is selected and current line is not blank and we are not at the end of the line,
then comment current line.
Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."
(interactive "*P")
(comment-normalize-vars)
(if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))
(comment-or-uncomment-region (line-beginning-position) (line-end-position))
(comment-dwim arg)))
(global-set-key "\M-;" 'comment-dwim-line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment