[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter ee14b9def5 057/235: invert line done
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter ee14b9def5 057/235: invert line done |
Date: |
Thu, 6 Jan 2022 02:59:34 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit ee14b9def57dfe9eae442bd9dacdc7921768ec72
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
invert line done
---
README.org | 1 +
evil-nerd-commenter.el | 59 +++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/README.org b/README.org
index fb0215c35d..03599447b1 100644
--- a/README.org
+++ b/README.org
@@ -93,6 +93,7 @@ Here are available commands. They are not dependent on
[[http://emacswiki.org/em
- evilnc-comment-or-uncomment-paragraphs :: comment/uncomment paragraphs which
separated by empty lines
- evilnc-toggle-comment-empty-lines :: toggle the flag to comment/uncomment
empty lines
- evilnc-copy-to-line :: Copy from the current line to the user specified
line, *for non-evil user only, you need set hot key for it*
+- evilnc-toggle-invert-comment-line-by-line :: toggle flag
evilnc-invert-comment-line-by-line. When this flag is true, the command
"evilnc-comment-or-uncomment-lines", "evilnc-comment-or-uncomment-to-the-line",
and "evilnc-comment-or-uncomment-paragraphs" will invert each line's comment
status.
- evilnc-kill-to-line :: Kill from the current line to the user specified
line, *for non-evil user only, you need set hot key for it*
Example 1:
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 1570c0a957..054756ca50 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -54,6 +54,8 @@
:type 'string
:group 'evil-nerd-commenter)
+(defvar evilnc-invert-comment-line-by-line nil "if t then invert region
comment status line by line")
+
;; shamelessly copied from goto-line
(defun evilnc--goto-line (line)
(save-restriction
@@ -181,6 +183,32 @@
(list beg end)
))
+(defun evilnc--invert-comment (beg end)
+ "scan the region line by line, invert its comment status"
+ (let (done b e)
+ (save-excursion
+ (goto-char end)
+ ;; comment (line-beginning-position line-end-position)
+ ;; (setq old-b (line-beginning-position)
+ ;; (forward-line -1)
+ ;; (if (= old-b (line-beginning-position)) we did't move, out of loop
+ ;; (if (<= (line-end-position) beg)), out of region, out of loop
+ (while (not done)
+ (setq b (line-beginning-position))
+ (setq e (line-end-position))
+ (funcall (if (comment-only-p b e)
+ 'uncomment-region 'comment-region)
+ b e)
+ (forward-line -1)
+ (when (or (= (line-beginning-position) b) (< (line-end-position) beg))
+ (setq done t))
+ ))))
+
+(defun evilnc--comment-or-uncomment-region (beg end)
+ (if evilnc-invert-comment-line-by-line
+ (evilnc--invert-comment beg end)
+ (comment-or-uncomment-region beg end)
+ ))
;; ==== below this line are public commands
;;;###autoload
@@ -226,11 +254,8 @@ Paragraphs are separated by empty lines."
(when (<= b e)
(save-excursion
(evilnc--fix-buggy-major-modes)
- (comment-or-uncomment-region b e)
- )
- )
- )
- )
+ (evilnc--comment-or-uncomment-region b e)
+ ))))
;;;###autoload
(defun evilnc-comment-or-uncomment-to-the-line (&optional LINENUM)
@@ -246,10 +271,19 @@ Paragraphs are separated by empty lines."
(if (> (line-end-position) e)
(setq e (line-end-position)))
(evilnc--fix-buggy-major-modes)
- (comment-or-uncomment-region b e)
- )
- )
- ))
+ (evilnc--comment-or-uncomment-region b e)
+ ))))
+
+;;;###autoload
+(defun evilnc-toggle-invert-comment-line-by-line ()
+ (interactive)
+ (if evilnc-invert-comment-line-by-line
+ (setq evilnc-invert-comment-line-by-line nil)
+ (setq evilnc-invert-comment-line-by-line t)
+ )
+ (message (if evilnc-invert-comment-line-by-line
+ "Each line's comment status will be inverted"
+ "Each line's comment status will NOT be inverted")))
;;;###autoload
(defun evilnc-toggle-comment-empty-lines ()
@@ -260,8 +294,7 @@ Paragraphs are separated by empty lines."
)
(message (if comment-empty-lines
"Empty line(s) will be commented"
- "Empty line(s) will NOT be commented"))
- )
+ "Empty line(s) will NOT be commented")))
;;;###autoload
(defun evilnc-comment-or-uncomment-lines (&optional NUM)
@@ -280,7 +313,7 @@ Paragraphs are separated by empty lines."
(evilnc--operation-on-lines-or-region '(lambda (b e)
(evilnc--fix-buggy-major-modes)
- (comment-or-uncomment-region b e)
+
(evilnc--comment-or-uncomment-region b e)
)
NUM)))
@@ -364,7 +397,7 @@ Paragraphs are separated by empty lines."
(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)
- )))
+ (define-key evil-normal-state-map ",cv"
'evilnc-toggle-invert-comment-line-by-line))))
;; Attempt to define the operator on first load.
;; Will only work if evil has been loaded
- [nongnu] elpa/evil-nerd-commenter 944fc7417d 031/235: Added comment operator (modelled after delete/change operator)., (continued)
- [nongnu] elpa/evil-nerd-commenter 944fc7417d 031/235: Added comment operator (modelled after delete/change operator)., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter d016f26471 036/235: Changed word to WORD (which goes through symbolic characters), ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 516fe784dc 040/235: Updated snippet to reflect code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 5263a96f3b 042/235: Made , work in visual mode as well, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter e1d39be8e3 044/235: Added additional evil example, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 237040205e 046/235: Made definition of evilnc-comment-operator a callable function, evilnc-define-comment-operator. Only does anything if 'evil-define-operator bound and 'evilnc-comment-operator isn't., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter fbd9d01a8c 043/235: Added visual map to readme recommendations, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b9cfe0c7a6 054/235: some evil tips, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 69a8710e3d 053/235: v1.2.4, updated doc on set up, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 9c43de8b19 064/235: Merge pull request #22 from chrueg/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ee14b9def5 057/235: invert line done,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter b456b82cce 068/235: Merge pull request #24 from untf/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter e6a8ef9399 072/235: minor wording error, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b44141bd06 074/235: Revert "minor wording error", ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 6d1e01bfb5 076/235: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 2dc8d8dd6c 078/235: README updated, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 337c66f376 080/235: web-mode is supported v1.5.0, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 627ac531a1 085/235: issue 5 the evil-visual 100 percent resolved, v1.5.1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 906f532241 092/235: M-; should start a comment on an empty line #34 v1.5.3, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 4d03da77c8 093/235: Make copy-and-comment interactive, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter fe82e6a0ff 091/235: README v1.5.2, ELPA Syncer, 2022/01/06