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

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

[elpa] scratch/javaimp-wip 544e9d428c: *** empty log message ***


From: Filipp Gunbin
Subject: [elpa] scratch/javaimp-wip 544e9d428c: *** empty log message ***
Date: Fri, 15 Apr 2022 12:50:48 -0400 (EDT)

branch: scratch/javaimp-wip
commit 544e9d428c9283cfb0649e8a3894b9760655dd9d
Author: Filipp Gunbin <fgunbin@okko.tv>
Commit: Filipp Gunbin <fgunbin@okko.tv>

    *** empty log message ***
---
 javaimp-parse.el |  4 ++--
 javaimp-util.el  |  9 +++++++++
 javaimp.el       | 56 +++++++++++++++++++++++++++++++-------------------------
 3 files changed, 42 insertions(+), 27 deletions(-)

diff --git a/javaimp-parse.el b/javaimp-parse.el
index 89b296b2b5..fb1d6bc6b7 100644
--- a/javaimp-parse.el
+++ b/javaimp-parse.el
@@ -429,8 +429,8 @@ is intended to use already set properties."
   (with-syntax-table javaimp-syntax-table
     (let ((state (syntax-ppss)))
       ;; Move out of any comment/string
-      (when (nth 8 ppss)
-       (goto-char (nth 8 ppss))
+      (when (nth 8 state)
+       (goto-char (nth 8 state))
        (setq state (syntax-ppss)))
       ;; Go up until we get something
       (catch 'found
diff --git a/javaimp-util.el b/javaimp-util.el
index df9913a9ef..3faa8fad57 100644
--- a/javaimp-util.el
+++ b/javaimp-util.el
@@ -160,6 +160,15 @@ left."
       (javaimp-test-scope-type s
         leaf-types javaimp--classlike-scope-types))))
 
+(defun javaimp--scope-same-parent-pred (parent)
+  (if parent
+      (lambda (s)
+        (and (javaimp-scope-parent s)
+             (= (javaimp-scope-open-brace (javaimp-scope-parent s))
+                (javaimp-scope-open-brace parent))))
+    (lambda (s)
+      (not (javaimp-scope-parent s)))))
+
 
 ;; Tree
 
diff --git a/javaimp.el b/javaimp.el
index 082773d7b4..5ccc37f847 100644
--- a/javaimp.el
+++ b/javaimp.el
@@ -573,7 +573,7 @@ If there's no such directive, then the last resort is just
   "Return fully-qualified names of all class-like scopes in the
 current buffer."
   (let ((package (javaimp--parse-get-package))
-        (scopes (javaimp--parse-get-all-scopes (javaimp--defun-scope-pred t)))
+        (scopes (javaimp--parse-get-all-scopes (javaimp--defun-scope-pred t))))
     (mapcar (lambda (class)
               (if package
                   (concat package "." class)
@@ -884,10 +884,10 @@ opening brace."
     (when (> arg 0) (setq arg (1- arg)))
     (let (found)
       (when-let* ((tmp (javaimp--get-sibling-defuns))
-                  (enc-idx (car tmp))
+                  (prev-idx (or (car tmp) -1))
                   (siblings (cdr tmp))
                   (target-idx
-                   (let ((val (- enc-idx arg)))
+                   (let ((val (- prev-idx arg)))
                      (cond ((< val 0)
                             0)
                            ((>= val (length siblings))
@@ -905,36 +905,42 @@ opening brace."
   )
 
 (defun javaimp--get-sibling-defuns ()
-  "Return list of the form (ENCLOSING-INDEX . SIBLINGS), where
-SIBLINGS is a list of all sibling defun scopes.  ENCLOSING-INDEX,
-if non-nil, is an index of the enclosing scope in this list.  If
-it's nil then we're between top-level defuns."
+  "Return list of the form (PREV-INDEX . SIBLINGS), where SIBLINGS
+is a list of all sibling defun scopes.  PREV-INDEX is the index
+of the \"previous\" (relative to point) scope in this list, or
+nil."
   (save-excursion
     (save-restriction
       (widen)
-      (let* ((defun-pred (javaimp--defun-scope-pred))
+      (let* ((pos (point))
+             (defun-pred (javaimp--defun-scope-pred))
              (enc (javaimp--parse-get-enclosing-scope defun-pred))
              (sibling-pred
-              (if (and enc (javaimp-scope-parent enc))
-                  ;; scopes with same parent
-                  (lambda (s)
-                    (and (javaimp-scope-parent s)
-                         (= (javaimp-scope-open-brace (javaimp-scope-parent s))
-                            (javaimp-scope-open-brace (javaimp-scope-parent 
enc)))))
-                ;; we're in a top-level scope or outside it, and
-                ;; need other top-level scopes
-                (lambda (s)
-                  (not (javaimp-scope-parent s)))))
+              (if (and enc (eq (javaimp-scope-type enc) 'method))
+                  ;; We're inside a method, and need to look at
+                  ;; sibling methods within same parent (it's ok for
+                  ;; parent to be nil)
+                  (javaimp--scope-same-parent-pred (javaimp-scope-parent enc))
+                ;; We're either inside a type (but not within its
+                ;; methods), or just at top-level.  Look at defuns
+                ;; whose parent is enc.
+                (javaimp--scope-same-parent-pred enc)))
              (siblings (javaimp--parse-get-all-scopes
                         (lambda (s)
                           (and (funcall defun-pred s)
-                               (funcall sibling-pred s))))))
-        (cons (and enc
-                   (seq-position
-                    siblings enc
-                    (lambda (s1 s2)
-                      (= (javaimp-scope-open-brace s1)
-                         (javaimp-scope-open-brace s2)))))
+                               (funcall sibling-pred s)))))
+             (prev
+              (if (and enc (eq (javaimp-scope-type enc) 'method))
+                  enc
+                ;; try to find previous defun
+                (seq-find (lambda (s)
+                            (< (javaimp-scope-open-brace s) pos))
+                          (reverse siblings)))))
+        (cons (and prev
+                   (seq-position siblings prev
+                                 (lambda (s1 s2)
+                                   (= (javaimp-scope-open-brace s1)
+                                      (javaimp-scope-open-brace s2)))))
               siblings)))))
 
 



reply via email to

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