[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
- [nongnu] elpa/evil-nerd-commenter 71995b8ac3 034/235: Updated readme, (continued)
- [nongnu] elpa/evil-nerd-commenter 71995b8ac3 034/235: Updated readme, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 0e24866151 048/235: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f3d4f7ef29 070/235: better integration with org-mode v1.3.0, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 1edf652fc6 086/235: explain how NOT to use comma as leader key, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter befd4da216 117/235: Comment operator should not be filling registers and kill-ring, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 9220e93853 128/235: Merge pull request #56 from syohex/correct-package-headers, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 7a441580ae 141/235: Save position in org-mode src blocks., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 80f503be1e 161/235: typo in doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 16dcffac65 163/235: Fix doc-string typo and length, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 4dca3cc33d 012/235: Merge pull request #4 from darth10/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b4b18c8190 017/235: you can copy and comment lines in one command, upgraded to version 0.0.6,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter 01556c89ba 021/235: add live demo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 2b68b829fe 023/235: fixed regression since 0.0.6: cannot comment region, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 94f87db048 025/235: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 5d9635cc11 028/235: better support for commenting multiple paragraph, v1.0.0, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 425294cc71 032/235: Replaced default evil setup with , operator, ELPA Syncer, 2022/01/06
- [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