branch: elpa/evil-nerd-commenter
commit 0a46b911200c75c4737bfdb2b71f10a9a8254969
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
more precise inner comment text object
---
README.org | 4 +++-
evil-nerd-commenter-operator.el | 46 ++++++++++++++++++++++++++++++++++++-----
evil-nerd-commenter.el | 17 +++++++++------
pkg.sh | 2 +-
4 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/README.org b/README.org
index 9b41c9036e..ae1a30fb08 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (v3.0.2)
+* evil-nerd-commenter (v3.0.3)
[[http://melpa.org/#/evil-nerd-commenter][file:http://melpa.org/packages/evil-nerd-commenter-badge.svg]]
[[http://stable.melpa.org/#/evil-nerd-commenter][file:http://stable.melpa.org/packages/evil-nerd-commenter-badge.svg]]
@@ -175,6 +175,8 @@ Press =vac= to select outer object (comment with limiters).
Press =vic= to select inner object (comment without limiter).
You can assign other key instead of "c" to the text object by customizing
=evilnc-comment-text-object=.
+
+Please note in order to select innner object precisely, either the first or
last line is the longest line.
** evilnc-comment-operator
=evilnc-comment-operator= acts much like the delete/change operator. Takes a
motion or text object and comments it out, yanking its content in the process.
diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index 205eec5eaf..f9d9b0aba3 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -143,7 +143,7 @@
(setq rlt (cons b e))))
rlt))
-(defun evilnc-ajusted-comment-end (b e)
+(defun evilnc-adjusted-comment-end (b e)
(let* ((next-end-char (evilnc-get-char (- e 2)))
(end-char (evilnc-get-char (- e 1))))
;; avoid selecting CR/LF at the end of comment
@@ -178,10 +178,19 @@
(forward-word 1)
(forward-word -1)
(point)))
+ (line-end-of-b (save-excursion
+ (goto-char b)
+ (line-end-position)))
+ (offset-b (save-excursion
+ (goto-char b)
+ (- b (line-beginning-position))))
(e (save-excursion
(goto-char (cdr bounds))
- (goto-char (evilnc-ajusted-comment-end b
(line-end-position)))
- (point))))
+ (goto-char (evilnc-adjusted-comment-end b
(line-end-position)))
+ (point)))
+ line-beginning-of-e
+ offset-e)
+ ;; keep move e to the end of comment
(when (evilnc-is-one-line-comment b e)
(while (and (< b e)
(or (evilnc-is-comment-delimiter e)
@@ -189,8 +198,35 @@
(evilnc-is-whitespace e))))
(setq e (- e 1)))
(setq e (+ e 1)))
-
- (if (< b e) (evil-range b e 'block :expanded t))))
+ ;; b line-end-of-b
+ ;; +---------------------+
+ ;; | |
+ ;; +---------------------|
+ ;; line-beginning-of-e e
+ (setq line-beginning-of-e (save-excursion
+ (goto-char e)
+ (+ (line-beginning-position) offset-b)
+ (forward-word 1)
+ (forward-word -1)
+ (point)))
+ (setq offset-e (save-excursion
+ (goto-char e)
+ (- line-beginning-of-e (line-beginning-position))))
+ ;; switch start/end of block region if required
+ (let* (block-b block-e)
+ (cond
+ ((> (- line-end-of-b b)
+ (- e line-beginning-of-e))
+ (setq block-b (if (> offset-e offset-b) (- line-beginning-of-e
+ (- offset-e offset-b))
+ line-beginning-of-e))
+ (setq block-e line-end-of-b))
+ (t
+ (setq block-b (if (> offset-b offset-e) (- b (- offset-b
+ offset-e))
+ b))
+ (setq block-e e)))
+ (evil-range block-b block-e 'block :expanded t))))
(t
(error "Not inside a comment.")))))
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 95e060ac72..9150520100 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -4,7 +4,7 @@
;; Author: Chen Bin <[email protected]>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.0.2
+;; Version: 3.0.3
;; Keywords: commenter vim line evil
;;
;; This file is not part of GNU Emacs.
@@ -38,7 +38,8 @@
;;
;; It helps you comment/uncomment multiple lines without selecting them.
;;
-;; `M-x evilnc-default-hotkeys` assigns hotkey `M-;` to
`evilnc-comment-or-uncomment-lines`
+;; `M-x evilnc-default-hotkeys` assigns hotkey `M-;` to
+;; `evilnc-comment-or-uncomment-lines'
;;
;; `M-x evilnc-comment-or-uncomment-lines` comment or uncomment lines.
;;
@@ -71,21 +72,25 @@
;; "ci" 'evilnc-comment-or-uncomment-lines
;; "cl" 'evilnc-quick-comment-or-uncomment-to-the-line
;; "ll" 'evilnc-quick-comment-or-uncomment-to-the-line
-;; "cc" 'evilnc-copy-and-comment-lines ; Or use
`evilnc-comment-and-kill-ring-save' instead
+;; ;; Or use `evilnc-comment-and-kill-ring-save' instead
+;; "cc" 'evilnc-copy-and-comment-lines
;; "cp" 'evilnc-comment-or-uncomment-paragraphs
;; "cr" 'comment-or-uncomment-region
;; "cv" 'evilnc-toggle-invert-comment-line-by-line
;; "." 'evilnc-copy-and-comment-operator
;; "\\" 'evilnc-comment-operator)
;;
-;; You can setup `evilnc-original-above-comment-when-copy-and-comment' to
decide which
-;; style to use when `evilnc-copy-and-comment-lines' or
`evilnc-copy-and-comment-operator',
+;; You can setup `evilnc-original-above-comment-when-copy-and-comment'
+;; to decide which style to use when `evilnc-copy-and-comment-lines'
+;; or `evilnc-copy-and-comment-operator',
;; - Place the commented out text above original text
;; - Or place the original text above commented out text
;;
;; We defined comment text object "c" which can have multi-lines.
;; Press "vac" to select outer object (comment with limiters).
;; Press "vic" to select inner object (comment without limiter).
+;; Please note in order to select innner object precisel,x
+;; either the first or last line is the longest line.
;; You can assign other key instead of "c" to the text object by
;; customizing `evilnc-comment-text-object'.
@@ -681,7 +686,7 @@ Then we operate the expanded region. NUM is ignored."
(defun evilnc-version ()
"The version number."
(interactive)
- (message "3.0.2"))
+ (message "3.0.3"))
(defvar evil-normal-state-map)
(defvar evil-visual-state-map)
diff --git a/pkg.sh b/pkg.sh
index 85ffef09e1..02aea7ed3d 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=evil-nerd-commenter
-version=3.0.2
+version=3.0.3
pkg=$name-$version
mkdir $pkg
cp *.el $pkg