[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master dad7d09 32/49: feat: add js2-comments-between func
From: |
Dmitry Gutov |
Subject: |
[elpa] master dad7d09 32/49: feat: add js2-comments-between func |
Date: |
Mon, 16 Jan 2017 15:35:49 +0000 (UTC) |
branch: master
commit dad7d094b792bb08e8c80f0bae053b3d2d3db71b
Author: 1111hui <address@hidden>
Commit: 1111hui <address@hidden>
feat: add js2-comments-between func
---
Makefile | 4 ++--
js2-mode.el | 15 +++++++++++++-
tests/consume.el | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index b181ed8..bad22c9 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,6 @@ clean:
-rm -f $(OBJS)
test:
- ${EMACS} $(BATCHFLAGS) -L . -l js2-mode.el -l js2-old-indent.el -l
tests/parser.el\
- -l tests/indent.el -l tests/externs.el -l tests/json-path.el \
+ ${EMACS} $(BATCHFLAGS) -L . -l js2-mode.el -l js2-old-indent.el -l
tests/parser.el \
+ -l tests/indent.el -l tests/externs.el -l tests/json-path.el -l
tests/consume.el \
-l tests/navigation.el -f ert-run-tests-batch-and-exit
diff --git a/js2-mode.el b/js2-mode.el
index 12a5c6a..c2b72f8 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -4962,7 +4962,20 @@ Function returns nil if POS was not in any comment node."
end (+ beg (js2-node-len comment)))
(if (and (>= x beg)
(<= x end))
- (throw 'done comment))))))
+ (throw 'done comment))))))
+
+(defun js2-comments-between (start end comments-list)
+ "Return comment nodes between START and END, nil if not found.
+START and END are absolute positions in current buffer.
+COMMENTS-LIST is the comments list to check."
+ (let (comments c-start c-end)
+ (nreverse
+ (dolist (comment comments-list comments)
+ (setq c-start (js2-node-abs-pos comment)
+ c-end (1- (+ c-start (js2-node-len comment))))
+ (unless (or (< c-end start)
+ (> c-start end))
+ (push comment comments))))))
(defun js2-mode-find-parent-fn (node)
"Find function enclosing NODE.
diff --git a/tests/consume.el b/tests/consume.el
new file mode 100644
index 0000000..6012699
--- /dev/null
+++ b/tests/consume.el
@@ -0,0 +1,59 @@
+;;; tests/consume.el --- Some tests for js2-mode.
+
+;; Copyright (C) 2009, 2011-2016 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'js2-mode)
+
+(defun js2-mode--and-parse ()
+ (js2-mode)
+ (js2-reparse))
+
+;;; Comments
+
+(ert-deftest js2-comments-between ()
+ (with-temp-buffer
+ (insert "0\n//\n[0,/* */1]")
+ (js2-mode--and-parse)
+ (let ((comments-list (js2-ast-root-comments js2-mode-ast))
+ comments)
+ (setq comments (js2-comments-between 1 2 comments-list))
+ (should (null comments))
+ ;; comment head between region
+ (setq comments (js2-comments-between 1 3 comments-list))
+ (should (= (length comments) 1))
+ ;; comment body between region
+ (setq comments (js2-comments-between 4 5 comments-list))
+ (should (= (length comments) 1))
+ ;; comment tail between region
+ (setq comments (js2-comments-between 5 6 comments-list))
+ (should (= (length comments) 1))
+ (setq comments (js2-comments-between 6 6 comments-list))
+ (should (null comments))
+ (setq comments (js2-comments-between 10 12 comments-list))
+ (should (= (length comments) 1))
+ ;; multiple comments between
+ (setq comments (js2-comments-between 5 15 comments-list))
+ (should (= (length comments) 2))
+ ;; pass comments-list when no AST available
+ (setq js2-mode-ast nil)
+ (setq comments (js2-comments-between 8 9 comments))
+ (should (= (length comments) 1))
+ )))
- [elpa] master df06798 23/49: Merge pull request #378 from JulianKniephoff/include-externs-locally, (continued)
- [elpa] master df06798 23/49: Merge pull request #378 from JulianKniephoff/include-externs-locally, Dmitry Gutov, 2017/01/16
- [elpa] master 2a79649 33/49: Fix indentation after regexp in js2-old-indent.el, Dmitry Gutov, 2017/01/16
- [elpa] master f450de0 34/49: Handle destructuring assignments when classifying variables, Dmitry Gutov, 2017/01/16
- [elpa] master 90e37cd 45/49: Merge pull request #397 from lelit/issue393, Dmitry Gutov, 2017/01/16
- [elpa] master 9b63a13 16/49: Special methods should allow keywords as names, Dmitry Gutov, 2017/01/16
- [elpa] master 672e2da 07/49: js2-parse-mul-expr: Parse the right operand as exponentiation too, Dmitry Gutov, 2017/01/16
- [elpa] master a91e357 40/49: Create a separate scope for switch statements, Dmitry Gutov, 2017/01/16
- [elpa] master 4d35da5 30/49: Fix the fix (error detection), Dmitry Gutov, 2017/01/16
- [elpa] master 31a2399 44/49: Mostly cosmetic, split js2--classify-variables in three simpler functions, Dmitry Gutov, 2017/01/16
- [elpa] master 3725fcf 35/49: Handle other cases of destructuring assignments/initializations, Dmitry Gutov, 2017/01/16
- [elpa] master dad7d09 32/49: feat: add js2-comments-between func,
Dmitry Gutov <=
- [elpa] master 523b3cb 38/49: Add a STRICT parameter to js2--collect-declared-symbols, Dmitry Gutov, 2017/01/16
- [elpa] master 1f12517 10/49: Merge pull request #353 from kaushalmodi/js2-jsx-mode-docstring-fix, Dmitry Gutov, 2017/01/16
- [elpa] master 454b242 20/49: Update NEWS.md, Dmitry Gutov, 2017/01/16
- [elpa] master 2d0dc5e 43/49: Cosmetic, reformat to stay within the preferred 80 columns limit, Dmitry Gutov, 2017/01/16
- [elpa] master ff072bf 49/49: Merge commit '03c679eb9914d58d7d9b7afc2036c482a9a01236' from js2-mode, Dmitry Gutov, 2017/01/16
- [elpa] master fbe58dc 18/49: Compute externs on demand, Dmitry Gutov, 2017/01/16
- [elpa] master d3dd406 46/49: fix: copyright year of tests/comsume.el, Dmitry Gutov, 2017/01/16
- [elpa] master cdbdca4 39/49: Rewrite js2--classify-variables, focusing only on name nodes, Dmitry Gutov, 2017/01/16
- [elpa] master 82bbd97 25/49: Move it up, Dmitry Gutov, 2017/01/16
- [elpa] master c303773 21/49: Fix dead link in the documentation, Dmitry Gutov, 2017/01/16