Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remyferre/comment-dwim-2
A replacement for the emacs' built-in command `comment-dwim'
https://github.com/remyferre/comment-dwim-2
Last synced: about 2 months ago
JSON representation
A replacement for the emacs' built-in command `comment-dwim'
- Host: GitHub
- URL: https://github.com/remyferre/comment-dwim-2
- Owner: remyferre
- License: gpl-3.0
- Created: 2014-09-03T18:32:54.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-08-24T10:43:09.000Z (about 1 year ago)
- Last Synced: 2024-07-14T00:35:12.148Z (3 months ago)
- Language: Emacs Lisp
- Homepage:
- Size: 50.8 KB
- Stars: 99
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Comment-dwim-2
`comment-dwim-2` is a replacement for the Emacs' built-in command `comment-dwim`, which includes more features and allows you to:
* comment/uncomment the current line (or region, if active)
* insert/kill end-of-line comments
* reindent end-of-line comments`comment-dwim-2` picks one behavior depending on the context but **can also be repeated several times to switch between the different possible behaviors**.
# Demo
`comment-dwim-2` used 3 times in a row:
![general behavior of comment-dwim-2](http://remyferre.github.io/images/cd2-general.gif)
# How to use
You need to add your own key binding first, for instance:
(global-set-key (kbd "M-;") 'comment-dwim-2)
If you use org-mode, consider using `org-comment-dwim-2` to comment within source blocks:
(define-key org-mode-map (kbd "M-;") 'org-comment-dwim-2)
# Installation
This package can be installed from [MELPA](http://melpa.org/#/).
# Detailed use cases
## Commenting/uncommenting the region
![commenting/uncommenting the region with comment-dwim-2](http://remyferre.github.io/images/cd2-region.gif)
## Commenting current line
![commenting current line with comment-dwim-2](http://remyferre.github.io/images/cd2-comment.gif)
## Uncommenting current line
![uncommenting current line with comment-dwim-2](http://remyferre.github.io/images/cd2-uncomment.gif)
## Insert comment (repeat the command)
![inserting comment with comment-dwim-2](http://remyferre.github.io/images/cd2-insert-comment.gif)
## Kill comment (repeat the command)
![killing comment with comment-dwim-2](http://remyferre.github.io/images/cd2-kill-comment.gif)
## Reindent comment (call the command with a prefix argument)
![reindenting comment with comment-dwim-2](http://remyferre.github.io/images/cd2-reindent-comment.gif)
# Customization
When commenting a region, `comment-dwim-2` will by default comment the entirety of the lines that the region spans (i.e. a line will be fully commented even if it is partly selected):
![comment-dwim-2 comment lines even if they are partly selected](http://remyferre.github.io/images/cd2-region-expand.gif)
In Lisp modes, however, `comment-dwim-2` will strictly comment the region as commenting whole lines could easily lead to unbalanced parentheses.
![region commenting in Lisp modes](http://remyferre.github.io/images/cd2-region-lisp.gif)
If you always want to fully comment lines (Lisp modes included), add this to your configuration file:
(setq cd2/region-command 'cd2/comment-or-uncomment-lines)
If you only want to comment the selected region (like `comment-dwim` does), add this:
(setq cd2/region-command 'cd2/comment-or-uncomment-region)