git clone 'git://github.com/remyferre/comment-dwim-2.git'
comment-dwim-2 is a replacement for the Emacs' built-in command
comment-dwim which includes more comment features, including:
As its name suggests,
comment-dwim-2 picks one behavior depending on the context but contrary to
comment-dwim can also be repeated several times to switch between the different behaviors.
comment-dwim-2 repeated 3 times:
comment-dwim-2 is not bound to any key, so you need to set up you own keybinding first. For instance:
(global-set-key (kbd "M-;") 'comment-dwim-2)
This package can be installed from MELPA.
An alternative behavior closer to what
comment-dwim does is available. To use it, add this to your init file:
(setq comment-dwim-2--inline-comment-behavior 'reindent-comment)
It basically swaps the killing and reindenting behavior, which means that repeating
comment-dwim-2 will by default reindent the comment instead of killing it, and that calling
comment-dwim-2 with a prefix argument will kill the comment instead of reindenting it.