emacs js2-mode如何在其他窗口中跳转到定义?

时间:2018-01-28 07:39:04

标签: emacs js2-mode

js2-mode中,M-.运行命令js2-jump-to-definition,效果很好。但我希望它转到其他窗口的定义。我在Github中找到了代码js2-jump-to-definition

在其他窗口中打开它的最简单方法是什么?

(defun js2-jump-to-definition (&optional arg)
  "Jump to the definition of an object's property, variable or function."
  (interactive "P")
  (if (eval-when-compile (fboundp 'xref-push-marker-stack))
      (xref-push-marker-stack)
    (ring-insert find-tag-marker-ring (point-marker)))
  (js2-reparse)
  (let* ((node (js2-node-at-point))
         (parent (js2-node-parent node))
         (names (if (js2-prop-get-node-p parent)
                    (reverse (let ((temp (js2-compute-nested-prop-get parent)))
                               (cl-loop for n in temp
                                        with result = '()
                                        do (push n result)
                                        until (equal node n)
                                        finally return result)))))
         node-init)
    (unless (and (js2-name-node-p node)
                 (not (js2-var-init-node-p parent))
                 (not (js2-function-node-p parent)))
      (error "Node is not a supported jump node"))
    (push (or (and names (pop names))
              (unless (and (js2-object-prop-node-p parent)
                           (eq node (js2-object-prop-node-left parent)))
                node)) names)
    (setq node-init (js2-search-scope node names))

    ;; todo: display list of results in buffer
    ;; todo: group found references by buffer
    (unless node-init
      (switch-to-buffer
       (catch 'found
         (unless arg
           (mapc (lambda (b)
                   (with-current-buffer b
                     (when (derived-mode-p 'js2-mode)
                       (setq node-init (js2-search-scope js2-mode-ast names))
                       (if node-init
                           (throw 'found b)))))
                 (buffer-list)))
         nil)))
    (setq node-init (if (listp node-init) (car node-init) node-init))
    (unless node-init
      (pop-tag-mark)
      (error "No jump location found"))
    (goto-char (js2-node-abs-pos node-init))))

0 个答案:

没有答案