[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter 16561277ae 200/235: comment html tag i
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter 16561277ae 200/235: comment html tag in more web templates |
Date: |
Thu, 6 Jan 2022 02:59:48 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit 16561277aeed22b0297bf39c8b77a5eec801d96a
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
comment html tag in more web templates
---
README.org | 14 ++-----
evil-nerd-commenter-tests.el | 34 +++++++++++----
evil-nerd-commenter.el | 99 ++++++++++++++++++++++++++++++++++----------
pkg.sh | 2 +-
4 files changed, 107 insertions(+), 42 deletions(-)
diff --git a/README.org b/README.org
index 6a84f459ad..2581526d19 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (v3.3.8)
+* evil-nerd-commenter
[[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]]
@@ -109,8 +109,7 @@ Comment lines and insert original lines into =kill-ring=.
Comment to the specified line.
*** evilnc-comment-or-uncomment-html-tag
Comment or uncomment current html tag or selected region.
-JSX from ReactJS is the default syntax to comment tags.
-Customize =evilnc-html-comment-start= and =evilnc-html-comment-end= for
different syntax.
+
Please note you don't need force the whole line selection (pressing =V=) in
=evil-mode=. This command is smart to select whole lines if needed.
Comment or uncomment html tag(s).
@@ -120,22 +119,17 @@ In this case, only one tag is selected.
If user manually selects region, the region could cross multiple sibling tags
and automatically expands to include complete tags. So user only need press =v=
key in =evil-mode= to select multiple tags.
-JSX from ReactJS like ={/* ... */}= is the default comment syntax.
-
-Customize =evilnc-html-comment-end= and =evilnc-html-comment-end= to use
different syntax.
-
Or you can use =evilnc-comment-or-uncomment-html-paragraphs= to
comment/uncomment paragraphs containing html tags.
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))))
+ (regexp-quote (evilnc-html-comment-start)))))
;; current paragraph does contain html tag
(if (and (>= (point) (car paragraph-region))
(string-match-p re line))
@@ -283,7 +277,7 @@ Most popular programming languages are supported.
- Make sure Evil installed
- Press ",,a("
** Choose the style of copy and comment
-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=,
+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
* Credits
diff --git a/evil-nerd-commenter-tests.el b/evil-nerd-commenter-tests.el
index bd9b130f73..b442a94913 100644
--- a/evil-nerd-commenter-tests.el
+++ b/evil-nerd-commenter-tests.el
@@ -79,27 +79,45 @@
(should (string= (nth 2 lines) "hello"))
(should (string= (nth 3 lines) "world")))))
+(defun evilnc-uncomment-to-original-html ()
+ ;; move the cursor to the middle of html tag and uncomment
+ (goto-char (point-min))
+ (forward-line 1)
+ ;; uncomment whole tag
+ (evilnc-comment-or-uncomment-html-tag)
+ ;; should be same as original html
+ (let* ((lines (evilnc-get-lines (point-min) (point-max))))
+ (should (string= (nth 0 lines) "<div class=\"box\">"))
+ (should (string= (nth 1 lines) "hello world"))
+ (should (string= (nth 2 lines) "</div>"))))
+
(ert-deftest evilnc-test-comment-html-tag ()
(let* (lines)
(with-temp-buffer
(insert "<div class=\"box\">\nhello world\n</div>")
+
+
+ ;; comment tag in html file
(html-mode)
- ;; comment tag
(goto-char (point-min))
(evilnc-comment-or-uncomment-html-tag)
(setq lines (evilnc-get-lines (point-min) (point-max)))
- (should (string= (nth 0 lines) "{/* <div class=\"box\">"))
+ (should (string= (nth 0 lines) "<!-- <div class=\"box\">"))
(should (string= (nth 1 lines) "hello world"))
- (should (string= (nth 2 lines) "</div> */}"))
- ;; move the cursor to the middle of html tag
+ (should (string= (nth 2 lines) "</div> -->"))
+
+ (evilnc-uncomment-to-original-html)
+
+ ;; comment tag in html file
+ (js-mode)
(goto-char (point-min))
- (forward-line 1)
- ;; uncomment whole tag
(evilnc-comment-or-uncomment-html-tag)
(setq lines (evilnc-get-lines (point-min) (point-max)))
- (should (string= (nth 0 lines) "<div class=\"box\">"))
+ (should (string= (nth 0 lines) "{/* <div class=\"box\">"))
(should (string= (nth 1 lines) "hello world"))
- (should (string= (nth 2 lines) "</div>")))))
+ (should (string= (nth 2 lines) "</div> */}"))
+
+ (evilnc-uncomment-to-original-html))))
(ert-deftest evilnc-test-org-src-block ()
(let* (lang-f)
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index 6fc9624e30..c7df6e77d6 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -3,7 +3,7 @@
;; Author: Chen Bin <chenbin DOT sh AT gmail.com>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.3.8
+;; Version: 3.3.9
;; Package-Requires: ((emacs "24.4"))
;; Keywords: convenience evil
;;
@@ -144,6 +144,7 @@ Please note it has NOT effect on evil text object!")
js2-jsx-mode
rust-mode
c++-mode
+ c-mode
objc-mode)
"Major modes which has C++ like comment syntax.")
@@ -158,11 +159,65 @@ Please note it has NOT effect on evil text object!")
(defvar evilnc-min-comment-length-for-imenu 8
"Minimum length of comment to display in imenu.")
-(defvar evilnc-html-comment-start "{/* "
- "String to start comment of HTML tag. JSX syntax is used by default.")
+(defvar evilnc-html-comment-delimiters
+ '((evilnc-html-jsx-p "{/* " " */}")
+ ("js-mode" "{/* " " */}")
+ (("web-mode" "html-mode") "<!-- " " -->"))
+ "List of html tag comment rules.
+The 1st item of each rule is the major mode(s) to match curernt `major-mode'.
+Current `major-mode' could equal or derive from the listed major mode(s).
+The 2nd and 3rd item is the comment start and comment end.")
+
+(defun evilnc-html-jsx-p ()
+ "Test if current file is jsx."
+ (and buffer-file-name
+ (string-match-p "\.jsx?$" buffer-file-name)))
+
+(defun evilnc-html-match-comment-delimiters-p (target-mode)
+ "Use `major-mode' to match TARGET-MODE which could be:
+One major mode.
+List of major modes.
+A function to return t or nil."
+ (let* (rlt)
+ (cond
+ ((functionp target-mode)
+ (setq rlt (funcall target-mode)))
+ ((stringp target-mode)
+ ;; convert name of `major-mode' to symbol
+ (when (or (eq major-mode (intern target-mode))
+ (derived-mode-p (intern target-mode)))
+ (setq rlt t)))
+ ((listp target-mode)
+ (while (and (not rlt) target-mode)
+ (unless (setq rlt (evilnc-html-match-comment-delimiters-p (nth 0
target-mode)))
+ ;; continue looping
+ (setq target-mode (cdr target-mode))))))
+ rlt))
-(defvar evilnc-html-comment-end " */}"
- "String to end Comment of HTML tag. JSX syntax is used by default.")
+(defun evilnc-html-find-comment-delimiter ()
+ "Found comment delimiter from `evilnc-html-find-comment-delimiter'."
+ (let* (found
+ (delimiters evilnc-html-comment-delimiters)
+ rule)
+ (while (and (not found) delimiters)
+ (setq rule (car delimiters))
+ (cond
+ ((evilnc-html-match-comment-delimiters-p (nth 0 rule))
+ (setq found rule))
+ (t
+ ;; keep looping
+ (setq delimiters (cdr delimiters)))))
+ found))
+
+(defun evilnc-html-comment-start ()
+ "Return start of html comment."
+ (let* ((s (evilnc-html-find-comment-delimiter)))
+ (if s (nth 1 s) "<!-- ")))
+
+(defun evilnc-html-comment-end ()
+ "Return end of html comment."
+ (let* ((s (evilnc-html-find-comment-delimiter)))
+ (if s (nth 2 s) " -->")))
(defun evilnc--count-lines (beg end)
"Assume BEG is less than END."
@@ -321,7 +376,7 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
"Return src-block info in org. It's like (beg end language)."
(cond
;; Emacs 24.4+
- ((and (fboundp 'org-edit-src-find-region-and-lang))
+ ((fboundp 'org-edit-src-find-region-and-lang)
(let* ((info (org-edit-src-find-region-and-lang)))
(list (nth 0 info)
(1+ (nth 1 info))
@@ -587,7 +642,7 @@ Paragraphs are separated by empty lines."
;;;###autoload
(defun evilnc-quick-comment-or-uncomment-to-the-line (&optional last-digits)
- "Comment/uncomment to line number by 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] \
@@ -752,7 +807,7 @@ Then we operate the expanded region. NUM is ignored."
(defun evilnc-version ()
"The version number."
(interactive)
- (message "3.3.8"))
+ (message "3.3.9"))
(defvar evil-normal-state-map)
(defvar evil-visual-state-map)
@@ -880,23 +935,25 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings
in EMACS mode."
"Comment region between BEG and END."
(save-excursion
(goto-char end)
- (insert evilnc-html-comment-end)
+ (insert (evilnc-html-comment-end))
(goto-char beg)
- (insert evilnc-html-comment-start)))
+ (insert (evilnc-html-comment-start))))
(defun evilnc-html-uncomment-region (beg end)
"Uncomment HTML tag between BEG and END."
- (let* (mark-start-pos mark-end-pos)
+ (let* (mark-start-pos
+ mark-end-pos
+ (len-comment-start (length (evilnc-html-comment-start))))
(save-excursion
(goto-char beg)
- (setq mark-start-pos (search-forward evilnc-html-comment-start end t))
+ (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) beg 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 (length evilnc-html-comment-start)))
- (delete-char (length evilnc-html-comment-start))))))
+ (delete-char (length (evilnc-html-comment-end)))
+ (goto-char (- mark-start-pos len-comment-start))
+ (delete-char len-comment-start)))))
(defun evilnc-is-html-tag-comment-p (beg)
"Html tag comment at position BEG?"
@@ -904,7 +961,7 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings
in EMACS mode."
(goto-char beg)
(let* ((line (buffer-substring-no-properties (line-beginning-position)
(line-end-position)))
- (re (concat "^[ \t]*" (regexp-quote evilnc-html-comment-start))))
+ (re (concat "^[ \t]*" (regexp-quote (evilnc-html-comment-start)))))
(string-match-p re line))))
;;;###autoload
@@ -913,13 +970,9 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings
in EMACS mode."
If no region is selected, current tag under focus is automatically selected.
In this case, only one tag is selected.
-If user manually selects region, the region could cross multiple sibling tags
+If users manually select region, the region could cross multiple sibling tags
and automatically expands to include complete tags.
-So user only need press \"v\" key in \"evil-mode\" to select multiple tags.
-
-JSX from ReactJS like \"{/* ... */}\" is the default comment syntax.
-Customize `evilnc-html-comment-end' and `evilnc-html-comment-end' to used
-different syntax."
+Users can press \"v\" key in evil mode to select multiple tags."
(interactive)
(let* (beg end beg-line-beg end-line-end)
(cond
diff --git a/pkg.sh b/pkg.sh
index 6c9ee7802b..c2a64cb8d1 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=evil-nerd-commenter
-version=3.3.8
+version=3.3.9
pkg=$name-$version
mkdir $pkg
cp *.el $pkg
- [nongnu] elpa/evil-nerd-commenter 498ac2dbbd 154/235: Merge pull request #75 from duianto/patch-1, (continued)
- [nongnu] elpa/evil-nerd-commenter 498ac2dbbd 154/235: Merge pull request #75 from duianto/patch-1, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 0a46b91120 157/235: more precise inner comment text object, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 6a05c86bdf 164/235: Merge pull request #80 from duianto/fix-doc-string-typo-length, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 8f6fafcce9 168/235: better algorithm to extract comments in imenu, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter d1a5c9cd63 188/235: org v9.1 changed api to get language of src_block, ELPA Syncer, 2022/01/06
- [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 <=
- [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, 2022/01/06
- [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