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

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

[nongnu] elpa/evil-nerd-commenter b4b18c8190 017/235: you can copy and c


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter b4b18c8190 017/235: you can copy and comment lines in one command, upgraded to version 0.0.6
Date: Thu, 6 Jan 2022 02:59:31 -0500 (EST)

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

    you can copy and comment lines in one command, upgraded to version 0.0.6
---
 README.org                 | 13 ++++---
 evil-nerd-commenter-pkg.el |  2 +-
 evil-nerd-commenter.el     | 95 ++++++++++++++++++++++++++++++----------------
 pkg.sh                     |  2 +-
 4 files changed, 73 insertions(+), 39 deletions(-)

diff --git a/README.org b/README.org
index c7a2dcac1c..a64e9116d2 100644
--- a/README.org
+++ b/README.org
@@ -1,9 +1,9 @@
-* evil-nerd-commenter (current version 0.0.5)
+* evil-nerd-commenter (current version 0.0.6)
 As a developer, I often need comment/uncomment lines for debugging or adding 
some short comment in the code block.
 
 As I know, the [[http://www.vim.org/scripts/script.php?script_id=1218][Nerd 
Commenter]] for Vim is the most efficient way to doing this thing. 
Unfortunately, there is no similar plugin in Emacs.
 
-That's why I develop this Nerd Commenter simulator for Emacs people.
+That's why I develop this Nerd Commenter simulator for Emacs people. Besides, 
I'm also add my own comment related utilities into this plugin, like command to 
command *AND* copy lines.
 
 Though this program could be used *independently*, I highly recommend you use 
it with [[http://gitorious.org/evil][evil]]
 and [[https://github.com/cofi/evil-leader][evil-leader]].
@@ -25,10 +25,11 @@ evil-nerd-commenter is already uploaded to 
[[http://marmalade-repo.org/]]. So th
 * Set up
 Nothing to set up.
 
-You may add below line into ~/.emacs which use hotkey "M-;" to toggle comment:
+You may add below line into ~/.emacs which use hot key "M-;" to toggle comment:
 #+BEGIN_SRC lisp
-(global-set-key "\M-;" 'evilnc-comment-or-uncomment-lines)
-(global-set-key "\M-:" 'evilnc-comment-or-uncomment-to-the-line)
+(global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
+(global-set-key (kbd "M-:") 'evilnc-comment-or-uncomment-to-the-line)
+(global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
 #+END_SRC
 
 The advantage of use "M-;" is you can set mark on the first line and scroll 
several pages down and comment all the lines in that region by "M-;". The key 
point here is you save the extra two key strikes to make marked region wrap the 
whole content of first and second line.
@@ -43,12 +44,14 @@ Here is my configuration for evil-mode (*OPTIONAL!* some 
people don't use evil-m
 (evil-leader/set-key
   "ci" 'evilnc-comment-or-uncomment-lines
   "cl" 'evilnc-comment-or-uncomment-to-the-line
+  "cc" 'evilnc-copy-and-comment-lines
   )
 #+END_SRC
 * Usage
 Here are available commands:
 - evilnc-comment-or-uncomment-lines :: comment/uncomment lines.
 - evilnc-comment-or-uncomment-to-the-line :: comment/uncomment from current 
line to the specified line.
+- evilnc-copy-and-comment-lines :: copy and paste lines, then comment out 
original lines
 - evilnc-toggle-comment-empty-lines :: toggle the flag to comment/uncomment 
empty lines
 
 Example 1:
diff --git a/evil-nerd-commenter-pkg.el b/evil-nerd-commenter-pkg.el
index 93e3ef195a..86f49c75a9 100644
--- a/evil-nerd-commenter-pkg.el
+++ b/evil-nerd-commenter-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-nerd-commenter" "0.0.5"
+(define-package "evil-nerd-commenter" "0.0.6"
                 "Comment/uncomment lines efficiently. Like Nerd Commenter in 
Vim")
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 0c453822ab..d78e6fd72f 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: 0.0.5
+;; Version: 0.0.6
 ;; Keywords: commenter vim line evil
 ;;
 ;; This file is not part of GNU Emacs.
@@ -76,6 +76,40 @@
     )
   )
 
+(defun evilnc--operation-on-lines-or-region (fn)
+  (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
+      (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) (= e (line-beginning-position)) (boundp 
'evil-state) (string= 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)
+      )
+    )
+  )
+
+;; ==== below this line are public commands
 ;;;###autoload
 (defun evilnc-comment-or-uncomment-to-the-line (&optional LINENUM)
   "Comment or uncomment from the current line to the LINENUM line"
@@ -115,42 +149,39 @@
    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."
   (interactive "p")
-  (if (not (region-active-p))
-      (let ((b (line-beginning-position))
-            e)
-        (save-excursion
-          (forward-line (- NUM 1))
-          (setq e (line-end-position))
-          (evilnc--fix-buggy-major-modes)
-          (comment-or-uncomment-region b e)
-          )
-        )
-    ;; expand selected region
-    (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) (= e (line-beginning-position)) (boundp 'evil-state) 
(string= evil-state 'visual))
-            (setq e (1- e))
-            )
-        (goto-char b)
-        (setq b (line-beginning-position))
-        (goto-char e)
-        (setq e (line-end-position))
-        (evilnc--fix-buggy-major-modes)
-        (comment-or-uncomment-region b e)))
-    ))
+  (evilnc--operation-on-lines-or-region '(lambda (b e)
+                                           (evilnc--fix-buggy-major-modes)
+                                           (comment-or-uncomment-region b e)
+                                           ))
+  )
+
+;;;###autoload
+(defun evilnc-copy-and-comment-lines (&optional NUM)
+  "Copy and paste lines. Then comment original lines.
+   Case 1: If no region selected, operate 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 operate the expanded region. NUM is ignored.
+"
+  (interactive "p")
+  (evilnc--operation-on-lines-or-region
+   '(lambda (beg end)
+      (evilnc--fix-buggy-major-modes)
+      (let ((str (buffer-substring-no-properties beg end)))
+        (goto-char end)
+        (newline 1)
+        (insert-before-markers str)
+        (comment-region beg end)
+        )))
+  )
 
 ;;;###autoload
 (defun evilnc-default-hotkeys ()
   "Set the hotkeys of evil-nerd-comment"
   (interactive)
-  (global-set-key "\M-;" 'evilnc-comment-or-uncomment-lines)
-  (global-set-key "\M-:" 'evilnc-comment-or-uncomment-to-the-line)
+  (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
+  (global-set-key (kbd "M-:") 'evilnc-comment-or-uncomment-to-the-line)
+  (global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
   )
 
 (provide 'evil-nerd-commenter)
diff --git a/pkg.sh b/pkg.sh
index 8b19962f4e..1a4399c170 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-pkg=evil-nerd-commenter-0.0.5
+pkg=evil-nerd-commenter-0.0.6
 mkdir $pkg
 cp README.org $pkg
 cp *.el $pkg



reply via email to

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