branch: elpa/evil-nerd-commenter
commit c156331ed251e9dbc3cdce52e7d5be19dcc1a78b
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
better comment to the line
---
evil-nerd-commenter.el | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index ed106d47d1..a4339dbf91 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -243,6 +243,22 @@
(defun evilnc--comment-or-uncomment-region (beg end)
(evilnc--working-on-region beg end 'comment-or-uncomment-region))
+(defun evilnc--current-line-num ()
+ (save-restriction
+ (widen)
+ (save-excursion
+ (beginning-of-line)
+ (1+ (count-lines 1 (point))))))
+
+(defun evilnc--find-dst-line-num (UNITS)
+ (let ((cur-line-num (evilnc--current-line-num))
+ dst-line-num)
+ (if (>= (mod cur-line-num 10) UNITS)
+ (setq UNITS (+ UNITS 10))
+ )
+ (setq dst-line-num (+ cur-line-num (- UNITS (mod cur-line-num 10))))
+ ))
+
;; ==== below this line are public commands
;;;###autoload
(defun evilnc-comment-or-uncomment-paragraphs (&optional NUM)
@@ -301,6 +317,15 @@ Paragraphs are separated by empty lines."
(evilnc--comment-or-uncomment-region b e)
))))
+;;;###autoload
+(defun evilnc-quick-comment-or-uncomment-to-the-line (&optional UNITS)
+ "Comment or uncomment to line number with its units is UNITS."
+ (interactive "p")
+ (let ((dst-line-num (evilnc--find-dst-line-num UNITS)))
+ (evilnc-comment-or-uncomment-to-the-line dst-line-num)
+ (evilnc--goto-line (+ 1 dst-line-num))
+ ))
+
;;;###autoload
(defun evilnc-toggle-invert-comment-line-by-line ()
(interactive)
@@ -408,13 +433,14 @@ Paragraphs are separated by empty lines."
"Set the hotkeys of evil-nerd-comment"
(interactive)
(global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
- (global-set-key (kbd "C-c l") 'evilnc-comment-or-uncomment-to-the-line)
+ (global-set-key (kbd "C-c l") 'evilnc-quick-comment-or-uncomment-to-the-line)
(global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
(global-set-key (kbd "C-c p") 'evilnc-comment-or-uncomment-paragraphs)
(eval-after-load 'evil
'(progn
(define-key evil-normal-state-map ",ci"
'evilnc-comment-or-uncomment-lines)
(define-key evil-normal-state-map ",cl"
'evilnc-comment-or-uncomment-to-the-line)
+ (define-key evil-normal-state-map ",ll"
'evilnc-quick-comment-or-uncomment-to-the-line)
(define-key evil-normal-state-map ",cc" 'evilnc-copy-and-comment-lines)
(define-key evil-normal-state-map ",cp"
'evilnc-comment-or-uncomment-paragraphs)
(define-key evil-normal-state-map ",cr" 'comment-or-uncomment-region)