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

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

[nongnu] elpa/evil-nerd-commenter 6ed6f9ea82 215/235: clean code


From: ELPA Syncer
Subject: [nongnu] elpa/evil-nerd-commenter 6ed6f9ea82 215/235: clean code
Date: Thu, 6 Jan 2022 02:59:49 -0500 (EST)

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

    clean code
---
 evil-nerd-commenter-operator.el | 64 ++++++++++++++++++++---------------------
 evil-nerd-commenter-sdk.el      | 42 +++++++++++++--------------
 evil-nerd-commenter-tests.el    |  2 +-
 evil-nerd-commenter.el          |  9 +++---
 4 files changed, 58 insertions(+), 59 deletions(-)

diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index 19117f5adf..8274a8877d 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -89,19 +89,19 @@
 Or expand the region to contain whole lines if it's not comment and certain 
conditions met."
 
   (cond
-   ((evilnc-is-pure-comment beg)
+   ((evilnc-pure-comment-p beg)
     (save-excursion
       (let* ((newbeg beg)
              (newend end))
 
         ;; expand the beginning
         (goto-char newbeg)
-        (while (and (>= (1- newbeg) (line-beginning-position)) 
(evilnc-is-pure-comment (1- newbeg)))
+        (while (and (>= (1- newbeg) (line-beginning-position)) 
(evilnc-pure-comment-p (1- newbeg)))
           (setq newbeg (1- newbeg)))
 
         ;; expand the end
         (goto-char newend)
-        (while (and (<= newend (line-end-position)) (evilnc-is-pure-comment 
newend))
+        (while (and (<= newend (line-end-position)) (evilnc-pure-comment-p 
newend))
           (setq newend (1+ newend)))
 
         (cons newbeg newend))))
@@ -174,33 +174,33 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
   (if (and (called-interactively-p 'any) (eq type 'line))
       (evil-first-non-blank)))
 
-(evil-define-operator evilnc-copy-and-comment-operator (beg end)
-  "Inserts an out commented copy of the text from BEG to END."
+(evil-define-operator evilnc-copy-and-comment-operator (begin end)
+  "Inserts an out commented copy of the text from BEGIN to END."
   :move-point (not evilnc-original-above-comment-when-copy-and-comment)
   (interactive "<r>")
   (evil-with-single-undo
-    (evil-yank-lines beg end nil 'lines)
+    (evil-yank-lines begin end nil 'lines)
     (cond
      (evilnc-original-above-comment-when-copy-and-comment
       (let* ((p (point)))
-        (comment-region beg end)
-        (goto-char beg)
+        (comment-region begin end)
+        (goto-char begin)
         (evil-paste-before 1)
         (goto-char p)))
      (t
       (goto-char end)
       (evil-paste-before 1)
       ;; actual comment operatio should happen at last
-      ;; or else beg end will be screwed up
-      (comment-region beg end)))))
+      ;; or else begin end will be screwed up
+      (comment-region begin end)))))
 
-(defun evilnc-is-one-line-comment (b e)
-  "Check whether text between B and E is one line comment."
+(defun evilnc-one-line-comment-p (begin end)
+  "Test if text between BEGIN and END is one line comment."
   (save-excursion
-    (goto-char b)
-    (and (<= (line-beginning-position) b)
-         ;; e is the upper limit great than (line-end-position)
-         (<= e (1+ (line-end-position))))))
+    (goto-char begin)
+    (and (<= (line-beginning-position) begin)
+         ;; end is the upper limit great than (line-end-position)
+         (<= end (1+ (line-end-position))))))
 
 (defun evilnc-get-comment-bounds ()
   "Return bounds like (cons beg end)."
@@ -209,11 +209,11 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
          (col 0)
          rlt)
     ;; decrease begin
-    (while (evilnc-is-comment (- b 1))
+    (while (evilnc-comment-p (- b 1))
       (setq b (- b 1)))
 
     ;; increase end
-    (while (evilnc-is-comment (+ e 1))
+    (while (evilnc-comment-p (+ e 1))
       (setq e (+ e 1)))
 
     ;; we could select extra spaces at the end of comment
@@ -228,13 +228,13 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
     (cond
      ((>= b e)
       (setq rlt nil))
-     ((evilnc-is-one-line-comment b e)
+     ((evilnc-one-line-comment-p b e)
       ;; contract begin
-      (while (not (evilnc-is-pure-comment b))
+      (while (not (evilnc-pure-comment-p b))
         (setq b (+ b 1)))
 
       ;; contract end
-      (while (not (evilnc-is-pure-comment e))
+      (while (not (evilnc-pure-comment-p e))
         (setq e (- e 1)))
 
       (if (< b e) (setq rlt (cons b (+ e 1)))))
@@ -265,11 +265,11 @@ Or expand the region to contain whole lines if it's not 
comment and certain cond
      (t
       ;; other languages we can safely use font face
       (while (and (> e b)
-                  (evilnc-is-comment-delimiter (- e 1)))
+                  (evilnc-comment-delimiter-p (- e 1)))
         (setq e (- e 1)))))
     e))
 
-(defun evilnc-is-c-style-comment (pos)
+(defun evilnc-c-style-comment-p (pos)
   "Is C style comment at POS?"
   (and (memq major-mode evilnc-c-style-comment-modes)
        (= (evilnc-get-char pos) ?/)
@@ -282,9 +282,9 @@ we are processing C like language."
   (let* ((col-min most-positive-fixnum)
          (col-max 0))
     (while (< beg end)
-      (when (and (not (evilnc-is-whitespace beg))
-                 (evilnc-is-pure-comment beg)
-                 (not (or (evilnc-is-comment-delimiter beg)
+      (when (and (not (evilnc-whitespace-p beg))
+                 (evilnc-pure-comment-p beg)
+                 (not (or (evilnc-comment-delimiter-p beg)
                           (and c-style
                                (memq (evilnc-get-char beg) '(?/ ?*))))))
         (let* ((col (evil-column beg)))
@@ -307,15 +307,15 @@ we are processing C like language."
       (setq b (car bounds))
       (setq e (cdr bounds))
       (cond
-       ((setq c-style (evilnc-is-c-style-comment b))
+       ((setq c-style (evilnc-c-style-comment-p b))
         (while (and (< b e)
-                    (or (evilnc-is-whitespace b)
-                        (evilnc-is-line-end b)
+                    (or (evilnc-whitespace-p b)
+                        (evilnc-line-end-p b)
                         (memq (evilnc-get-char b) '(?/ ?*))))
           (setq b (1+ b)))
         (while (and (< b e)
-                    (or (evilnc-is-whitespace e)
-                        (evilnc-is-line-end e)
+                    (or (evilnc-whitespace-p e)
+                        (evilnc-line-end-p e)
                         (memq (evilnc-get-char e) '(?/ ?*))))
           (setq e (1- e)))
         (setq e (1+ e))
@@ -335,7 +335,7 @@ we are processing C like language."
                   (goto-char (evilnc-adjusted-comment-end b 
(line-end-position)))
                   (point)))))
       (cond
-       ((evilnc-is-one-line-comment b e)
+       ((evilnc-one-line-comment-p b e)
         ;; keep move e to the end of comment
         (evil-range b ;; (if c-style (1+ e) e)
                     e))
diff --git a/evil-nerd-commenter-sdk.el b/evil-nerd-commenter-sdk.el
index f7836ca232..e9e89f7b1d 100644
--- a/evil-nerd-commenter-sdk.el
+++ b/evil-nerd-commenter-sdk.el
@@ -33,7 +33,7 @@
                     (member f fonts-list))
                 fonts-under-cursor)))
 
-(defun evilnc-web-mode-is-comment (&optional pos)
+(defun evilnc-web-mode-comment-p (&optional pos)
   "Check whether the code at POS is comment.
 `web-mode' removes its API, so create our own."
   (unless pos (setq pos (point)))
@@ -46,23 +46,29 @@
   (let* ((fontfaces (if (> pos 0) (get-text-property pos 'face))))
     (if (listp fontfaces) fontfaces (list fontfaces))))
 
-(defun evilnc-is-pure-comment (pos)
+(defun evilnc-pure-comment-p (pos)
   "Check character at POS is pure comment."
   (or (and (eq major-mode 'web-mode)
-           (evilnc-web-mode-is-comment pos))
+           (evilnc-web-mode-comment-p pos))
       (evilnc--check-fonts (evilnc-fonts-at-point pos)
                            '(font-lock-comment-face
                              font-lock-comment-delimiter-face))))
 
-(defun evilnc-is-whitespace (pos)
-  "Character at POS is white space."
-  (member (evilnc-get-char pos) '(32 9)))
+(defmacro evilnc-get-char (position)
+  "Get character at POSITION."
+  `(save-excursion
+     (goto-char ,position)
+     (following-char)))
 
-(defun evilnc-is-line-end (pos)
-  "Character at POS is line end."
-  (member (evilnc-get-char pos) '(10 11)))
+(defmacro evilnc-whitespace-p (position)
+  "Character at POSITION is white space."
+  `(member (evilnc-get-char ,position) '(32 9)))
 
-(defun evilnc-is-comment (pos)
+(defmacro evilnc-line-end-p (position)
+  "Character at POSITION is line end."
+  `(member (evilnc-get-char ,position) '(10 11)))
+
+(defun evilnc-comment-p (pos)
   "Check whether the code at POS is comment by comparing font face.
 Please note the white spaces out of comment is treated as comment,
 or else we can't select multiple lines comment."
@@ -72,19 +78,13 @@ or else we can't select multiple lines comment."
    ((not (evilnc-fonts-at-point pos))
     ;; character under cursor is SPACE or TAB
     ;; and out of comment
-    (evilnc-is-whitespace pos))
+    (evilnc-whitespace-p pos))
    (t
-    (evilnc-is-pure-comment pos))))
-
-(defun evilnc-get-char (pos)
-  "Get character at POS."
-  (save-excursion
-    (goto-char pos)
-    (following-char)))
+    (evilnc-pure-comment-p pos))))
 
-(defun evilnc-is-comment-delimiter (pos)
-  "Is character at POS a comment delimiter?"
-  (let* ((fontfaces (evilnc-fonts-at-point pos)))
+(defun evilnc-comment-delimiter-p (position)
+  "Is character at POSITION a comment delimiter?"
+  (let* ((fontfaces (evilnc-fonts-at-point position)))
     (and fontfaces
          (evilnc--check-fonts fontfaces
                               '(font-lock-comment-delimiter-face)))))
diff --git a/evil-nerd-commenter-tests.el b/evil-nerd-commenter-tests.el
index 9af5b8f4db..bdd47138b8 100644
--- a/evil-nerd-commenter-tests.el
+++ b/evil-nerd-commenter-tests.el
@@ -72,7 +72,7 @@
       (js-mode)
       (goto-char (point-min))
       (evilnc-copy-and-comment-lines 2)
-      (should (not (evilnc-is-pure-comment (point))))
+      (should (not (evilnc-pure-comment-p (point))))
       (setq lines (evilnc-get-lines (point-min) (point-max)))
       (should (string= (nth 0 lines) "// hello"))
       (should (string= (nth 1 lines) "// world"))
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 2f1ebc709f..9316e17a33 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -451,8 +451,7 @@ Code snippets embedded in Org-mode is identified and right 
`major-mode' is used.
     is-comment))
 
 (defun evilnc--web-mode-comment-or-uncomment (beg end)
-  "Comment/uncomment line by line from BEG to END.
-DO-COMMENT decides we comment or uncomment."
+  "Comment/uncomment line by line from BEG to END."
   ;; end will change when you comment line by line
   (let* (tmp)
     ;; make sure beg <= end
@@ -813,7 +812,7 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings 
in EMACS mode."
          (t
           (setq beg (1+ beg))))
 
-        (when (and searching (evilnc-is-comment beg))
+        (when (and searching (evilnc-comment-p beg))
           (setq linenum (line-number-at-pos beg) )
           (cond
            ((string= comment-end "")
@@ -877,7 +876,7 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings 
in EMACS mode."
         (goto-char (- mark-start-pos len-comment-start))
         (delete-char len-comment-start)))))
 
-(defun evilnc-is-html-tag-comment-p (beg)
+(defun evilnc-html-tag-comment-p (beg)
   "Html tag comment at position BEG?"
   (save-excursion
     (goto-char beg)
@@ -921,7 +920,7 @@ This command is not dependent on any 3rd party package."
         (setq end-line-end (line-end-position)))))
 
     (cond
-     ((evilnc-is-html-tag-comment-p beg)
+     ((evilnc-html-tag-comment-p beg)
       ;; make sure all tags plus comment marks are selected
       (evilnc-html-uncomment-region beg-line-beg end-line-end))
      (t



reply via email to

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