[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter 82069b7643 121/235: comment region res
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter 82069b7643 121/235: comment region restricted in one line #50, v2.0 |
Date: |
Thu, 6 Jan 2022 02:59:40 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit 82069b7643c7ef5549ccdd8b38214393fcb36c7c
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
comment region restricted in one line #50, v2.0
- evilnc-comment-or-uncomment-lines enhancement
- right comment syntax is used automatically
---
README.org | 7 ++-
evil-nerd-commenter-operator.el | 2 +-
evil-nerd-commenter-pkg.el | 2 +-
evil-nerd-commenter.el | 103 +++++++++++++++++++++++++++-------------
pkg.sh | 2 +-
5 files changed, 78 insertions(+), 38 deletions(-)
diff --git a/README.org b/README.org
index 5a6c619450..bce9059d56 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (v1.5.15)
+* evil-nerd-commenter (v2.0)
This program can be used *independently WITHOUT
[[http://www.emacswiki.org/Evil][evil-mode]]!*
@@ -70,6 +70,11 @@ comment/uncomment lines. This command supports negative
arguments.
The hotkey is ",ci" in evil-mode and "M-;" in all modes. "M" means ALT key.
+If a region selected, the region is expand to make sure the region contain
+whole lines. Then we comment/uncomment the expanded region. NUM is ignored.
+
+If the region is insided of ONE line, we comment/uncomment that region. In
this case, CORRECT comment syntax will be used for C++/Java/Javascript.
+
This may be the *only command* you need to learn!
*** evilnc-quick-comment-or-uncomment-to-the-line
comment/uncomment from current line to the user-specified line. You can input
the rightest digit(s) to specify the line number if you want to type less.
diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index 97eaf4dadb..28c14c3615 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -4,7 +4,7 @@
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 1.5.15
+;; Version: 2.0
;; Keywords: commenter vim line evil
;;
;; This file is not part of GNU Emacs.
diff --git a/evil-nerd-commenter-pkg.el b/evil-nerd-commenter-pkg.el
index bbad4fa911..9b81bdac81 100644
--- a/evil-nerd-commenter-pkg.el
+++ b/evil-nerd-commenter-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-nerd-commenter" "1.5.15"
+(define-package "evil-nerd-commenter" "2.0"
"Comment/uncomment lines efficiently. Like Nerd Commenter in
Vim")
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index ac79535b10..a5d33cbb23 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -4,7 +4,7 @@
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 1.5.15
+;; Version: 2.0
;; Keywords: commenter vim line evil
;;
;; This file is not part of GNU Emacs.
@@ -121,35 +121,69 @@
(setq comment-start-skip "^\\(\\s*\\)\\(dnl\\|#\\) +"))))
(defun evilnc--operation-on-lines-or-region (fn &optional NUM)
- (if (not (region-active-p))
- (let ((b (line-beginning-position)) e)
- (save-excursion
- (forward-line (- NUM 1))
- (setq e (line-end-position))
- )
- (funcall fn b e))
- ;; expand selected region
- (progn
+ (cond
+ ((not (region-active-p))
+ (let ((b (line-beginning-position)) e)
(save-excursion
- (let ((b (region-beginning))
- (e (region-end))
- )
- ;; another work around for evil-visual-line bug:
- ;; in evil-mode, if we use hot key V `M-x evil-visual-line` to
select line
- ;; the (line-beginning-position) of the line which is after the last
selected
- ;; line is always (region-end)! Don't know why.
- (if (and (> e b)
- (save-excursion (goto-char e) (= e
(line-beginning-position)))
- (boundp 'evil-state) (eq evil-state 'visual))
- (setq e (1- e)))
-
- (goto-char b)
- (setq b (line-beginning-position))
- (goto-char e)
- (setq e (line-end-position))
- (funcall fn b e)
- ))
- )))
+ (forward-line (- NUM 1))
+ (setq e (line-end-position))
+ )
+ (funcall fn b e)))
+ ((and (<= (line-beginning-position) (region-beginning))
+ (<= (region-end) (line-end-position)))
+ ;; Select region inside ONE line
+ (cond
+ ;; Well, looks current comment syntax is NOT fit for comment out a region.
+ ;; So we also need hack the comment-start and comment-end
+ ((and (string= "" comment-end)
+ (member major-mode '(java-mode
+ javascript-mode
+ js-mode
+ js2-mode
+ js3-mode
+ c++-mode
+ objc-mode)))
+ (let ((comment-start-old comment-start)
+ (comment-end-old comment-end)
+ (comment-start-skip-old comment-start-skip)
+ (comment-end-skip-old comment-end-skip))
+
+ ;; use C comment syntax temporarily
+ (setq comment-start "/* ")
+ (setq comment-end " */")
+ (setq comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
+ (setq comment-end-skip "[ ]*\\(\\s>\\|\\*+/\\)")
+
+ (funcall fn (region-beginning) (region-end))
+
+ ;; Restore the original comment syntax
+ (setq comment-start comment-start-old)
+ (setq comment-end comment-end-old)
+ (setq comment-start-skip comment-start-skip-old)
+ (setq comment-end-skip comment-end-skip-old)))
+ ;; just comment out the region
+ (t (funcall fn (region-beginning) (region-end)))))
+ (t
+ ;; selected region spans MORE than one line
+ (save-excursion
+ (let ((b (region-beginning))
+ (e (region-end)))
+ ;; Another work around for evil-visual-line bug:
+ ;; In evil-mode, if we use hotkey V or `M-x evil-visual-line` to
select line,
+ ;; the (line-beginning-position) of the line which is after the last
selected
+ ;; line is always (region-end)! Don't know why.
+ (if (and (> e b)
+ (save-excursion (goto-char e) (= e (line-beginning-position)))
+ (boundp 'evil-state) (eq evil-state 'visual))
+ (setq e (1- e)))
+
+ (goto-char b)
+ (setq b (line-beginning-position))
+ (goto-char e)
+ (setq e (line-end-position))
+ (funcall fn b e)
+ )))
+ ))
(defun evilnc--get-one-paragraph-region ()
(let (b e)
@@ -299,12 +333,11 @@
(web-mode-uncomment (/ (+ beg end) 2))
)
(t
- (when (not (region-active-p))
+ (unless (region-active-p)
(push-mark beg t t)
(goto-char end))
(web-mode-comment (/ (+ beg end) 2)))
- )
- )
+ ))
(t
(evilnc--working-on-region beg end 'comment-or-uncomment-region))
))
@@ -428,7 +461,9 @@ or 'C-u 3 M-x
evilnc-quick-comment-or-uncomment-to-the-line' to comment to the l
Case 1: If no region selected, comment/uncomment on current line. if NUM>1,
comment/uncomment
extra N-1 lines from next line
Case 2: If a region selected, the region is expand to make sure the region
contain
- whole lines. Then we comment/uncomment the expanded region. NUM is ignored."
+ whole lines. Then we comment/uncomment the expanded region. NUM is ignored.
+ Case 3: If a region in ONE line is selected, we comment/uncomment that
region.
+ In this case, CORRECT comment syntax will be used for C++/Java/Javascript."
(interactive "p")
;; donot move the cursor
;; support negative number
@@ -510,7 +545,7 @@ or 'C-u 3 M-x
evilnc-quick-comment-or-uncomment-to-the-line' to comment to the l
;;;###autoload
(defun evilnc-version ()
(interactive)
- (message "1.5.15"))
+ (message "2.0"))
;;;###autoload
(defun evilnc-default-hotkeys ()
diff --git a/pkg.sh b/pkg.sh
index a99963e1ab..50ea6366e4 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
#!/bin/bash
-pkg=evil-nerd-commenter-1.5.15
+pkg=evil-nerd-commenter-2.0
mkdir $pkg
cp README.org $pkg
cp *.el $pkg
- [nongnu] elpa/evil-nerd-commenter a88146b600 099/235: fixed: minor bug comment to the line v1.5.7, (continued)
- [nongnu] elpa/evil-nerd-commenter a88146b600 099/235: fixed: minor bug comment to the line v1.5.7, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter dfdaae43e9 106/235: Don't byte-compile the evil bits, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ac03a92ae6 107/235: updated README v1.5.10, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ff0344ed82 110/235: updated README v1.5.12, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 1dd577ca35 113/235: clean README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 06ac3b1680 115/235: README updated, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f12142e033 118/235: Update evil-nerd-commenter-operator.el, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 0529e7c78e 119/235: clean code on kill-ring, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ab27df65e6 120/235: clean doc v1.5.15, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 2d04ea603a 124/235: add melpa badge, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 82069b7643 121/235: comment region restricted in one line #50, v2.0,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter cb96ce729f 125/235: complete doc. make `M-x checkdoc' happy, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f2eacda61a 127/235: Correct package header, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 54c618aada 135/235: add `evilnc-comment-and-kill-ring-save`, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter bbed0ef060 142/235: Merge pull request #70 from therockmandolinist/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a61f920a66 146/235: commenter text objext finished, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ecb4e23b7e 140/235: clean pkg.sh, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter c44836d279 149/235: Merge pull request #73 from PythonNut/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 29ed027b53 150/235: Remove error and some warnings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter bb47704a10 155/235: Do not byte-compile evil-nerd-commenter-operator.el, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 76fd0c5692 160/235: go to original column after copy and comment, ELPA Syncer, 2022/01/06