emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil-nerd-commenter b8ac35fe01 225/235: add evilnc-yank-an


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter b8ac35fe01 225/235: add evilnc-yank-and-comment-operator
Date: Thu, 6 Jan 2022 02:59:50 -0500 (EST)

branch: elpa/evil-nerd-commenter
commit b8ac35fe019df5602c31912f65303a3d8ad0066c
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>

    add evilnc-yank-and-comment-operator
---
 README.org                      |  2 ++
 evil-nerd-commenter-operator.el | 31 +++++++++++++++++++++++--------
 evil-nerd-commenter.el          |  8 +++++---
 pkg.sh                          |  2 +-
 4 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/README.org b/README.org
index da9b7d50b7..8f5d2a8f76 100644
--- a/README.org
+++ b/README.org
@@ -255,6 +255,8 @@ Example 7: ",,it", comment the region inside html tags (all 
html major modes are
 ** evilnc-copy-and-comment-operator
 =evilnc-copy-and-comment-operator= is another evil-mode operator. Instead of 
commenting out the text in the operator-range, it inserts an copy of the text 
in the range and comments out that copy. Its hot key is ",.". For example, 
",.," to comment out the current line.
 
+** evilnc-yank-and-comment-operator
+Operator to comment or uncomment the text and yank the original text at the 
same time.
 * Tips
 ** Yank in evil-mode
 You can yank to line 99 using hotkey =y99G= or =y99gg=. That's the feature 
from evil-mode.
diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index 24f8ecde80..63a32d1349 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -174,10 +174,8 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
   (if (and (called-interactively-p 'any) (eq type 'line))
       (evil-first-non-blank)))
 
-(evil-define-operator evilnc-copy-and-comment-operator (begin end)
-  "Inserts a commented copy of the text from BEGIN to END."
-  :move-point (not evilnc-original-above-comment-when-copy-and-comment)
-  (interactive "<r>")
+(defun evilnc-comment-or-uncomment-region-then-action (begin end commenter 
&optional action)
+  "Comment/uncomment between BEGIN and END using COMMENTER, then take ACTION."
   (evil-with-single-undo
     ;; yank original text
     (evil-yank-lines begin end nil 'lines)
@@ -189,17 +187,34 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
     (cond
      (evilnc-original-above-comment-when-copy-and-comment
       (let* ((p (point)))
-        (comment-region begin end)
+        (funcall commenter begin end)
         (goto-char begin)
-        (evil-paste-before 1)
+        (when action (funcall action))
         (goto-char p)))
 
      (t
       (goto-char end)
-      (evil-paste-before 1)
+      (when action (funcall action))
       ;; actual comment operation should happen at last
       ;; or else begin end will be screwed up
-      (comment-region begin end)))))
+      (funcall commenter begin end)))))
+
+(evil-define-operator evilnc-yank-and-comment-operator (begin end)
+  "(Un)comment and yank the text from BEGIN to END."
+  :move-point (not evilnc-original-above-comment-when-copy-and-comment)
+  (interactive "<r>")
+  (evilnc-comment-or-uncomment-region-then-action begin
+                                                  end
+                                                  
evilnc-comment-or-uncomment-region-function))
+
+(evil-define-operator evilnc-copy-and-comment-operator (begin end)
+  "Inserts a commented copy of the text from BEGIN to END."
+  :move-point (not evilnc-original-above-comment-when-copy-and-comment)
+  (interactive "<r>")
+  (evilnc-comment-or-uncomment-region-then-action begin
+                                                  end
+                                                  'comment-region
+                                                  (lambda () 
(evil-paste-before 1))))
 
 (defun evilnc-one-line-comment-p (begin end)
   "Test if text between BEGIN and END is one line comment."
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 4bb77eae05..f7c9965b7d 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -3,7 +3,7 @@
 ;; Author: Chen Bin <chenbin DOT sh AT gmail.com>
 
 ;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.5.3
+;; Version: 3.5.4
 ;; Package-Requires: ((emacs "24.4"))
 ;; Keywords: convenience evil
 ;;
@@ -88,7 +88,9 @@
 ;;   - 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.
+;; `evilnc-yank-and-comment-operator' (un)comment&yank text in one shot.
+;;
+;; Comment text object "c" is defined.  It can have multi-lines.
 ;; Press "vac" to select outer object (comment with limiters).
 ;; Press "vic" to select inner object (comment without limiter).
 ;;
@@ -760,7 +762,7 @@ Then we operate the expanded region.  NUM is ignored."
 (defun evilnc-version ()
   "The version number."
   (interactive)
-  (message "3.5.3"))
+  (message "3.5.4"))
 
 (defvar evil-normal-state-map)
 (defvar evil-visual-state-map)
diff --git a/pkg.sh b/pkg.sh
index 890a7c3b1f..9aa89b386a 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
 #!/bin/bash
 name=evil-nerd-commenter
-version=3.5.3
+version=3.5.4
 pkg=$name-$version
 mkdir $pkg
 cp *.el $pkg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]