branch: externals/javaimp commit 3ea7aebb96c1f964057f6b1e3e2b3bb9d4c5e3fd Author: Filipp Gunbin <fgun...@fastmail.fm> Commit: Filipp Gunbin <fgun...@fastmail.fm>
*** empty log message *** --- javaimp-parse.el | 9 ++++----- javaimp.el | 57 ++++++++++++++++++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/javaimp-parse.el b/javaimp-parse.el index bab4249823..ce51f1ad38 100644 --- a/javaimp-parse.el +++ b/javaimp-parse.el @@ -515,12 +515,11 @@ lambdas are also recognized as such." (defun javaimp-parse--scope-method-or-stmt (brace-pos) "Attempt to parse `method' or `statement' scope." - ;; Take the closest preceding closing paren as the bound - (let ((throws-search-bound (when (javaimp-parse--rsb-keyword ")" nil t 1) - (1+ (point))))) - (when throws-search-bound + (let ((arglist-end (when (javaimp-parse--rsb-keyword ")" nil t 1) + (1+ (point))))) + (when arglist-end (let* ((throws-start (javaimp-parse--decl-suffix - "\\_<throws\\_>" brace-pos throws-search-bound)) + "\\_<throws\\_>" brace-pos arglist-end)) (throws-args (when throws-start (or (javaimp-parse--arglist (+ throws-start (length "throws")) brace-pos t) diff --git a/javaimp.el b/javaimp.el index ea2a79af30..94737cf47b 100644 --- a/javaimp.el +++ b/javaimp.el @@ -877,6 +877,7 @@ 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) @@ -1077,33 +1078,41 @@ buffer." (let* ((ctx (javaimp--get-sibling-context)) (parent-start (nth 0 ctx)) (offset-from-prev (if (> arg 0) - (1- arg) + (1- arg) ;prev counts for 1 arg)) (target-idx (- (nth 1 ctx) offset-from-prev)) (siblings (nthcdr 2 ctx))) - (if (or (not siblings) - (< target-idx 0) - (>= target-idx (length siblings))) - (if parent-start - ;; It's not very clear what to do when we need to move - ;; out of current scope. Currently we just move up to - ;; parent, trying to also skip its decl prefix. This - ;; gives acceptable results. - (goto-char (or (javaimp--beg-of-defun-decl parent-start) - parent-start)) - (goto-char (if (> arg 0) - (point-min) - (point-max))) - nil) - (let ((scope (nth target-idx siblings))) - (goto-char (or (javaimp--beg-of-defun-decl - (javaimp-scope-start scope) parent-start) - (javaimp-scope-open-brace scope)))))))) + (cond ((and (>= target-idx 0) + (< target-idx (length siblings))) + ;; Move to target sibling + (let ((scope (nth target-idx siblings))) + (goto-char (or (javaimp--beg-of-defun-decl + (javaimp-scope-start scope) parent-start) + (javaimp-scope-open-brace scope))))) + (siblings + ;; Move to start of first/last sibling + (goto-char (javaimp-scope-open-brace + (car (if (< target-idx 0) + siblings + (last siblings)))))) + (parent-start + (goto-char parent-start) + ;; Move forward one line unless closing brace is on the + ;; same line + (let ((parent-end (ignore-errors + (scan-lists parent-start 1 0)))) + (unless (and parent-end + (= (line-number-at-pos parent-start) + (line-number-at-pos parent-end))) + (forward-line)))) + (t + (goto-char (if (< target-idx 0) + (point-min) (point-max)))))))) (defun javaimp--beg-of-defun-decl (pos &optional bound) "Assuming POS is somewhere inside the defun declaration, return the beginning of that declaration. Don't go farther backwards -than BOUND." +than BOUND. POS should not be in arglist or similar list." (save-excursion (save-restriction (widen) @@ -1125,7 +1134,8 @@ than BOUND." 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 -1. PARENT-START is the position of -beginning (as in `javaimp-scope-start') of parent defun, if any. +beginning (as in `javaimp-scope-open-brace') of parent defun, if +any. Both when we're inside a method and between methods, the parent is the method's enclosing class. When we're inside the method, @@ -1174,6 +1184,7 @@ PREV-INDEX gives the index of the method itself." (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 @@ -1186,9 +1197,7 @@ PREV-INDEX gives the index of the method itself." (reverse siblings)))))) (nconc (list - ;; Return start, not open brace, as this is where we'd like - ;; to go when no sibling - (and parent (javaimp-scope-start parent)) + (and parent (javaimp-scope-open-brace parent)) (or (and prev (seq-position siblings prev (lambda (s1 s2)