branch: elpa/evil-nerd-commenter
commit 87734b9c7fcd047f73a072b9d03ec05f786eeb03
Author: Chen Bin <[email protected]>
Commit: Chen Bin <[email protected]>
clean code
---
evil-nerd-commenter-operator.el | 2 +-
evil-nerd-commenter-sdk.el | 5 +++++
evil-nerd-commenter.el | 8 +++-----
3 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/evil-nerd-commenter-operator.el b/evil-nerd-commenter-operator.el
index 3e37928480..067c5c6f20 100644
--- a/evil-nerd-commenter-operator.el
+++ b/evil-nerd-commenter-operator.el
@@ -220,7 +220,7 @@ Or expand the region to contain whole lines if it's not
comment and certain cond
;; so we need go back
(let* ((str (save-excursion
(goto-char e)
- (buffer-substring-no-properties (line-beginning-position)
e)))
+ (evilnc-sdk-cur-line e)))
(empty-line-p (string-match "^[ \t]*$" str)))
(if empty-line-p
;; empty line plus line feed
diff --git a/evil-nerd-commenter-sdk.el b/evil-nerd-commenter-sdk.el
index 696ea3c663..21b43998b2 100644
--- a/evil-nerd-commenter-sdk.el
+++ b/evil-nerd-commenter-sdk.el
@@ -92,6 +92,11 @@ or else we can't select multiple lines comment."
(and (<= (line-beginning-position) beg)
(<= end (line-end-position))))
+(defun evilnc-sdk-cur-line (&optional end)
+ "String from line beginning to END or line end."
+ (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.
Return new range like '(region_begin . region_end)."
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 9316e17a33..d160ac2953 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -622,7 +622,7 @@ CORRECT comment syntax will be used for
C++/Java/Javascript."
;; donot move the cursor
;; support negative number
(cond
- ((and (= 1 num) (string-match "^[ \t]*$" (buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
+ ((and (= 1 num) (string-match "^[ \t]*$" (evilnc-sdk-cur-line)))
;; comment on current empty line
(comment-dwim nil))
(t
@@ -880,10 +880,8 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings
in EMACS mode."
"Html tag comment at position BEG?"
(save-excursion
(goto-char beg)
- (let* ((line (buffer-substring-no-properties (line-beginning-position)
- (line-end-position)))
- (re (concat "^[ \t]*" (regexp-quote (evilnc-html-comment-start)))))
- (string-match-p re line))))
+ (string-match-p (concat "^[ \t]*" (regexp-quote
(evilnc-html-comment-start)))
+ (evilnc-sdk-cur-line))))
;;;###autoload
(defun evilnc-comment-or-uncomment-html-tag ()