[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 8569ba6 47/49: Merge pull request #387 from futurist/maste
From: |
Dmitry Gutov |
Subject: |
[elpa] master 8569ba6 47/49: Merge pull request #387 from futurist/master |
Date: |
Mon, 16 Jan 2017 15:35:50 +0000 (UTC) |
branch: master
commit 8569ba6734184b869b4ac42e79231d195ea4dba2
Merge: 90e37cd d3dd406
Author: Dmitry Gutov <address@hidden>
Commit: GitHub <address@hidden>
Merge pull request #387 from futurist/master
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 85fff86..7fa637b 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..935cdeb
--- /dev/null
+++ b/tests/consume.el
@@ -0,0 +1,59 @@
+;;; tests/consume.el --- Some tests for js2-mode.
+
+;; Copyright (C) 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 d3dd406 46/49: fix: copyright year of tests/comsume.el, (continued)
- [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
- [elpa] master 5855a45 22/49: Merge pull request #380 from JulianKniephoff/fix-dead-doc-link-js2-include-jslint-globals, Dmitry Gutov, 2017/01/16
- [elpa] master 94b2721 31/49: Merge pull request #385 from mishoo/master, Dmitry Gutov, 2017/01/16
- [elpa] master 91e722a 27/49: Merge pull request #381 from mgiles/template-pos, Dmitry Gutov, 2017/01/16
- [elpa] master 3106e3c 37/49: Fix arrow expression function's length, Dmitry Gutov, 2017/01/16
- [elpa] master 6f2d51b 41/49: Fix the breakage from the previous commit, Dmitry Gutov, 2017/01/16
- [elpa] master 03c679e 48/49: Bump the version, Dmitry Gutov, 2017/01/16
- [elpa] master 8569ba6 47/49: Merge pull request #387 from futurist/master,
Dmitry Gutov <=
- [elpa] master 80ebdee 42/49: Rename js2--collect-declared-symbols to js2--collect-target-symbols, Dmitry Gutov, 2017/01/16
- [elpa] master b575f17 19/49: Optimize a call to `append`, Dmitry Gutov, 2017/01/16
- [elpa] master e77fcd4 36/49: Refactor ‘js2-define-destruct-symbols’ on top of ‘js2--collect-declared-symbols’, Dmitry Gutov, 2017/01/16