[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter 2133167e06 232/235: clean code
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter 2133167e06 232/235: clean code |
Date: |
Thu, 6 Jan 2022 02:59:51 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit 2133167e0699f44fe37830839362e2e6793bce88
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
clean code
---
README.org | 6 +-
evil-nerd-commenter-operator.el | 3 +-
evil-nerd-commenter-sdk.el | 27 ++++----
evil-nerd-commenter.el | 135 +++++++++++++++++++---------------------
4 files changed, 84 insertions(+), 87 deletions(-)
diff --git a/README.org b/README.org
index ab29900c06..67ca9ed11f 100644
--- a/README.org
+++ b/README.org
@@ -224,7 +224,7 @@ if(flag==true){ doSomething(); }
#+END_SRC
The first line is production code. The second line is your debug code. You
want to invert the comment status of these two lines (for example, comment out
first line and uncomment the second line) for debug purpose.
-All you need to is =M-x evilnc-toggle-invert-comment-line-by-line= then =C-u 2
evilnc-comment-or-uncomment-lines=. The first command turn on some flag, so the
behaviour of (un)commenting is different.
+All you need to is =M-x evilnc-toggle-invert-comment-line-by-line= then =C-u 2
evilnc-comment-or-uncomment-lines=. The first command turn on some flag, so the
behavior of (un)commenting is different.
* Evil usage
If you use [[http://emacswiki.org/emacs/Evil][Evil]], you can use
[[http://vimdoc.sourceforge.net/htmldoc/motion.html#text-objects][text objects
and motions]]. But if you only *deals with lines*, I suggest using
=evilnc-comment-or-uncomment-lines= instead.
** commenter text object "c"
@@ -297,10 +297,10 @@ Most popular programming languages are supported.
You can set up =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=,
- Place the commented out text above original text
- Or place the original text above commented out text
-** Customise comment style
+** Customize comment style
Most commands call =evilnc-comment-or-uncomment-region-function=.
-You can modify this variable to customise the comment style.
+You can modify this variable to customize the comment style.
#+begin_src elisp
(with-eval-after-load 'evil-nerd-commenter
diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index 452f0ce14d..6dbd022fdc 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -85,7 +85,8 @@
(setq evilnc-temporary-goal-column 0)))
(defun evilnc-expand-to-whole-comment-or-line (start end)
- "Expand the comment region defined by START and END so all comment is
included.
+ "Expand the comment region defined by START and END.
+Make sure all comment is included.
Or expand the region to contain whole lines."
(cond
diff --git a/evil-nerd-commenter-sdk.el b/evil-nerd-commenter-sdk.el
index 5ba7fcfdea..70e5f9b13d 100644
--- a/evil-nerd-commenter-sdk.el
+++ b/evil-nerd-commenter-sdk.el
@@ -25,6 +25,8 @@
;;; Code:
+(defvar evil-state)
+
(defun evilnc--check-fonts (fonts-under-cursor fonts-list)
"Check whether FONTS-UNDER-CURSOR among FONTS-LIST."
(delq nil
@@ -87,9 +89,9 @@ or else we can't select multiple lines comment."
(evilnc--check-fonts fontfaces
'(font-lock-comment-delimiter-face)))))
-(defun evilnc-sdk-inside-one-line-p (beg end)
- "Test BEG and END is inside one line."
- (and (<= (line-beginning-position) beg)
+(defun evilnc-sdk-inside-one-line-p (start end)
+ "Test START and END is inside one line."
+ (and (<= (line-beginning-position) start)
(<= end (line-end-position))))
(defun evilnc-sdk-cur-line (&optional end)
@@ -97,24 +99,27 @@ or else we can't select multiple lines comment."
(buffer-substring-no-properties (line-beginning-position)
(or end (line-end-position))))
-(defun evilnc-sdk-expand-to-contain-whole-lines (beg end)
- "Expand region between BEG and END so the region contain whole lines.
+(defun evilnc-sdk-expand-to-contain-whole-lines (start end)
+ "Expand region between START and END so the region contain whole lines.
Return new range like '(region_begin . region_end)."
(save-excursion
;; Another work around for evil-visual-line bug:
;; In `evil-mode', if we use hotkey V or `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.
- (when (and (> end beg)
- (save-excursion (goto-char end) (= end
(line-beginning-position)))
- (boundp 'evil-state) (eq evil-state 'visual))
+ (when (and (> end start)
+ (save-excursion
+ (goto-char end)
+ (= end (line-beginning-position)))
+ (boundp 'evil-state)
+ (eq evil-state 'visual))
(setq end (1- end)))
- (goto-char beg)
- (setq beg (line-beginning-position))
+ (goto-char start)
+ (setq start (line-beginning-position))
(goto-char end)
(setq end (line-end-position)))
- (cons beg end))
+ (cons start end))
(provide 'evil-nerd-commenter-sdk)
;;; evil-nerd-commenter-sdk.el ends here
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 3108464c37..33e9fac3dd 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -123,10 +123,10 @@
;; You can modify this variable to customize the comment style,
;;
;; (with-eval-after-load 'evil-nerd-commenter
-;; (defun my-comment-or-uncomment-region (beg end)
+;; (defun my-comment-or-uncomment-region (start end)
;; (let* ((comment-start "aaa")
;; (comment-end "bbb"))
-;; (evilnc-comment-or-uncomment-region-internal beg end)))
+;; (evilnc-comment-or-uncomment-region-internal start end)))
;; (setq evilnc-comment-or-uncomment-region-function
;; 'my-comment-or-uncomment-region))
;;
@@ -240,15 +240,6 @@ A function to return t or nil."
(let* ((s (evilnc-html-find-comment-delimiter)))
(if s (nth 2 s) " -->")))
-(defun evilnc--count-lines (beg end)
- "Assume BEG is less than END."
- (let* ((rlt (count-lines beg end)))
- (save-excursion
- (goto-char beg)
- (if (> beg (line-beginning-position))
- (setq rlt (1+ rlt))))
- rlt))
-
(defun evilnc--goto-line (line-num)
"Shamelessly copied from `goto-line'. Goto line with LINE-NUM."
(save-restriction
@@ -359,8 +350,8 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
(point-max))))))
(list b e)))
-(defun evilnc--invert-comment (beg end)
- "Scan the region from BEG to END line by line, invert its comment status."
+(defun evilnc--invert-comment (start end)
+ "Scan the region from START to END line by line, invert its comment status."
(let* (done b e)
(save-excursion
(goto-char end)
@@ -373,7 +364,7 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
(forward-line -1)
(if (or (= (line-beginning-position) b)
- (< (line-end-position) beg))
+ (< (line-end-position) start))
(setq done t))))))
(defvar org-src-lang-modes)
@@ -381,7 +372,7 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
(declare-function outline-up-heading "outline")
(defun evilnc--org-src-block-info ()
- "Return src-block info in org. It's like (beg end language)."
+ "Return src-block info in org. It's like (start end language)."
(cond
;; Emacs 24.4+
((fboundp 'org-edit-src-find-region-and-lang)
@@ -419,8 +410,8 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
(t
nil))))
-(defun evilnc--working-on-region (beg end fn)
- "Region from BEG to END is applied with operation FN.
+(defun evilnc--working-on-region (start end fn)
+ "Region from START to END is applied with operation FN.
Code snippets embedded in Org-mode is identified and right `major-mode' is
used."
(let* ((old-pos (point))
(info (if (eq major-mode 'org-mode) (evilnc--org-src-block-info)))
@@ -431,7 +422,7 @@ Code snippets embedded in Org-mode is identified and right
`major-mode' is used.
(lang-f
(let* ((src-beg (nth 0 info))
(src-end (nth 1 info))
- (comment-beg-in-buf (1+ (- beg src-beg)))
+ (comment-beg-in-buf (1+ (- start src-beg)))
(comment-end-in-buf (1+ (- end src-beg)))
(new-pos (1+ (- old-pos src-beg)))
(old-code (buffer-substring-no-properties src-beg src-end))
@@ -457,9 +448,9 @@ Code snippets embedded in Org-mode is identified and right
`major-mode' is used.
(t
(cond
(evilnc-invert-comment-line-by-line
- (evilnc--invert-comment beg end))
+ (evilnc--invert-comment start end))
(t
- (funcall fn beg end)))))))
+ (funcall fn start end)))))))
(declare-function web-mode-comment-or-uncomment "ext:web-mode")
(defvar web-mode-engine)
@@ -475,39 +466,39 @@ Code snippets embedded in Org-mode is identified and
right `major-mode' is used.
comment-operation))
is-comment))
-(defun evilnc--web-mode-comment-or-uncomment (beg end)
- "Comment/uncomment line by line from BEG to END."
+(defun evilnc--web-mode-comment-or-uncomment (start end)
+ "Comment/uncomment line by line from START to END."
;; end will change when you comment line by line
(let* (tmp)
- ;; make sure beg <= end
- (when (> beg end)
- (setq tmp beg)
- (setq beg end)
+ ;; make sure start <= end
+ (when (> start end)
+ (setq tmp start)
+ (setq start end)
(setq end tmp))
(save-excursion
- (push-mark beg t t)
+ (push-mark start t t)
(goto-char end)
(web-mode-comment-or-uncomment))))
;;;###autoload
-(defun evilnc-comment-or-uncomment-region-internal (beg end)
- "Comment or uncomment region from BEG to END."
+(defun evilnc-comment-or-uncomment-region-internal (start end)
+ "Comment or uncomment region from START to END."
(cond
((eq major-mode 'web-mode)
;; elixir is not supported in web-mode for now
(unless (fboundp 'web-mode-comment-elixir-block)
(defun web-mode-comment-elixir-block (pos)
- (web-mode-comment-erb-block pos))
+ (funcall 'web-mode-comment-erb-block pos))
(defun web-mode-uncomment-elixir-block (pos)
- (web-mode-uncomment-erb-block pos)))
- (evilnc--web-mode-comment-or-uncomment beg end))
+ (funcall 'web-mode-uncomment-erb-block pos)))
+ (evilnc--web-mode-comment-or-uncomment start end))
(t
- (evilnc--working-on-region beg end 'comment-or-uncomment-region))))
+ (evilnc--working-on-region start end 'comment-or-uncomment-region))))
;;;###autoload
-(defun evilnc-comment-or-uncomment-region (beg end)
- "Comment or uncomment region from BEG to END."
- (funcall evilnc-comment-or-uncomment-region-function beg end))
+(defun evilnc-comment-or-uncomment-region (start end)
+ "Comment or uncomment region from START to END."
+ (funcall evilnc-comment-or-uncomment-region-function start end))
(defun evilnc--current-line-num ()
"Get current line number."
@@ -708,21 +699,21 @@ Then we operate the expanded region. NUM is ignored."
(let* ((original-column (current-column)))
(evilnc--operation-on-lines-or-region
- '(lambda (beg end)
+ '(lambda (start end)
(evilnc--fix-buggy-major-modes)
- (let* ((str (buffer-substring-no-properties beg end)))
+ (let* ((str (buffer-substring-no-properties start end)))
(cond
(evilnc-original-above-comment-when-copy-and-comment
(let* ((p (point)))
- (comment-region beg end)
- (goto-char beg)
+ (comment-region start end)
+ (goto-char start)
(insert-before-markers (concat str "\n"))
(goto-char p)))
(t
(goto-char end)
(newline 1)
(insert-before-markers str)
- (comment-region beg end)))))
+ (comment-region start end)))))
num)
;; Go to original column after evilnc-copy-and-comment-lines
;; @see https://github.com/redguardtoo/evil-nerd-commenter/issues/79
@@ -746,10 +737,10 @@ Then we operate the expanded region. NUM is ignored."
(setq num (- 0 num)))
(evilnc--operation-on-lines-or-region
- '(lambda (beg end)
+ '(lambda (start end)
(evilnc--fix-buggy-major-modes)
- (kill-new (buffer-substring-no-properties beg end))
- (comment-region beg end))
+ (kill-new (buffer-substring-no-properties start end))
+ (comment-region start end))
num))
;; {{ for non-evil user only
@@ -849,37 +840,36 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings
in EMACS mode."
;;;###autoload
(defun evilnc-imenu-create-index-function ()
"Imenu function find comments."
- (let* (beg
- end
- linenum
- str
- (searching t)
- m
- cands)
+ (let* (start end linenum str searching cands)
(save-excursion
(goto-char (point-min))
;; learn this skill from etags-select
;; use simple string search to speed up searching
+ (setq searching t)
(while searching
;; C/C++ might use "/* " as comment-start
- (setq beg (search-forward (string-trim comment-start) (point-max) t))
+ (setq start (search-forward (string-trim comment-start) (point-max) t))
;; OK, it's comment
(cond
- ((not beg)
+ ((not start)
(setq searching nil))
+
(t
- (setq beg (1+ beg))))
+ (setq start (1+ start))))
+
+ (when (and searching (evilnc-comment-p start))
+ (setq linenum (line-number-at-pos start) )
- (when (and searching (evilnc-comment-p beg))
- (setq linenum (line-number-at-pos beg) )
(cond
((string= comment-end "")
(setq end (line-end-position)))
+
(t
(setq end (search-forward comment-end (point-max) t))))
+
(cond
- ((and end (> end beg))
- (setq str (string-trim (buffer-substring-no-properties beg end)))
+ ((and end (> end start))
+ (setq str (string-trim (buffer-substring-no-properties start end)))
;; no empty line
(setq str (replace-regexp-in-string "[\r\n]+" "\n" str))
;; could be multi-lines comment
@@ -902,44 +892,45 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings
in EMACS mode."
(when (and (not (string-match-p "^[ \t\n\r]*$" str))
(> (length str) evilnc-min-comment-length-for-imenu))
- (setq m (make-marker))
- (set-marker m beg)
- (push (cons (evilnc-frame-wide-string (format "%d:%s" linenum
str)) m)
- cands))
+ (let* ((m (make-marker)))
+ (set-marker m start)
+ (push (cons (evilnc-frame-wide-string (format "%d:%s" linenum
str)) m)
+ cands)))
(goto-char (min (1+ end) (point-max))))
+
(t
(setq searching nil))))))
(nreverse cands)))
-(defun evilnc-html-comment-region (beg end)
- "Comment region between BEG and END."
+(defun evilnc-html-comment-region (start end)
+ "Comment region between START and END."
(save-excursion
(goto-char end)
(insert (evilnc-html-comment-end))
- (goto-char beg)
+ (goto-char start)
(insert (evilnc-html-comment-start))))
-(defun evilnc-html-uncomment-region (beg end)
- "Uncomment HTML tag between BEG and END."
+(defun evilnc-html-uncomment-region (start end)
+ "Uncomment HTML tag between START and END."
(let* (mark-start-pos
mark-end-pos
(len-comment-start (length (evilnc-html-comment-start))))
(save-excursion
- (goto-char beg)
+ (goto-char start)
(setq mark-start-pos (search-forward (evilnc-html-comment-start) end t))
(goto-char end)
- (setq mark-end-pos (search-backward (evilnc-html-comment-end) beg t))
+ (setq mark-end-pos (search-backward (evilnc-html-comment-end) start t))
(when (and mark-start-pos mark-end-pos)
(goto-char mark-end-pos)
(delete-char (length (evilnc-html-comment-end)))
(goto-char (- mark-start-pos len-comment-start))
(delete-char len-comment-start)))))
-(defun evilnc-html-tag-comment-p (beg)
- "Html tag comment at position BEG?"
+(defun evilnc-html-tag-comment-p (start)
+ "Test if html tag comment is at position START position."
(save-excursion
- (goto-char beg)
+ (goto-char start)
(string-match-p (concat "^[ \t]*" (regexp-quote
(evilnc-html-comment-start)))
(evilnc-sdk-cur-line))))
- [nongnu] elpa/evil-nerd-commenter cf1f57921d 175/235: can comment html paragraphs, (continued)
- [nongnu] elpa/evil-nerd-commenter cf1f57921d 175/235: can comment html paragraphs, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a4ef4ec548 176/235: document on comment paragraph, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 29990d314c 177/235: enable evil text object usage by default, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a6d492b819 193/235: support inline comment for rust-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 7e48e61207 197/235: Make evilnc-comment-and-copy-operator create only one undo entry, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 16561277ae 200/235: comment html tag in more web templates, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter cc8b254723 216/235: optimize performance, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 2730820b9c 224/235: fixed: evil-copy-and-comment-operator does not copy in visual-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter e32519bc75 231/235: remove travis setup, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 6bc41317ba 233/235: doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 2133167e06 232/235: clean code,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter 63baf2d1c7 235/235: Merge pull request #124 from rafauke/feature/treat-tsx-as-jsx, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 29513d6c3b 004/235: now can comment to specified line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 1a93b64203 016/235: typo in README.org, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 6e560d6956 024/235: no evil-leader, upgraded to 0.0.9, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 8a3b13ed0b 018/235: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 59586d7e0b 027/235: updated doc on comment paragraphs, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter d279beb83d 035/235: Updated description, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter c9d325bb3f 037/235: Moved operator to evil section, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 223d99372d 039/235: Added check for comment operator being bound, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 229ed115d2 041/235: Streamlined evil section, ELPA Syncer, 2022/01/06