emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/javaimp b5d5a49229 1/2: Fixes for javaimp--get-sibling-


From: Filipp Gunbin
Subject: [elpa] externals/javaimp b5d5a49229 1/2: Fixes for javaimp--get-sibling-context
Date: Thu, 12 May 2022 14:37:17 -0400 (EDT)

branch: externals/javaimp
commit b5d5a4922958d555039a1be45904abed152fd1d3
Author: Filipp Gunbin <fgunbin@fastmail.fm>
Commit: Filipp Gunbin <fgunbin@fastmail.fm>

    Fixes for javaimp--get-sibling-context
    
    * javaimp-parse.el (javaimp-parse--decl-prefix): Move out of
    comment/string.
    * javaimp.el (javaimp--get-sibling-context): Fixes.
---
 javaimp-parse.el | 57 +++++++++++++++++++++++++++++++-------------------------
 javaimp.el       |  8 ++++++--
 2 files changed, 38 insertions(+), 27 deletions(-)

diff --git a/javaimp-parse.el b/javaimp-parse.el
index b82257b6a0..984dfa5579 100644
--- a/javaimp-parse.el
+++ b/javaimp-parse.el
@@ -259,31 +259,38 @@ point (but not farther than BOUND).  Matches inside 
comments /
 strings are skipped.  Return the beginning of the match (then the
 point is also at that position) or nil (then the point is left
 unchanged)."
-  ;; If we skip a previous scope (including unnamed initializers), or
-  ;; reach enclosing scope start, we'll fail the check in the below
-  ;; loop.  But a semicolon, which delimits statements, will just be
-  ;; skipped by scan-sexps, so find it and use as bound.  If it is in
-  ;; another scope, that's not a problem, for the same reasons as
-  ;; described above.
-  (let* ((prev-semi (save-excursion
-                      (javaimp-parse--rsb-keyword ";" bound t)))
-         (bound (when (or bound prev-semi)
-                  (apply #'max
-                         (delq nil
-                               (list bound
-                                     (and prev-semi (1+ prev-semi)))))))
-         pos res)
-    (with-syntax-table javaimp--arglist-syntax-table
-      (while (and (ignore-errors
-                    (setq pos (scan-sexps (point) -1)))
-                  (or (not bound) (>= pos bound))
-                  (or (member (char-after pos)
-                              '(?@ ?\(  ;annotation type / args
-                                   ?<)) ;generic type
-                      ;; keyword / identifier first char
-                      (= (syntax-class (syntax-after pos)) 2))) ;word
-        (goto-char (setq res pos))))
-    res))
+  (with-syntax-table javaimp-syntax-table
+    (let ((state (syntax-ppss))
+          prev-semi pos res)
+      ;; Move out of any comment/string
+      (when (nth 8 state)
+       (goto-char (nth 8 state))
+       (setq state (syntax-ppss)))
+      ;; If we skip a previous scope (including unnamed initializers),
+      ;; or reach enclosing scope start, we'll fail the check in the
+      ;; below loop.  But a semicolon, which delimits statements, will
+      ;; just be skipped by scan-sexps, so find it and use as bound.
+      ;; If it is in another scope, that's not a problem, for the same
+      ;; reasons as described above.
+      (setq prev-semi (save-excursion
+                        (javaimp-parse--rsb-keyword ";" bound t))
+            bound (when (or bound prev-semi)
+                    (apply #'max
+                           (delq nil
+                                 (list bound
+                                       (and prev-semi (1+ prev-semi)))))))
+      ;; Go back by sexps
+      (with-syntax-table javaimp--arglist-syntax-table
+        (while (and (ignore-errors
+                      (setq pos (scan-sexps (point) -1)))
+                    (or (not bound) (>= pos bound))
+                    (or (member (char-after pos)
+                                '(?@ ?\( ;annotation type / args
+                                     ?<)) ;generic type
+                        ;; keyword / identifier first char
+                        (= (syntax-class (syntax-after pos)) 2))) ;word
+          (goto-char (setq res pos))))
+      res)))
 
 
 ;;; Scopes
diff --git a/javaimp.el b/javaimp.el
index 5ea948d9f2..4bb6926fb6 100644
--- a/javaimp.el
+++ b/javaimp.el
@@ -1163,8 +1163,12 @@ PREV-INDEX gives the index of the method itself."
                                  (lambda (s)
                                    (>= (javaimp-scope-open-brace s) pos))
                                  siblings))
-                          (beg-decl (javaimp--beg-of-defun-decl pos))
-                          ((<= beg-decl pos)))
+                          (next-beg-decl
+                           (javaimp--beg-of-defun-decl
+                            (javaimp-scope-start next) parent-beg))
+                          (beg-decl
+                           (javaimp--beg-of-defun-decl pos parent-beg))
+                          ((= next-beg-decl beg-decl)))
                     ;; If we're inside next's declaration - behave as
                     ;; if we were inside its body, so it becomes our
                     ;; prev



reply via email to

[Prev in Thread] Current Thread [Next in Thread]