[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter 5cf8755264 191/235: clean code. more u
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter 5cf8755264 191/235: clean code. more unit test. bump 3.3.6 |
Date: |
Thu, 6 Jan 2022 02:59:47 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit 5cf87552648b8168d6c9a0a97982468cd764384d
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
clean code. more unit test. bump 3.3.6
---
README.org | 2 +-
evil-nerd-commenter-tests.el | 44 +++++++++++++++++
evil-nerd-commenter.el | 115 +++++++++++++++++++++----------------------
pkg.sh | 2 +-
4 files changed, 101 insertions(+), 62 deletions(-)
diff --git a/README.org b/README.org
index dd40ee4617..687629c595 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (v3.3.5)
+* evil-nerd-commenter (v3.3.6)
[[https://travis-ci.org/redguardtoo/evil-nerd-commenter][https://travis-ci.org/redguardtoo/evil-nerd-commenter.svg?branch=master]]
[[http://melpa.org/#/evil-nerd-commenter][file:http://melpa.org/packages/evil-nerd-commenter-badge.svg]]
[[http://stable.melpa.org/#/evil-nerd-commenter][file:http://stable.melpa.org/packages/evil-nerd-commenter-badge.svg]]
diff --git a/evil-nerd-commenter-tests.el b/evil-nerd-commenter-tests.el
index be610d8ecf..dc20adc7a0 100644
--- a/evil-nerd-commenter-tests.el
+++ b/evil-nerd-commenter-tests.el
@@ -132,4 +132,48 @@
(setq lang-f (evilnc--org-lang-major-mode))
(should (string= lang-f "emacs-lisp-mode")))))
+(ert-deftest evilnc-test-paragraph-line-calculation ()
+ (let* (selected-region)
+ (with-temp-buffer
+ (insert "hello world\n"
+ "\n"
+ "para1 begin\n"
+ "line 4\n"
+ "line 5\n"
+ "para1 end\n"
+ "\n"
+ "bye world")
+
+ ;; test paragraph selection
+ (goto-char (point-min))
+ ;; begin of paragraph
+ (re-search-forward "para1 begin")
+ (setq selected-region (evilnc--get-one-paragraph-region))
+ (should (eq 14 (car selected-region)))
+ (should (eq 49 (cadr selected-region)))
+ ;; middle of paragraph
+ (re-search-forward "line 4")
+ (setq selected-region (evilnc--get-one-paragraph-region))
+ (should (eq 14 (car selected-region)))
+ (should (eq 49 (cadr selected-region)))
+
+ ;; test line number
+ (goto-char (point-min))
+ ;; move focus to line 4
+ (re-search-forward "line 4")
+ ;; line 14 is close
+ (should (eq 14 (evilnc--find-destination-linenum 4)))
+ ;; line 5 is close to line 4
+ (should (eq 5 (evilnc--find-destination-linenum 5)))
+ ;; line 9 is close to line 4
+ (should (eq 9 (evilnc--find-destination-linenum 9)))
+ ;; move focus to line 5
+ (re-search-forward "line 5")
+ ;; line 14 is close, ignore the lines abover current line (line 5)
+ (should (eq 14 (evilnc--find-destination-linenum 4)))
+ ;; line 5 is close to line 4
+ (should (eq 15 (evilnc--find-destination-linenum 5)))
+ ;; line 9 is close to line 4
+ (should (eq 9 (evilnc--find-destination-linenum 9))))))
+
(ert-run-tests-batch-and-exit)
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index e07672b1c5..f0b0b1a6f5 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -3,7 +3,7 @@
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.3.5
+;; Version: 3.3.6
;; Package-Requires: ((emacs "24.4"))
;; Keywords: commenter vim line evil
;;
@@ -276,19 +276,20 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
(defun evilnc--get-one-paragraph-region ()
"Select a paragraph which has NO empty line."
- (let* (b e)
- (save-excursion
- (if (setq b (re-search-backward "^[ \t]*$" nil t))
- (progn
- (forward-line)
- (setq b (line-beginning-position)))
- (setq b 1)))
- (save-excursion
- (if (setq e (re-search-forward "^[ \t]*$" nil t))
- (progn
- (forward-line -1)
- (setq e (line-end-position)))
- (setq e (point-max))))
+ (let* ((b (save-excursion
+ (cond
+ ((re-search-backward "^[ \t]*$" nil t)
+ (forward-line)
+ (line-beginning-position))
+ (t
+ 1))))
+ (e (save-excursion
+ (cond
+ ((re-search-forward "^[ \t]*$" nil t)
+ (forward-line -1)
+ (line-end-position))
+ (t
+ (point-max))))))
(list b e)))
(defun evilnc--invert-comment (beg end)
@@ -314,22 +315,19 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
(defun evilnc--org-lang-major-mode ()
"Get `major-mode' for language of org source block."
- (let* (info lang lang-f)
- (when (eq major-mode 'org-mode)
- (cond
- ;; Emacs 24.4+
- ((fboundp 'org-edit-src-find-region-and-lang)
- (setq info (org-edit-src-find-region-and-lang))
- (when info
- (setq lang (or (cdr (assoc (nth 2 info) org-src-lang-modes))
- (nth 2 info)))))
-
- ;; Emacs 26.1
- ((fboundp 'org-element-at-point)
- (setq lang
- (let ((lang (org-element-property :language
(org-element-at-point))))
- (or (cdr (assoc lang org-src-lang-modes)) lang))))))
- (when lang
+ (let* (info lang lang-f fallback-lang)
+ (cond
+ ;; Emacs 24.4+
+ ((and (fboundp 'org-edit-src-find-region-and-lang)
+ (setq info (org-edit-src-find-region-and-lang)))
+ (setq info (nth 2 info)))
+
+ ;; Emacs 26.1
+ ((fboundp 'org-element-at-point)
+ (setq info (org-element-property :language (org-element-at-point)))))
+
+ (when (setq lang (or (cdr (assoc info org-src-lang-modes))
+ info))
(setq lang (if (symbolp lang) (symbol-name lang) lang))
(setq lang-f (intern (concat lang "-mode"))))
lang-f))
@@ -338,7 +336,7 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
"Region from BEG to END is applied with operation FN.
Code snippets embedded in Org-mode is identified and right `major-mode' is
used."
(let* (pos
- (lang-f (evilnc--org-lang-major-mode))
+ (lang-f (if (eq major-mode 'org-mode) (evilnc--org-lang-major-mode)))
old-flag)
;; turn on 3rd party language's major-mode temporarily
@@ -476,22 +474,19 @@ DO-COMMENT decides we comment or uncomment."
(goto-char position)
(evilnc--current-line-num)))
-(defun evilnc--find-dst-line-num (UNITS)
- "Find closet line whose line number ends with digit UNITS.
-Given UNITS as 5, line 5, line 15, and line 25 are good candidates.
-If UNITS is 16, line 16, line 116, and line 216 are good candidates."
+(defun evilnc--find-destination-linenum (last-digits)
+ "Find closest line whose line number ends with digit LAST-DIGITS.
+If LAST-DIGITS is 16, line 16, line 116, and line 216 are candidates.
+Then if current line is 17, 16 is the final result."
(let* ((cur-line-num (evilnc--current-line-num))
- dst-line-num
(r 1)
- (l (length (number-to-string UNITS))))
+ (l (length (number-to-string last-digits))))
(while (> l 0)
(setq r (* r 10))
(setq l (- l 1)))
- (if (>= (mod cur-line-num r) UNITS)
- (setq UNITS (+ UNITS r)))
- (setq dst-line-num (+ cur-line-num (- UNITS (mod cur-line-num r))))))
-
-;; ==== below this line are public commands
+ (if (>= (mod cur-line-num r) last-digits)
+ (setq last-digits (+ last-digits r)))
+ (+ cur-line-num (- last-digits (mod cur-line-num r)))))
(defun evilnc-do-paragraphs (action num)
"Apply ACTION on NUM paragraphs."
@@ -514,22 +509,22 @@ If UNITS is 16, line 16, line 116, and line 216 are good
candidates."
(funcall action b e)))
;; prepare for the next paragraph
- (if (and rlt (< i num))
- (progn
- (evilnc--goto-line linenum)
+ (cond
+ ((and rlt (< i num))
+ (evilnc--goto-line linenum)
- ;; move to an empty line
- (forward-line)
+ ;; move to an empty line
+ (forward-line)
- ;; move to next non-empty line
- (re-search-forward "^[ \t]*[^ \t]" nil t)
+ ;; move to next non-empty line
+ (re-search-forward "^[ \t]*[^ \t]" nil t)
+ (if (<= (line-beginning-position) e)
+ (throw 'break i)))
- (if (<= (line-beginning-position) e)
- (throw 'break i)))
- (throw 'break i))
- (setq i (1+ i))))
+ (t
+ (throw 'break i)))
- ))
+ (setq i (1+ i))))))
;;;###autoload
(defun evilnc-comment-or-uncomment-paragraphs (&optional num)
@@ -561,16 +556,16 @@ Paragraphs are separated by empty lines."
))))
;;;###autoload
-(defun evilnc-quick-comment-or-uncomment-to-the-line (&optional units)
- "Comment/uncomment to line number by last digit(s) whose value is UNITS.
+(defun evilnc-quick-comment-or-uncomment-to-the-line (&optional last-digits)
+ "Comment/uncomment to line number by LAST DIGITS.
For example, you can use either \
\\<M-53>\\[evilnc-quick-comment-or-uncomment-to-the-line] \
or \\<M-3>\\[evilnc-quick-comment-or-uncomment-to-the-line] \
to comment to the line 6453"
(interactive "p")
- (let* ((dst-line-num (evilnc--find-dst-line-num units)))
- (evilnc-comment-or-uncomment-to-the-line dst-line-num)
- (evilnc--goto-line (+ 1 dst-line-num))))
+ (let* ((l (evilnc--find-destination-linenum last-digits)))
+ (evilnc-comment-or-uncomment-to-the-line l)
+ (evilnc--goto-line (+ 1 l))))
;;;###autoload
(defun evilnc-toggle-invert-comment-line-by-line ()
@@ -725,7 +720,7 @@ Then we operate the expanded region. NUM is ignored."
(defun evilnc-version ()
"The version number."
(interactive)
- (message "3.3.5"))
+ (message "3.3.6"))
(defvar evil-normal-state-map)
(defvar evil-visual-state-map)
diff --git a/pkg.sh b/pkg.sh
index d757997cd3..1d3cda1768 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=evil-nerd-commenter
-version=3.3.5
+version=3.3.6
pkg=$name-$version
mkdir $pkg
cp *.el $pkg
- [nongnu] elpa/evil-nerd-commenter 76fd0c5692 160/235: go to original column after copy and comment, (continued)
- [nongnu] elpa/evil-nerd-commenter 76fd0c5692 160/235: go to original column after copy and comment, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a32e12d16d 166/235: add evilnc-imenu-create-index-function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 41d4370921 165/235: Fixed: missing one char when comment end is (point-max), ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 912a967fe5 167/235: avoid duplicates in imenu comments, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 275c95c89c 172/235: Merge pull request #88 from mssdvd/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter c68ad3346f 170/235: Add an option to not define keybindings in Emacs mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 8089308aad 181/235: Merge pull request #94 from leungbk/vertical-motion, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 3089141dd2 183/235: Merge pull request #95 from leungbk/forward-line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 3cf6b1e746 174/235: can comment or uncomment jsx tag(s), ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 72d4aacd28 187/235: more unit test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 5cf8755264 191/235: clean code. more unit test. bump 3.3.6,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter f510a491c1 195/235: support js2-rjsx-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 9c87ea30fa 199/235: wording, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ce3530406c 201/235: fixed CI, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a5555ff02a 202/235: remove legacy code on old version of web-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter d664ad5af7 203/235: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter c9fa23ee7e 206/235: evil operator try to comment on whole lines if possible, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter fd2fba722e 205/235: clean keybinding setup code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 4a72fbd022 207/235: README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 76f07963c0 213/235: Update outdated link to emacswiki, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 747e346f11 212/235: Merge pull request #109 from hlissner/patch-1, ELPA Syncer, 2022/01/06