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

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

[nongnu] elpa/evil-nerd-commenter 1f32941bce 047/235: v1.2.0


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter 1f32941bce 047/235: v1.2.0
Date: Thu, 6 Jan 2022 02:59:34 -0500 (EST)

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

    v1.2.0
    
    - adjust hokey to respect evil-leader
    - uncomment text object
---
 README.org                 | 45 +++++++++++++-------------
 evil-nerd-commenter-pkg.el |  2 +-
 evil-nerd-commenter.el     | 78 ++++++++++++++++++++++++++++++++++++++++------
 pkg.sh                     |  2 +-
 4 files changed, 95 insertions(+), 32 deletions(-)

diff --git a/README.org b/README.org
index 6d9c89ff3d..8a289d9d83 100644
--- a/README.org
+++ b/README.org
@@ -1,17 +1,17 @@
-* evil-nerd-commenter (current version 1.1.0)
+* evil-nerd-commenter (current version 1.2.0)
 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. Besides, 
I'm also adding my own utilities into this plugin. For example, I added a 
command to comment *AND* copy lines in version 1.1.0.
+That's why I develop this Nerd Commenter simulator for Emacs people. Besides, 
I'm also adding my own utilities into this plugin. For example, I added a 
command to comment *AND* copy lines in version 1.2.0.
 
 Though this program could be used *independently*, I highly recommend you use 
it with [[http://gitorious.org/evil][evil]].
 
-Evil makes you take advantage of power of Vi to comment lines in shocking 
speed. For example, you can press key `,99j` to comment out 99 lines.
+Evil makes you take advantage of power of Vi to comment lines in shocking 
speed. For example, you can press key `,,99j` or `99,ci` to comment out 99 
lines.
 
 * Why evil-nerd-commenter is better? 
 ** A simple use case on the efficiency
-Say you want to comment out nine lines. Instead pressing "C-space M-9 C-n 
M-;", now you can press "M-9 M-;" or ",9j".
+Say you want to comment out nine lines. Instead pressing "C-space M-9 C-n 
M-;", now you can press "M-9 M-;" or ",,9j" or "9,ci".
 
 The key point is you need *NOT* mark any text to comment line(s)!
 
@@ -43,22 +43,23 @@ Further explanation, the content of evilnc-default-hotkeys 
is:
   (global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
   (global-set-key (kbd "C-c p") 'evilnc-comment-or-uncomment-paragraphs)
   (eval-after-load 'evil
-    '(when (fboundp 'evilnc-comment-operator)
-       (define-key evil-normal-state-map "," 'evilnc-comment-operator)
-       (define-key evil-visual-state-map "," 'evilnc-comment-operator))))
+       (define-key evil-normal-state-map ",ci" 
'evilnc-comment-or-uncomment-lines)
+       (define-key evil-normal-state-map ",cl" 
'evilnc-comment-or-uncomment-to-the-line)
+       (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 ",," 'evilnc-comment-operator)
+       (define-key evil-visual-state-map ",," 'evilnc-comment-operator)
+       ))
 #+END_SRC
 
 As you can see, the default hot key for commenting lines is "M-;" when you 
don't use [[http://emacswiki.org/emacs/Evil][evil-mode]].
 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 last line.
 
-I prefer vi key binds. So I also use 
[[http://emacswiki.org/emacs/Evil][evil-mode]].
+I prefer vi key binds. So I also use 
[[http://emacswiki.org/emacs/Evil][evil-mode]]. Evil-mode is only *optional*! 
Some people dont use it because they prefer emacs native key binding.
+
+Feel free to copy the content of evilnc-default-hotkeys into your .emacs 
instead calling it directly. So you can define your own hotkeys.
 
-Here is my configuration for evil-mode (*OPTIONAL!* some people don't use 
evil-mode at all because they don't like vi key bindings):
-#+BEGIN_SRC lisp
-(require 'evil)
-(define-key evil-normal-state-map "," 'evilnc-comment-operator)
-(define-key evil-visual-state-map "," 'evilnc-comment-operator)
-#+END_SRC
 * Usage
 Here are available commands:
 - evilnc-comment-or-uncomment-lines :: comment/uncomment lines.
@@ -90,21 +91,23 @@ var myJson={
 #+END_SRC
 
 * Evil Usage
-If you use [[http://emacswiki.org/emacs/Evil][evil-mode]], you get an operator 
that works with all the usual text objects and motions:
+If you use [[http://emacswiki.org/emacs/Evil][evil-mode]], you get an operator 
that works with all the usual 
[[http://vimdoc.sourceforge.net/htmldoc/motion.html#text-objects][text objects 
and motions]]:
 
 - 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.  
 
-Example 1: ",," to comment out the current line.
+By default we assign the hot key ",," to evilnc-comment-operator.
+
+Example 1: ",,," to comment out the current line.
 
-Example 2: ",9j" to comment out the next 9 lines.
+Example 2: ",,9j" to comment out the next 9 lines.
 
-Example 3: ",99G" to comment from the current line to line 99.
+Example 3: ",,99G" to comment from the current line to line 99.
 
-Example 4: ",a(" to comment out the current s-expression, or ",i(" to only 
comment out the s-expression's content.  Similarly for blocks ",a{", etc.
+Example 4: ",,a(" to comment out the current s-expression, or ",,i(" to only 
comment out the s-expression's content.  Similarly for blocks ",,a{", etc.
 
-Example 5: ",ao" to comment out the current symbol, or ",aW" to comment out 
the current WORD.  Could be useful when commenting out function parameters, for 
instance.
+Example 5: ",,ao" to comment out the current symbol, or ",,aW" to comment out 
the current WORD.  Could be useful when commenting out function parameters, for 
instance.
 
-Example 6: ",w" comments to the beginning of the next word, ",e" to the end of 
the next word, ",b" to the beginning of the previous word.
+Example 6: ",,w" comments to the beginning of the next word, ",,e" to the end 
of the next word, ",,b" to the beginning of the previous word.
 
 * Contact me
 You can report bugs at [[https://github.com/redguardtoo/evil-nerd-commenter]]. 
My email is <chenbin.sh@gmail.com>.
diff --git a/evil-nerd-commenter-pkg.el b/evil-nerd-commenter-pkg.el
index 434c8215f6..7eba0abb20 100644
--- a/evil-nerd-commenter-pkg.el
+++ b/evil-nerd-commenter-pkg.el
@@ -1,2 +1,2 @@
-(define-package "evil-nerd-commenter" "1.1.0"
+(define-package "evil-nerd-commenter" "1.2.0"
                 "Comment/uncomment lines efficiently. Like Nerd Commenter in 
Vim")
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 8744c24118..d40fc58963 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.1.0
+;; Version: 1.2.0
 ;; Keywords: commenter vim line evil
 ;;
 ;; This file is not part of GNU Emacs.
@@ -135,6 +135,45 @@
     )
   )
 
+(defun evilnc--in-comment-p (pos)
+  (interactive)
+  (let ((fontface (get-text-property pos 'face)))
+    ;; learn this trick from flyspell
+    (or (string= fontface 'font-lock-comment-face)
+        (string= fontface 'font-lock-comment-delimiter-face)
+        )
+    ))
+
+;; @return (list beg end)
+(defun evilnc--extend-to-whole-comment (beg end)
+  (interactive)
+  (if (evilnc--in-comment-p beg)
+      (save-excursion
+        (let ((newbeg beg)
+              (newend end))
+
+          ;; extend the beginning
+          (goto-char newbeg)
+          (while (and (>= newbeg (line-beginning-position)) 
(evilnc--in-comment-p newbeg))
+            (decf newbeg)
+            )
+          ;; make sure newbeg is at the beginning of the comment
+          (if (< newbeg beg) (incf newbeg))
+
+          ;; extend the end
+          (goto-char newend)
+          (while (and (<= newend (line-end-position)) (evilnc--in-comment-p 
newend))
+            (incf newend)
+            )
+          ;; make sure newend is at the end of the comment
+          (if (> newend end) (decf newend))
+
+          (list newbeg newend)
+          )
+        )
+    (list beg end)
+    ))
+
 
 ;; ==== below this line are public commands
 ;;;###autoload
@@ -262,12 +301,24 @@ Paragraphs are separated by empty lines."
   (global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
   (global-set-key (kbd "C-c p") 'evilnc-comment-or-uncomment-paragraphs)
   (eval-after-load 'evil
-    '(progn (evilnc-define-comment-operator)
-            (define-key evil-normal-state-map "," 'evilnc-comment-operator)
-            (define-key evil-visual-state-map "," 'evilnc-comment-operator))))
+    '(progn
+       (define-key evil-normal-state-map ",ci" 
'evilnc-comment-or-uncomment-lines)
+       (define-key evil-normal-state-map ",cl" 
'evilnc-comment-or-uncomment-to-the-line)
+       (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)
+       ;; Please note evilnc-comment-operator require evil-mode
+       ;; press key ",," which is default value 
evilnc-operator-to-comment-text-object
+       ;; example, presss ",,a{" will change C code:
+       ;;  {printf("hello");} to /* {printf("hello");}*/
+       ;; google "vim text object for more syntax"
+       (define-key evil-normal-state-map ",," 'evilnc-comment-operator)
+       (define-key evil-visual-state-map ",," 'evilnc-comment-operator)
+       )))
 
+;;;###autoload
 (defun evilnc-define-comment-operator ()
-  "Attempts to define the comment operator evilnc-comment-operator.  
+  "Attempts to define the comment operator evilnc-comment-operator.
 
 Will only work if 'evil-define-operator is defined and 
'evilnc-comment-operator is not."
   (interactive)
@@ -285,7 +336,10 @@ Save in REGISTER or in the kill-ring with YANK-HANDLER."
       (evil-yank beg end type register yank-handler)
       (cond
        ((eq type 'block)
-        (evil-apply-on-block #'comment-or-uncomment-region beg end nil))
+        (let ((newpos (evilnc--extend-to-whole-comment beg end) ))
+          (evil-apply-on-block #'comment-or-uncomment-region (nth 0 newpos) 
(nth 1 newpos) nil)
+          )
+        )
        ((and (eq type 'line)
              (= end (point-max))
              (or (= beg end)
@@ -294,15 +348,21 @@ Save in REGISTER or in the kill-ring with YANK-HANDLER."
              (=  (char-before beg) ?\n))
         (comment-or-uncomment-region (1- beg) end))
        (t
-        (comment-or-uncomment-region beg end)))
+        (let ((newpos (evilnc--extend-to-whole-comment beg end) ))
+          (comment-or-uncomment-region (nth 0 newpos) (nth 1 newpos))
+          )
+        ))
       ;; place cursor on beginning of line
       (when (and (evil-called-interactively-p)
                  (eq type 'line))
         (evil-first-non-blank)))))
 
-;; Attemps to define the operator on first load.
+;; Attempt to define the operator on first load.
 ;; Will only work if evil has been loaded
-(evilnc-define-comment-operator)
+(eval-after-load 'evil
+  '(progn
+     (evilnc-define-comment-operator)
+     ))
 
 (provide 'evil-nerd-commenter)
 
diff --git a/pkg.sh b/pkg.sh
index 92a316553c..f0b7ab076d 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-pkg=evil-nerd-commenter-1.1.0
+pkg=evil-nerd-commenter-1.2.0
 mkdir $pkg
 cp README.org $pkg
 cp *.el $pkg



reply via email to

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