[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter 151ac57475 178/235: fix bugs on commen
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter 151ac57475 178/235: fix bugs on commenting html paragraph |
Date: |
Thu, 6 Jan 2022 02:59:46 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit 151ac5747539eaac5562b93c94f738d6001ab0c7
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
fix bugs on commenting html paragraph
---
README.org | 27 +++++++++++-------
evil-nerd-commenter.el | 76 ++++++++++++++++++++++----------------------------
pkg.sh | 2 +-
3 files changed, 51 insertions(+), 54 deletions(-)
diff --git a/README.org b/README.org
index 2441f1304d..02b0276cfe 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (v3.3.2)
+* evil-nerd-commenter (v3.3.3)
[[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]]
@@ -130,20 +130,27 @@ Paragraph is text separated by empty lines.
Sample to combine =evilnc-comment-or-uncomment-html-paragraphs= and
=evilnc-comment-or-uncomment-paragraphs=:
#+begin_src elisp
+(defun my-current-line-html-p (paragraph-region)
+ (let* ((line (buffer-substring-no-properties (line-beginning-position)
+ (line-end-position)))
+ (re (format "^[ \t]*\\(%s\\)?[ \t]*</?[a-zA-Z]+"
+ (regexp-quote evilnc-html-comment-start))))
+ ;; current paragraph does contain html tag
+ (if (and (>= (point) (car paragraph-region))
+ (string-match-p re line))
+ t)))
+
(defun my-evilnc-comment-or-uncomment-paragraphs (&optional num)
"Comment or uncomment NUM paragraphs which might contain html tags."
(interactive "p")
(unless (featurep 'evil-nerd-commenter) (require 'evil-nerd-commenter))
(let* ((paragraph-region (evilnc--get-one-paragraph-region))
- (html-p (save-excursion
- (sgml-skip-tag-backward 1)
- (let* ((line (buffer-substring-no-properties
(line-beginning-position)
-
(line-end-position))))
- ;; current paragraph does contain html tag
- (if (and (>= (point) (car paragraph-region))
- (string-match-p (format "^[ \t]*\\(%s\\)?[
\t]*<[a-zA-Z]+"
- (regexp-quote
evilnc-html-comment-start)) line))
- t)))))
+ (html-p (or (save-excursion
+ (sgml-skip-tag-backward 1)
+ (my-current-line-html-p paragraph-region))
+ (save-excursion
+ (sgml-skip-tag-forward 1)
+ (my-current-line-html-p paragraph-region)))))
(if html-p (evilnc-comment-or-uncomment-html-paragraphs num)
(evilnc-comment-or-uncomment-paragraphs num))))
#+end_src
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 3148c0ccf3..09f792bbe6 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -1,10 +1,10 @@
;;; evil-nerd-commenter.el --- Comment/uncomment lines efficiently. Like Nerd
Commenter in Vim
-;; Copyright (C) 2013-2017, Chen Bin
+;; Copyright (C) 2013-2019, Chen Bin
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.3.2
+;; Version: 3.3.3
;; Package-Requires: ((emacs "24.4"))
;; Keywords: commenter vim line evil
;;
@@ -85,25 +85,6 @@
;; `evilnc-comment-or-uncomment-html-paragraphs' comment/uncomment paragraphs
;; containing html tags.
;;
-;; Sample to combine `evilnc-comment-or-uncomment-html-paragraphs' and
-;; `evilnc-comment-or-uncomment-paragraphs':
-;; (defun my-evilnc-comment-or-uncomment-paragraphs (&optional num)
-;; "Comment or uncomment NUM paragraphs which might contain html tags."
-;; (interactive "p")
-;; (unless (featurep 'evil-nerd-commenter) (require 'evil-nerd-commenter))
-;; (let* ((paragraph-region (evilnc--get-one-paragraph-region))
-;; (html-p (save-excursion
-;; (sgml-skip-tag-backward 1)
-;; (let* ((line (buffer-substring-no-properties
(line-beginning-position)
-;;
(line-end-position))))
-;; ;; current paragraph does contain html tag
-;; (if (and (>= (point) (car paragraph-region))
-;; (string-match-p (format "^[ \t]*\\(%s\\)?[
\t]*<[a-zA-Z]+"
-;; (regexp-quote
evilnc-html-comment-start)) line))
-;; t)))))
-;; (if html-p (evilnc-comment-or-uncomment-html-paragraphs num)
-;; (evilnc-comment-or-uncomment-paragraphs num))))
-;;
;; You can setup `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',
@@ -464,6 +445,12 @@ DO-COMMENT decides we comment or uncomment."
(beginning-of-line)
(1+ (count-lines 1 (point))))))
+(defun evilnc--get-line-num (position)
+ "Get line number at POSITION."
+ (save-excursion
+ (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.
@@ -486,19 +473,25 @@ If UNITS is 16, line 16, line 116, and line 216 are good
candidates."
(let* ((i 0)
rlt
(b (point-max))
- (e 0))
+ (e 0)
+ linenum)
(catch 'break
(while (< i num)
- (setq i (1+ i))
- (setq rlt (evilnc--get-one-paragraph-region))
- (setq b (if (< (nth 0 rlt) b) (nth 0 rlt) b))
- (setq e (if (> (nth 1 rlt) e) (nth 1 rlt) e))
+ (when (setq rlt (evilnc--get-one-paragraph-region))
+ (setq b (nth 0 rlt))
+ (setq e (nth 1 rlt))
+ (setq linenum (evilnc--get-line-num e)))
+
+ ;; Original algorithm select all paragraph and comment once
+ ;; New algorithm comment paragraph by paragraph
+ (when (<= b e)
+ (save-excursion
+ (funcall action b e)))
;; prepare for the next paragraph
(if (and rlt (< i num))
(progn
- ;; e should be the end of last non-empty line
- (goto-char e)
+ (evilnc--goto-line linenum)
;; move to an empty line
(forward-line)
@@ -508,11 +501,10 @@ If UNITS is 16, line 16, line 116, and line 216 are good
candidates."
(if (<= (line-beginning-position) e)
(throw 'break i)))
- (throw 'break i))))
+ (throw 'break i))
+ (setq i (1+ i))))
- (when (<= b e)
- (save-excursion
- (funcall action b e)))))
+ ))
;;;###autoload
(defun evilnc-comment-or-uncomment-paragraphs (&optional num)
@@ -708,7 +700,7 @@ Then we operate the expanded region. NUM is ignored."
(defun evilnc-version ()
"The version number."
(interactive)
- (message "3.3.2"))
+ (message "3.3.3"))
(defvar evil-normal-state-map)
(defvar evil-visual-state-map)
@@ -915,16 +907,14 @@ different syntax."
A paragraph is a continuation non-empty lines.
Paragraphs are separated by empty lines."
(interactive "p")
- (save-excursion
- (evilnc-do-paragraphs
- (lambda (b e)
- ;; {{ select region from b to e
- (set-mark b)
- (goto-char e)
- (activate-mark)
- ;; }}
- (evilnc-comment-or-uncomment-html-tag))
- num)))
+ (evilnc-do-paragraphs
+ (lambda (b e)
+ ;; {{ make sure tag is focused
+ (goto-char b)
+ (sgml-skip-tag-forward 1)
+ ;; }}
+ (evilnc-comment-or-uncomment-html-tag))
+ num))
;; Attempt to define the operator on first load.
;; Will only work if evil has been loaded
diff --git a/pkg.sh b/pkg.sh
index edc2ee76db..61eda08a7f 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=evil-nerd-commenter
-version=3.3.2
+version=3.3.3
pkg=$name-$version
mkdir $pkg
cp *.el $pkg
- [nongnu] elpa/evil-nerd-commenter 41910491e7 101/235: updated README, (continued)
- [nongnu] elpa/evil-nerd-commenter 41910491e7 101/235: updated README, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter e7f57427be 109/235: Fixes #45, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 966435bf25 129/235: warn on comment operations NOT implemented in web-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 981c80bb53 131/235: can comment the line mixed with html and snippet, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter d61c6629b4 132/235: updated doc, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 01a98a20c5 144/235: users choose the style they prefer when copy and comment, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 92bee71aa6 159/235: fixed typo, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ef4d595e18 180/235: Modify evilnc--operation-on-lines-or-region for visual line numbers., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 44b6fd8e09 173/235: add missing require statement, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 4bf2a84ba5 189/235: prefer org-src-lang-modes over language property of org src, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 151ac57475 178/235: fix bugs on commenting html paragraph,
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter 4f83773eee 190/235: add test for org-land-major-mode needing org-src-lang-modes, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter acc0f75cde 192/235: comment in org-src-block will not collapse node, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 27d8fe0bf0 194/235: fixed CI, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 7132693a4c 196/235: fixed test warning, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f9d2da93de 204/235: inside org src block cursor move after comment, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 3febe822a1 211/235: Replace string feature with symbol, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter b9207c5fa2 219/235: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 8b0d9654ec 230/235: fix&doc of text object; unit test for evil, ELPA Syncer, 2022/01/06