[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-nerd-commenter 3cf6b1e746 174/235: can comment or unc
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-nerd-commenter 3cf6b1e746 174/235: can comment or uncomment jsx tag(s) |
Date: |
Thu, 6 Jan 2022 02:59:45 -0500 (EST) |
branch: elpa/evil-nerd-commenter
commit 3cf6b1e746f4cab9cc6aa1ba93e14d8b54b0d291
Author: Chen Bin <chenbin.sh@gmail.com>
Commit: Chen Bin <chenbin.sh@gmail.com>
can comment or uncomment jsx tag(s)
---
README.org | 20 ++++++++-
evil-nerd-commenter-sdk.el | 2 -
evil-nerd-commenter.el | 100 ++++++++++++++++++++++++++++++++++++++++++---
pkg.sh | 2 +-
4 files changed, 113 insertions(+), 11 deletions(-)
diff --git a/README.org b/README.org
index 24bcf006bd..fb5c1be217 100644
--- a/README.org
+++ b/README.org
@@ -1,4 +1,4 @@
-* evil-nerd-commenter (v3.2.3)
+* evil-nerd-commenter (v3.3.0)
[[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]]
@@ -8,7 +8,7 @@ A [[http://www.vim.org/scripts/script.php?script_id=1218][Nerd
Commenter]] emula
I recommend using it with Evil though Evil is optional.
-Tested on Emacs 24.4, 24.5, 25.3
+Tested on Emacs 24.4, 24.5, 25.3, 26.1
* Why?
** A simple use case on the efficiency
@@ -106,6 +106,22 @@ The hotkey is ",cc" in evil-mode and =C-c c= in emacs
normal mode.
Comment lines and insert original lines into =kill-ring=.
*** evilnc-comment-or-uncomment-to-the-line
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).
+
+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
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.
*** evilnc-toggle-comment-empty-lines
Toggle the flag to comment/uncomment empty lines.
diff --git a/evil-nerd-commenter-sdk.el b/evil-nerd-commenter-sdk.el
index cbd6977754..1e85513be9 100644
--- a/evil-nerd-commenter-sdk.el
+++ b/evil-nerd-commenter-sdk.el
@@ -27,8 +27,6 @@
;;; Code:
-(require 'subr-x) ; required by `string-trim'
-
(defun evilnc--check-fonts (fonts-under-cursor fonts-list)
"Check whether FONTS-UNDER-CURSOR among FONTS-LIST."
(delq nil
diff --git a/evil-nerd-commenter.el b/evil-nerd-commenter.el
index c281665fd2..8c5b786890 100644
--- a/evil-nerd-commenter.el
+++ b/evil-nerd-commenter.el
@@ -4,7 +4,7 @@
;; Author: Chen Bin <chenbin.sh@gmail.com>
;; URL: http://github.com/redguardtoo/evil-nerd-commenter
-;; Version: 3.2.3
+;; Version: 3.3.0
;; Package-Requires: ((emacs "24.4"))
;; Keywords: commenter vim line evil
;;
@@ -81,6 +81,8 @@
;; "." 'evilnc-copy-and-comment-operator
;; "\\" 'evilnc-comment-operator)
;;
+;; `evilnc-comment-or-uncomment-html-tag' comment/uncomment html tag(s).
+;;
;; 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',
@@ -114,6 +116,9 @@
;;
;;; Code:
+(require 'subr-x) ; required by `string-trim'
+(require 'sgml-mode)
+(require 'newcomment)
(require 'evil-nerd-commenter-sdk)
(autoload 'count-lines "simple")
@@ -138,6 +143,12 @@ 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-end " */}"
+ "String to end Comment of HTML tag. JSX syntax is used by default.")
+
(defun evilnc--count-lines (beg end)
"Assume BEG is less than END."
(let* ((rlt (count-lines beg end)))
@@ -194,8 +205,8 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
((and (<= (line-beginning-position) (region-beginning))
(<= (region-end) (line-end-position)))
(cond
- ;; Well, looks current comment syntax is NOT fit for comment out a region.
- ;; So we also need hack the comment-start and comment-end
+ ;; current comment syntax is NOT fit to comment out a region.
+ ;; So we also need hack the `comment-start' and `comment-end'
((and (string= "" comment-end)
(member major-mode '(java-mode
javascript-mode
@@ -233,7 +244,7 @@ See
http://lists.gnu.org/archive/html/bug-gnu-emacs/2013-03/msg00891.html."
(let* ((b (region-beginning))
(e (region-end)))
;; Another work around for evil-visual-line bug:
- ;; In evil-mode, if we use hotkey V or `M-x evil-visual-line` to
select line,
+ ;; 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.
(if (and (> e b)
@@ -295,7 +306,7 @@ Code snippets embedded in Org-mode is identified and right
`major-mode' is used.
old-flag)
(when (and (eq major-mode 'org-mode)
(fboundp 'org-edit-src-find-region-and-lang))
- (setq info (org-edit-src-find-region-and-lang)))
+ (setq info (funcall 'org-edit-src-find-region-and-lang)))
(when info
(setq lang (or (cdr (assoc (nth 2 info) org-src-lang-modes))
@@ -666,7 +677,7 @@ Then we operate the expanded region. NUM is ignored."
(defun evilnc-version ()
"The version number."
(interactive)
- (message "3.2.3"))
+ (message "3.3.0"))
(defvar evil-normal-state-map)
(defvar evil-visual-state-map)
@@ -789,6 +800,83 @@ if NO-EMACS-KEYBINDINGS is t, we don't define keybindings
in EMACS mode."
(setq searching nil))))))
cands))
+(defun evilnc-html-comment-region (beg end)
+ "Comment region between BEG and END."
+ (save-excursion
+ (goto-char end)
+ (insert evilnc-html-comment-end)
+ (goto-char beg)
+ (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)
+ (save-excursion
+ (goto-char beg)
+ (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))
+ (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))))))
+
+(defun evilnc-is-html-tag-comment-p (beg)
+ "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))))
+
+;;;###autoload
+(defun evilnc-comment-or-uncomment-html-tag ()
+ "Comment or uncomment html tag(s).
+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
+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."
+ (interactive)
+ (let* (beg end beg-line-beg end-line-end)
+ (cond
+ ((region-active-p)
+ (setq beg (region-beginning))
+ (setq end (region-end))
+ (save-excursion
+ (goto-char beg)
+ (setq beg-line-beg (line-beginning-position))
+ (goto-char end)
+ (setq end-line-end (line-end-position))
+ (when (< beg-line-beg (line-beginning-position))
+ ;; it's multiple lines region
+ (goto-char beg-line-beg)
+ (setq beg (re-search-forward "^[ \t]*" end t))
+ (setq end end-line-end))))
+ (t
+ (save-excursion
+ (sgml-skip-tag-backward 1)
+ (setq beg (point))
+ (setq beg-line-beg (line-beginning-position))
+ (sgml-skip-tag-forward 1)
+ (setq end (point))
+ (setq end-line-end (line-end-position)))))
+
+ (cond
+ ((evilnc-is-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
+ ;; the whole tags is already selected
+ (evilnc-html-comment-region beg end)))))
+
;; Attempt to define the operator on first load.
;; Will only work if evil has been loaded
(eval-after-load 'evil
diff --git a/pkg.sh b/pkg.sh
index 2943618318..f0579adbeb 100755
--- a/pkg.sh
+++ b/pkg.sh
@@ -1,6 +1,6 @@
#!/bin/bash
name=evil-nerd-commenter
-version=3.2.3
+version=3.3.0
pkg=$name-$version
mkdir $pkg
cp *.el $pkg
- [nongnu] elpa/evil-nerd-commenter 29ed027b53 150/235: Remove error and some warnings, (continued)
- [nongnu] elpa/evil-nerd-commenter 29ed027b53 150/235: Remove error and some warnings, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter bb47704a10 155/235: Do not byte-compile evil-nerd-commenter-operator.el, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 76fd0c5692 160/235: go to original column after copy and comment, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a32e12d16d 166/235: add evilnc-imenu-create-index-function, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 41d4370921 165/235: Fixed: missing one char when comment end is (point-max), ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 912a967fe5 167/235: avoid duplicates in imenu comments, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 275c95c89c 172/235: Merge pull request #88 from mssdvd/master, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter c68ad3346f 170/235: Add an option to not define keybindings in Emacs mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 8089308aad 181/235: Merge pull request #94 from leungbk/vertical-motion, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 3089141dd2 183/235: Merge pull request #95 from leungbk/forward-line, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 3cf6b1e746 174/235: can comment or uncomment jsx tag(s),
ELPA Syncer <=
- [nongnu] elpa/evil-nerd-commenter 72d4aacd28 187/235: more unit test, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 5cf8755264 191/235: clean code. more unit test. bump 3.3.6, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter f510a491c1 195/235: support js2-rjsx-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 9c87ea30fa 199/235: wording, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter ce3530406c 201/235: fixed CI, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter a5555ff02a 202/235: remove legacy code on old version of web-mode, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter d664ad5af7 203/235: clean code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter c9fa23ee7e 206/235: evil operator try to comment on whole lines if possible, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter fd2fba722e 205/235: clean keybinding setup code, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-nerd-commenter 4a72fbd022 207/235: README, ELPA Syncer, 2022/01/06