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

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

[nongnu] elpa/evil-nerd-commenter 8c0f23d46a 2/2: add evilnc-comment-box


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter 8c0f23d46a 2/2: add evilnc-comment-box
Date: Wed, 7 Dec 2022 07:58:49 -0500 (EST)

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

    add evilnc-comment-box
---
 README.org             | 31 +++----------------
 evil-nerd-commenter.el | 84 ++++++++++++++++++++++++++++++++------------------
 2 files changed, 59 insertions(+), 56 deletions(-)

diff --git a/README.org b/README.org
index 212edffb22..48913e5312 100644
--- a/README.org
+++ b/README.org
@@ -38,33 +38,8 @@ Insert =(evilnc-default-hotkeys)= into =~/.emacs= to use key 
bindings preset for
 Use =(evilnc-default-hotkeys t)= to use key binding only for non-evil mode if 
you want to define key bindings in evil-mode by yourself.
 
 Use =(evilnc-default-hotkeys nil t)= to use key binding only for evil mode if 
you want to define key bindings in Emacs mode by yourself.
-** Use evil-leader instead
-Install [[https://github.com/cofi/evil-leader][evil-leader according to its 
README]].
-
-Insert following code into you =~/.emacs=,
-#+BEGIN_SRC elisp
-;; Emacs key bindings
-(global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
-(global-set-key (kbd "C-c l") 'evilnc-quick-comment-or-uncomment-to-the-line)
-(global-set-key (kbd "C-c c") 'evilnc-copy-and-comment-lines)
-(global-set-key (kbd "C-c p") 'evilnc-comment-or-uncomment-paragraphs)
-
-;; Vim key bindings
-(require 'evil-leader)
-(global-evil-leader-mode)
-(evil-leader/set-key
-  "ci" 'evilnc-comment-or-uncomment-lines
-  "cl" 'evilnc-quick-comment-or-uncomment-to-the-line
-  "ll" 'evilnc-quick-comment-or-uncomment-to-the-line
-  "cc" 'evilnc-copy-and-comment-lines
-  "cp" 'evilnc-comment-or-uncomment-paragraphs
-  "cr" 'comment-or-uncomment-region
-  "cv" 'evilnc-toggle-invert-comment-line-by-line
-  "."  'evilnc-copy-and-comment-operator
-  "\\" 'evilnc-comment-operator ; if you prefer backslash key
-)
-#+END_SRC
 
+You can also use third party package 
[[https://github.com/noctuid/general.el][general.el]] instead of calling 
=evilnc-default-hotkeys=.
 ** Assign key bindings manually
 Manual setup is necessary for certain major modes (matlab-mode, for example)
 
@@ -186,6 +161,10 @@ For example:
 If a line is snippet wrapped HTML tags in HTML template, only the HTML syntax 
is used to comment out the line by default.
 
 But if you =(setq evilnc-comment-both-snippet-html t)=, snippet will be 
commented out with its own syntax at first. Then the wrapped html tag will be 
comment out using HTML syntax. This flag has effect on all above commands.  
[[http://web-mode.org/][Web-mode]] should be enabled to use this flag.
+*** evilnc-comment-box
+Comment out N lines, putting it inside a box. N could be negative. If N is 
nil, comment out current paragraph.  This command uses builtin API 
=comment-box=.
+
+The hotkey is ",cs" in evil-mode
 *** Use imenu to list and jump to comments in current file
 Please setup `imenu-create-index-function' to 
`evilnc-imenu-create-index-function'.
 
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index ef29009e1d..8c6c49f1a5 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -3,8 +3,8 @@
 ;; Author: Chen Bin <chenbin.sh@gmail.com>
 
 ;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.5.8
-;; Package-Requires: ((emacs "25.1"))
+;; Version: 3.6.0
+;; Package-Requires: ((emacs "26.1"))
 ;; Keywords: convenience evil
 ;;
 ;; This file is not part of GNU Emacs.
@@ -48,8 +48,8 @@
 ;; For example, `C-u 9 evilnc-quick-comment-or-uncomment-to-the-line` comments
 ;; code from current line to line 99 if you current line is 91.
 ;;
-;; Though this program could be used *independently*, though I highly recommend
-;; using it with Evil (https://bitbucket.org/lyro/evil/)
+;; Though this program could be used *independently*, it's recommended to
+;; us it with Evil.
 ;;
 ;; Evil makes you take advantage of power of Vi to comment lines.
 ;; For example, you can press key `99,ci` to comment out 99 lines.
@@ -57,34 +57,24 @@
 ;; Setup:
 ;;
 ;; If comma is your leader key, as most Vim users do, setup is one liner,
-;; (evilnc-default-hotkeys)
-;;
-;; If you use evil-leader and its default leader key,
-;; insert below setup into your ~/.emacs instead,
-;;
-;; (global-set-key (kbd "M-;") 'evilnc-comment-or-uncomment-lines)
-;;
-;; (require 'evil-leader)
-;; (global-evil-leader-mode)
-;; (evil-leader/set-key
-;;   "ci" 'evilnc-comment-or-uncomment-lines
-;;   "cl" 'evilnc-quick-comment-or-uncomment-to-the-line
-;;   "ll" 'evilnc-quick-comment-or-uncomment-to-the-line
-;;   ;; Or use `evilnc-comment-and-kill-ring-save' instead
-;;   "cc" 'evilnc-copy-and-comment-lines
-;;   "cp" 'evilnc-comment-or-uncomment-paragraphs
-;;   "cr" 'comment-or-uncomment-region
-;;   "cv" 'evilnc-toggle-invert-comment-line-by-line
-;;   "."  'evilnc-copy-and-comment-operator
-;;   "\\" 'evilnc-comment-operator)
+;;   (evilnc-default-hotkeys)
 ;;
-;; `evilnc-comment-or-uncomment-html-tag' comment/uncomment html tag(s).
-;; `evilnc-comment-or-uncomment-html-paragraphs' comment/uncomment paragraphs
-;; containing html tags.
+;; Or else you can set up key bindings of below commands by yourself.
+;;   `evilnc-comment-or-uncomment-lines'
+;;   `evilnc-quick-comment-or-uncomment-to-the-line'
+;;   `evilnc-comment-and-kill-ring-save'
+;;   `evilnc-copy-and-comment-lines'
+;;   `evilnc-comment-or-uncomment-paragraphs'
+;;   `evilnc-comment-box'
+;;   `evilnc-toggle-invert-comment-line-by-line'
+;;   `evilnc-copy-and-comment-operator'
+;;   `evilnc-comment-operator'
+;;   `evilnc-comment-or-uncomment-html-tag'
+;;   `evilnc-comment-or-uncomment-html-paragraphs'
 ;;
-;; You can setup `evilnc-original-above-comment-when-copy-and-comment'
-;; to decide which style to use when `evilnc-copy-and-comment-lines'
-;; or `evilnc-copy-and-comment-operator',
+;; Set up `evilnc-original-above-comment-when-copy-and-comment'
+;; to decide which style to use in `evilnc-copy-and-comment-lines'
+;; and `evilnc-copy-and-comment-operator',
 ;;   - Place the commented out text above original text
 ;;   - Or place the original text above commented out text
 ;;
@@ -799,6 +789,8 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings 
in EMACS mode."
     (define-key evil-normal-state-map ",cc" 'evilnc-copy-and-comment-lines)
     (define-key evil-visual-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 ",cs" 'evilnc-comment-box)
+    (define-key evil-visual-state-map ",cs" 'evilnc-comment-box)
     (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)
 
@@ -980,6 +972,38 @@ Paragraphs are separated by empty lines."
      (evilnc-comment-or-uncomment-html-tag))
    num))
 
+(defun evilnc-comment-box (&optional num)
+  "Comment out NUM lines, putting it inside a box.  NUM could be negative.
+If NUM is nil, comment out current paragraph.  This command uses 
`comment-box'."
+  (interactive "P")
+  (let* ((orig-pos (evilnc-guess-position-at-point))
+         range)
+
+    (cond
+     ((or (not num))
+      (when (setq range (bounds-of-thing-at-point 'paragraph))
+        (evilnc--fix-buggy-major-modes)
+        (when (evilnc-visual-line-p) (evil-normal-state))
+        (comment-box (car range) (cdr range) 1)))
+     (t
+      (save-excursion
+        (when (< num 0)
+          (evilnc--forward-line (1+ num))
+          (setq num (- 0 num)))
+        (evilnc--operation-on-lines-or-region
+         (lambda (b e)
+           (evilnc--fix-buggy-major-modes)
+           ;; when comment in evil visual state, the cursor may be rogue
+           (when (evilnc-visual-line-p) (evil-normal-state))
+           (comment-box b e 1))
+         num))))
+
+    (unless (eq (evilnc-guess-position-at-point) orig-pos)
+      (evilnc--goto-line (car orig-pos))
+      ;; make sure we stay on original line
+      (goto-char (min (+ (line-beginning-position) (cdr orig-pos))
+                      (1- (line-end-position)))))))
+
 ;; Attempt to define the operator on first load.
 ;; Will only work if evil has been loaded
 (with-eval-after-load 'evil



reply via email to

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