From 91a2895d72470c81e67bf40227bbcaa615d8894c Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Sun, 10 Feb 2013 09:03:53 +0400 Subject: [PATCH] Make sure js2-mode-ast is available for callbacks --- js2-imenu-extras.el | 8 ++------ js2-mode.el | 5 +++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/js2-imenu-extras.el b/js2-imenu-extras.el index f9215a478..30619051b 100644 --- a/js2-imenu-extras.el +++ b/js2-imenu-extras.el @@ -104,8 +104,6 @@ prefix any functions defined inside the IIFE with the module name." (when (or js2-imenu-show-other-functions js2-imenu-show-module-pattern) (add-to-list 'js2-post-parse-callbacks 'js2-imenu-walk-ast t))) -(declare (special root)) - (defun js2-imenu-record-declarations () (let* ((styles (loop for style in js2-imenu-extension-styles when (memq (plist-get style :framework) @@ -113,9 +111,7 @@ prefix any functions defined inside the IIFE with the module name." collect style)) (re (mapconcat (lambda (style) (concat "\\(" (plist-get style :call-re) "\\)")) - styles "\\|")) - ;; Dynamic scoping. Ew. - (js2-mode-ast root)) + styles "\\|"))) (goto-char (point-min)) (while (js2-re-search-forward re nil t) (loop for i from 0 to (1- (length styles)) @@ -163,7 +159,7 @@ prefix any functions defined inside the IIFE with the module name." (defun js2-imenu-walk-ast () (js2-visit-ast - root + js2-mode-ast (lambda (node end-p) (unless end-p (cond diff --git a/js2-mode.el b/js2-mode.el index 702b32c93..69eac43e3 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -843,7 +843,7 @@ externs appropriate for the specific file, perhaps based on its path. These should go in `js2-additional-externs', which is buffer-local. Finally, you can add a function to `js2-post-parse-callbacks', -which is called after parsing completes, and `root' is bound to +which is called after parsing completes, and `js2-mode-ast' is bound to the root of the parse tree. At this stage you can set up an AST node visitor using `js2-visit-ast' and examine the parse tree for specific import patterns that may imply the existence of @@ -7187,6 +7187,7 @@ Scanner should be initialized." (push comment (js2-ast-root-comments root)) (js2-node-add-children root comment))) (setf (js2-node-len root) (- end pos)) + (setq js2-mode-ast root) ; Make sure this is available for callbacks. ;; Give extensions a chance to muck with things before highlighting starts. (let ((js2-additional-externs js2-additional-externs)) (save-excursion @@ -10448,7 +10449,7 @@ buffer will only rebuild its `js2-mode-ast' if the buffer is dirty." (js2-time (setq interrupted-p (catch 'interrupted - (setq js2-mode-ast (js2-parse)) + (js2-parse) ;; if parsing is interrupted, comments and regex ;; literals stay ignored by `parse-partial-sexp' (remove-text-properties (point-min) (point-max) -- 2.39.2