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

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

[elpa] master f942b83 26/38: Support jumping to buffers of the same majo


From: Dmitry Gutov
Subject: [elpa] master f942b83 26/38: Support jumping to buffers of the same major mode
Date: Wed, 09 Sep 2015 18:41:47 +0000

branch: master
commit f942b83f95394d4035e8de6e73b98551e722335a
Author: ScottyB <address@hidden>
Commit: ScottyB <address@hidden>

    Support jumping to buffers of the same major mode
---
 js2-mode.el |   66 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 41 insertions(+), 25 deletions(-)

diff --git a/js2-mode.el b/js2-mode.el
index cfcc302..cf99e37 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -12299,41 +12299,57 @@ it marks the next defun after the ones already 
marked."
     (unless (js2-ast-root-p fn)
       (narrow-to-region beg (+ beg (js2-node-len fn))))))
 
-(defun js2-jump-to-definition ()
+(defun js2-jump-to-definition (&optional arg)
   "Jump to the definition of an object's property, variable or function."
-  (interactive)
+  (interactive "P")
   (ring-insert find-tag-marker-ring (point-marker))
   (let* ((node (js2-node-at-point))
          (parent (js2-node-parent node))
-         (prop-names (if (js2-prop-get-node-p parent)(reverse 
(js2-prop-names-left node))))
-         (name (or (and prop-names (pop prop-names))
-                  (unless (and (js2-object-prop-node-p parent)
-                    (eq node (js2-object-prop-node-left parent)))
-                    (js2-name-node-name node))
-                  (error "Node is not a supported jump node")))
+         (names (if (js2-prop-get-node-p parent)(reverse (js2-prop-names-left 
node))))
          node-init)
-    (ignore-errors
-      (setq node-init (js2-symbol-ast-node (js2-get-symbol-declaration node 
name)))
-      (when prop-names
-        (let ((found-node (js2-var-init-node-initializer (js2-node-parent 
node-init))))
-          (setq node-init nil)
-          (when (js2-object-node-p found-node)
-            (js2-visit-ast
-             found-node
-             (lambda (node endp)
-               (unless endp
-                 (when (and (js2-object-prop-node-p node)
-                          (string= (car prop-names)
-                                   (js2-name-node-name 
(js2-object-prop-node-left node))))
-                   (pop prop-names)
-                   (unless prop-names (setq node-init node)))
-                 t)))))))
+    (push (or (and names (pop names))
+             (unless (and (js2-object-prop-node-p parent)
+                        (eq node (js2-object-prop-node-left parent)))
+               (js2-name-node-name node))
+             (error "Node is not a supported jump node")) names)
+    (setq node-init (js2-search-scope node names))
+    (unless node-init
+      (switch-to-buffer (catch 'found
+                          (unless arg
+                            (mapc (lambda (b) (if (derived-mode-p 'js2-mode)
+                                             (with-current-buffer b
+                                               (setq node-init 
(js2-search-scope js2-mode-ast names))
+                                               (if node-init
+                                                   (throw 'found b)))))
+                                  (buffer-list)))
+                          nil)))
     (unless node-init
       (pop-tag-mark)
       (error "No jump location found"))
     (goto-char (js2-node-abs-pos node-init))))
 
-(defun js2-prop-names-left (name-node)
+(defun js2-search-scope (scope names)
+  "Searches SCOPE for jump location in NAMES."
+  (let (node-init)
+    (ignore-errors
+    (setq node-init (js2-symbol-ast-node (js2-get-symbol-declaration scope 
(pop names))))
+    (when names
+      (let ((found-node (js2-var-init-node-initializer (js2-node-parent 
node-init))))
+        (setq node-init nil)
+        (when (js2-object-node-p found-node)
+          (js2-visit-ast
+           found-node
+           (lambda (node endp)
+             (unless endp
+               (when (and (js2-object-prop-node-p node)
+                        (string= (car names)
+                                 (js2-name-node-name 
(js2-object-prop-node-left node))))
+                 (pop names)
+                 (unless names (setq node-init node)))
+               t)))))))
+    node-init))
+
+(defun js2-names-left (name-node)
   "Create a list of all of the names in the property NAME-NODE.
 NAME-NODE must have a js2-prop-get-node as parent.  Only adds
 properties to the left of point.  This is so individual jump



reply via email to

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