[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter 0a33fee751 026/235: (un)comment paragr
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter 0a33fee751 026/235: (un)comment paragraph |
Date: |
Thu, 6 Jan 2022 02:59:32 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit 0a33fee751a89a085e9a879292b97b780c557b69
Author: Chen Bin <Chen.Bin@optus.com.au>
Commit: Chen Bin <Chen.Bin@optus.com.au>
(un)comment paragraph
---
evil-nerd-commenter.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 61bc7afd31..dd3f9457bc 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -109,7 +109,74 @@
)
)
+
+(defun evilnc--comment-or-uncomment-one-paragraph ()
+ (let (b e (forward-search-done nil))
+ (save-excursion
+ (setq b (re-search-backward "^[ \t]*$" nil t))
+ (if b (progn
+ (forward-line)
+ (setq b (line-beginning-position))
+ )
+ (setq b 1)
+ )
+ )
+ (save-excursion
+ (setq e (re-search-forward "^[ \t]*$" nil t))
+ (if e (progn
+ (forward-line -1)
+ (setq e (line-end-position))
+ )
+ (progn
+ (setq e (point-max))
+ (setq forward-search-done t)
+ )
+ )
+ )
+ ;; (message "b e: %d %d" b e)
+ (when (<= b e)
+ (evilnc--fix-buggy-major-modes)
+ (comment-or-uncomment-region b e)
+ )
+ (if forward-search-done nil e)
+ )
+ )
+
+
;; ==== below this line are public commands
+;;;###autoload
+(defun evilnc-comment-or-uncomment-paragraphs (&optional NUM)
+ "Comment or uncomment paragraph(s). A paragraph is a continuation non-empty
lines.
+Paragraphs are separated by empty lines."
+ (interactive "p")
+ (let ((i 0)
+ rlt)
+ (catch 'break
+ (while (< i NUM)
+ (incf i)
+ (setq rlt (evilnc--comment-or-uncomment-one-paragraph))
+
+ ;; prepare for the next paragraph
+ (if (and rlt (< i NUM))
+ (progn
+ ;; rlt should be the end of last non-empty line
+ (goto-char rlt)
+
+ ;; (beginning-of-line)
+ ;; move to an empty line
+ (forward-line)
+ ;; record the empty line position for furture use
+ (setq rlt (line-beginning-position))
+
+ ;; move to next non-empty line
+ (re-search-forward "^[ \t]*[^ \t]" nil t)
+ (if (<= (line-beginning-position) rlt) (throw 'break i))
+ )
+ (throw 'break i)
+ )
+ )))
+ )
+
;;;###autoload
(defun evilnc-comment-or-uncomment-to-the-line (&optional LINENUM)
"Comment or uncomment from the current line to the LINENUM line"
@@ -184,11 +251,13 @@
(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)
+ (global-set-key (kbd "C-c p") 'evilnc-comment-or-uncomment-paragraphs)
(eval-after-load 'evil
'(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)
))
)
- [nongnu] branch elpa/evil-nerd-commenter created (now 63baf2d1c7), ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 9aa4593e19 005/235: typo in README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 83af4f4835 002/235: set evil hotkey after evil-leader loaded, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b4fcadabd9 001/235: first import, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 6e618b3c7f 008/235: tweak README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 906f01ee55 009/235: make my email not too public and updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 43034e5604 010/235: upgraded to version 0.0.3, now you can toggle flag to comment empty lines, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter e94cbcd747 011/235: Fixed typos in README.org, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 78569a4c0b 015/235: work around a bug in evil-visual-line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f3f0922b0b 020/235: fixed broken 0.0.6, upgraded to 0.0.7, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 0a33fee751 026/235: (un)comment paragraph,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter 3c3fb92e67 029/235: minor typo in README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 2491e83868 030/235: hotkey to comment region, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f8de9b168d 058/235: clean code a bit, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ccb31ba534 061/235: finalize doc v1.2.7, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 1848bc36a1 077/235: comment to the line is optimized v1.4.0, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 487e1cdf2b 098/235: fixed: upgrade from melpa may fail v1.5.6, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 7c75a0e782 050/235: fixed: initialize error when set up hotkeys, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b48da5411b 111/235: README updated, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 789a180160 100/235: FIXED: revert work on with-eval-after-load v1.5.8, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 7a1647cf6d 114/235: donot use comma as default hotkey, v 1.5.14, ELPA Syncer, 2022/01/06