[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/javaimp 4e6ed4f: Fixes
From: |
Filipp Gunbin |
Subject: |
[elpa] externals/javaimp 4e6ed4f: Fixes |
Date: |
Tue, 10 Aug 2021 11:03:03 -0400 (EDT) |
branch: externals/javaimp
commit 4e6ed4fdcc92d41c5cba08bf229609493be79af9
Author: Filipp Gunbin <fgunbin@fastmail.fm>
Commit: Filipp Gunbin <fgunbin@fastmail.fm>
Fixes
---
javaimp-parse.el | 88 ++++++++++++++++++++++++--------------------------------
javaimp-tests.el | 12 ++++++--
javaimp.el | 1 +
3 files changed, 49 insertions(+), 52 deletions(-)
diff --git a/javaimp-parse.el b/javaimp-parse.el
index bb0fe24..cb26b81 100644
--- a/javaimp-parse.el
+++ b/javaimp-parse.el
@@ -25,7 +25,7 @@
javaimp--classlike-scope-types))
(defconst javaimp--parse-stmt-keywords
- '("if" "for" "while" "switch" "try" "catch" "finally"
+ '("if" "else" "for" "while" "do" "switch" "try" "catch" "finally"
"static" ; static initializer block
))
(defconst javaimp--parse-stmt-keyword-maxlen
@@ -36,18 +36,6 @@
considered as stale. Usually set by modification change hooks.
Should be set to (point-min) in major mode hook.")
-
-(defmacro javaimp--parse-with-syntax-table (syntax-table beg &rest body)
- (declare (debug t)
- (indent 2))
- (let ((begin (make-symbol "begin")))
- `(let ((,begin ,beg))
- (syntax-ppss-flush-cache ,begin)
- (unwind-protect
- (with-syntax-table ,syntax-table
- ,@body)
- (syntax-ppss-flush-cache ,begin)))))
-
(defsubst javaimp--parse-substr-before-< (str)
(let ((end (string-search "<" str)))
(if end
@@ -71,11 +59,10 @@ point is outside of any context initially."
"Parse arg list between BEG and END, of the form 'TYPE NAME,
...'. Return list of conses (TYPE . NAME). If ONLY-TYPE is
non-nil, then name parsing is skipped."
- (javaimp--parse-with-syntax-table javaimp--arglist-syntax-table beg
- (save-excursion
- (save-restriction
- (narrow-to-region beg end)
- (goto-char (point-max))
+ (let ((substr (buffer-substring-no-properties beg end)))
+ (with-temp-buffer
+ (insert substr)
+ (with-syntax-table javaimp--arglist-syntax-table
(ignore-errors
(let (res)
(while (progn
@@ -188,9 +175,9 @@ is unchanged."
(catch 'found
(while (javaimp--parse-rsb-keyword regexp bound t)
(let ((scan-pos (match-end 0)))
- (javaimp--parse-with-syntax-table javaimp--arglist-syntax-table
scan-pos
- ;; Skip over any number of lists, which may be
- ;; exceptions in "throws", or something like that
+ (with-syntax-table javaimp--arglist-syntax-table
+ ;; Skip over any number of lists, which may be exceptions
+ ;; in "throws", or something like that
(while (and scan-pos (<= scan-pos (nth 1 state)))
(if (ignore-errors
(= (scan-lists scan-pos 1 -1) ;As in
javaimp--parse-preceding
@@ -249,14 +236,14 @@ those may later become 'local-class' (see
`javaimp--parse-scopes')."
(or (and (= (char-before (1- (point))) ?-) ; ->
(= (char-before) ?>))
(looking-back (regexp-opt javaimp--parse-stmt-keywords 'words)
- (- (point) javaimp--parse-stmt-keyword-maxlen)
nil)))
- (make-javaimp-scope
- :type 'simple-statement
- :name (or (match-string 1)
- "lambda")
- :start (or (match-beginning 1)
- (- (point) 2))
- :open-brace (nth 1 state))))
+ (- (point) javaimp--parse-stmt-keyword-maxlen) nil))
+ (make-javaimp-scope
+ :type 'simple-statement
+ :name (or (match-string 1)
+ "lambda")
+ :start (or (match-beginning 1)
+ (- (point) 2))
+ :open-brace (nth 1 state)))))
(defun javaimp--parse-scope-anonymous-class (state)
"Attempts to parse 'anonymous-class' scope."
@@ -382,24 +369,26 @@ nil then goes all the way up. Examines and sets property
res))
(defun javaimp--parse-all-scopes ()
- "Entry point to the scope parsing. Parses scopes in this buffer
-which are after `javaimp--parse-dirty-pos', if it is non-nil.
-Resets this variable after parsing is done."
+ "Entry point to the scope parsing. Parses scopes in this
+buffer which are after `javaimp--parse-dirty-pos', if it is
+non-nil. Resets this variable after parsing is done."
+ ;; FIXME Set parse-sexp-.. vars, as well as syntax-table and
+ ;; syntax-ppss-table, in major mode function. Remove let-binding of
+ ;; inhibit-modification-hooks here.
(when javaimp--parse-dirty-pos
- (remove-text-properties javaimp--parse-dirty-pos (point-max)
- '(javaimp-parse-scope nil))
- (goto-char (point-max))
- ;; FIXME With major mode we could set these, as well as syntax
- ;; table, in mode function.
- (let ((parse-sexp-ignore-comments t)
- (parse-sexp-lookup-properties nil))
- (javaimp--parse-with-syntax-table javaimp-syntax-table (point-min)
- (while (javaimp--parse-rsb-keyword "{" javaimp--parse-dirty-pos t)
- (save-excursion
- (forward-char)
- ;; Set props at this brace and all the way up
- (javaimp--parse-scopes nil)))))
- (setq javaimp--parse-dirty-pos nil)))
+ (let ((inhibit-modification-hooks t))
+ (remove-text-properties javaimp--parse-dirty-pos (point-max)
+ '(javaimp-parse-scope nil))
+ (goto-char (point-max))
+ (let ((parse-sexp-ignore-comments t)
+ (parse-sexp-lookup-properties nil))
+ (with-syntax-table javaimp-syntax-table
+ (while (javaimp--parse-rsb-keyword "{" javaimp--parse-dirty-pos t)
+ (save-excursion
+ (forward-char)
+ ;; Set props at this brace and all the way up
+ (javaimp--parse-scopes nil)))))
+ (setq javaimp--parse-dirty-pos nil))))
@@ -407,10 +396,9 @@ Resets this variable after parsing is done."
(defun javaimp--parse-get-package ()
(goto-char (point-max))
- (javaimp--parse-with-syntax-table javaimp-syntax-table (point-min)
- (when (javaimp--parse-rsb-keyword
- "^[ \t]*package[ \t]+\\([^ \t;\n]+\\)[ \t]*;" nil t 1)
- (match-string 1))))
+ (when (javaimp--parse-rsb-keyword
+ "^[ \t]*package[ \t]+\\([^ \t;\n]+\\)[ \t]*;" nil t 1)
+ (match-string 1)))
(defun javaimp--parse-get-all-classlikes ()
(mapcar (lambda (scope)
diff --git a/javaimp-tests.el b/javaimp-tests.el
index 755e644..cee91a2 100644
--- a/javaimp-tests.el
+++ b/javaimp-tests.el
@@ -165,6 +165,7 @@ throws E1 {"
(dolist (item test-items)
(with-temp-buffer
(insert (nth 0 item))
+ (setq syntax-ppss-table javaimp-syntax-table)
(setq javaimp--parse-dirty-pos (point-min))
(let ((scopes (javaimp--parse-get-all-scopes)))
(should (= 1 (length scopes)))
@@ -181,12 +182,14 @@ throws E1 {"
/*
package commented.block;
*/")
+ (setq syntax-ppss-table javaimp-syntax-table)
(should (equal (javaimp--parse-get-package) "foo.bar.baz"))))
(ert-deftest javaimp-test--parse-get-all-classlikes ()
(with-temp-buffer
(insert-file-contents
(concat javaimp--basedir "testdata/test1-misc-classes.java"))
+ (setq syntax-ppss-table javaimp-syntax-table)
(setq javaimp--parse-dirty-pos (point-min))
(should (equal (javaimp--parse-get-all-classlikes)
'("Top"
@@ -203,6 +206,7 @@ package commented.block;
(with-temp-buffer
(insert-file-contents
(concat javaimp--basedir "testdata/test1-misc-classes.java"))
+ (setq syntax-ppss-table javaimp-syntax-table)
(let ((javaimp-format-method-name #'javaimp-format-method-name-types))
;;
;; parse full buffer
@@ -312,8 +316,10 @@ package commented.block;
(actual (with-temp-buffer
(insert-file-contents
(concat javaimp--basedir
"testdata/test1-misc-classes.java"))
+ (setq syntax-ppss-table javaimp-syntax-table)
(setq javaimp--parse-dirty-pos (point-min))
- (javaimp-imenu-create-index))))
+ (let ((imenu-use-markers nil))
+ (javaimp-imenu-create-index)))))
(javaimp-test--imenu-simplify-entries actual)
(should
(equal
@@ -387,8 +393,10 @@ package commented.block;
(with-temp-buffer
(insert-file-contents
(concat javaimp--basedir "testdata/test1-misc-classes.java"))
+ (setq syntax-ppss-table javaimp-syntax-table)
(setq javaimp--parse-dirty-pos (point-min))
- (javaimp-imenu-create-index)))
+ (let ((imenu-use-markers nil))
+ (javaimp-imenu-create-index))))
(expected javaimp-test--imenu-method-list-expected))
(should (= (length expected) (length actual)))
(dotimes (i (length expected))
diff --git a/javaimp.el b/javaimp.el
index 41fbf45..e6cae7a 100644
--- a/javaimp.el
+++ b/javaimp.el
@@ -612,6 +612,7 @@ Currently it requires some manual setup, something like
this in
the `java-mode-hook':
(setq imenu-create-index-function #'javaimp-imenu-create-index)
+ (setq syntax-ppss-table javaimp-syntax-table)
(setq javaimp--parse-dirty-pos (point-min))
(add-hook 'after-change-functions #'javaimp--parse-update-dirty-pos)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/javaimp 4e6ed4f: Fixes,
Filipp Gunbin <=