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

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

[elpa] externals/javaimp 784e5f0527 2/2: Fix javaimp-beginning-of-defun


From: Filipp Gunbin
Subject: [elpa] externals/javaimp 784e5f0527 2/2: Fix javaimp-beginning-of-defun when inside arg list in declaration
Date: Mon, 25 Jul 2022 15:26:48 -0400 (EDT)

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

    Fix javaimp-beginning-of-defun when inside arg list in declaration
---
 javaimp.el | 74 ++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 41 insertions(+), 33 deletions(-)

diff --git a/javaimp.el b/javaimp.el
index 94737cf47b..8c2a4460e5 100644
--- a/javaimp.el
+++ b/javaimp.el
@@ -877,12 +877,10 @@ nested in methods are not included, see
                  scopes))))
 
 (defun javaimp-imenu--function (_index-name index-position _scope)
-  ;; TODO use scope open-brace as arg?
-  (let ((decl-beg (javaimp--beg-of-defun-decl index-position)))
-    (if decl-beg
-        (goto-char decl-beg)
-      (goto-char index-position)
-      (back-to-indentation))))
+  (if-let ((decl-beg (javaimp--beg-of-defun-decl index-position)))
+      (goto-char decl-beg)
+    (goto-char index-position)
+    (back-to-indentation)))
 
 
 
@@ -1168,33 +1166,7 @@ PREV-INDEX gives the index of the method itself."
                (lambda (s)
                  (and (funcall defun-pred s)
                       (funcall sibling-pred s)))))
-             ;; Note: when looking for prev/next sibling, it might be
-             ;; tempting to directly look at prev/next property
-             ;; change, but this would be correct only by accident -
-             ;; there might be any scopes in different nests in
-             ;; between.
-             (prev
-              (if (and enc (eq (javaimp-scope-type enc) 'method))
-                  enc
-                (if-let* ((next (seq-find
-                                 (lambda (s)
-                                   (>= (javaimp-scope-open-brace s) pos))
-                                 siblings))
-                          (next-beg-decl
-                           (javaimp--beg-of-defun-decl
-                            (javaimp-scope-start next) parent-beg))
-                          (beg-decl
-                           ;; TODO move out of possible arglist
-                           (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
-                    next
-                  ;; Just find previous defun
-                  (seq-find (lambda (s)
-                              (< (javaimp-scope-open-brace s) pos))
-                            (reverse siblings))))))
+             (prev (javaimp--get-prev-scope pos enc parent-beg siblings)))
         (nconc
          (list
           (and parent (javaimp-scope-open-brace parent))
@@ -1206,6 +1178,42 @@ PREV-INDEX gives the index of the method itself."
               -1))
          siblings)))))
 
+(defun javaimp--get-prev-scope (pos enc parent-beg siblings)
+  "Subroutine of `javaimp--get-sibling-context'."
+  ;; Note: when looking for prev/next sibling, it might be tempting to
+  ;; directly look at prev/next property change, but this would be
+  ;; correct only by accident - there might be any scopes in different
+  ;; nests in between.
+  (if (and enc (eq (javaimp-scope-type enc) 'method))
+      enc
+    (if-let* ((next (seq-find
+                     (lambda (s)
+                       (>= (javaimp-scope-open-brace s) pos))
+                     siblings))
+              (next-beg-decl
+               (javaimp--beg-of-defun-decl
+                (javaimp-scope-start next) parent-beg))
+              (beg-decl
+               (let ((tmp pos))
+                 ;; pos may be inside arg list or some other nested
+                 ;; construct, move out
+                 (while (and tmp
+                             ;; Note that case when both are nil is
+                             ;; also correct: there's no parent and
+                             ;; we're outside of any scope.
+                             (not (eql parent-beg (nth 1 (syntax-ppss tmp)))))
+                   (setq tmp (nth 1 (syntax-ppss tmp))))
+                 (when tmp
+                   (javaimp--beg-of-defun-decl tmp 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
+        next
+      ;; Just find previous defun
+      (seq-find (lambda (s)
+                  (< (javaimp-scope-open-brace s) pos))
+                (reverse siblings)))))
+
 (defun javaimp-jump-to-enclosing-scope ()
   "Jump to enclosing scope at point."
   (interactive)



reply via email to

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