From: Dmitry Gutov Date: Fri, 10 May 2013 12:16:48 +0000 (+0400) Subject: js2-imenu-extras: Define a minor mode X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/068a36adff25e244dcbb21aafb953fc3b66c5853 js2-imenu-extras: Define a minor mode js2-do-parse: Use `run-hooks' on `js2-post-parse-callbacks'. js2-post-parse-callbacks: Use `add-hook'. The old way to set up this should still work, too. --- diff --git a/js2-imenu-extras.el b/js2-imenu-extras.el index 30619051b..e8e15a505 100644 --- a/js2-imenu-extras.el +++ b/js2-imenu-extras.el @@ -1,5 +1,7 @@ ;;; js2-imenu-extras.el --- Imenu support for additional constructs +;; Copyright (C) 2012-2013 Free Software Foundation, Inc. + ;; Author: Dmitry Gutov ;; Keywords: languages, javascript, imenu @@ -21,14 +23,11 @@ ;;; Commentary: ;; This package adds Imenu support for additional framework constructs and -;; general patterns to `js2-mode'. +;; structural patterns to `js2-mode'. ;; Usage: -;; (eval-after-load 'js2-mode -;; '(progn -;; (require 'js2-imenu-extras) -;; (js2-imenu-extras-setup))) +;; (add-hook 'js2-mode-hook 'js2-imenu-extras-mode) ;; To customize how it works: ;; M-x customize-group RET js2-imenu RET @@ -100,9 +99,13 @@ prefix any functions defined inside the IIFE with the module name." ;;;###autoload (defun js2-imenu-extras-setup () (when js2-imenu-enabled-frameworks - (add-to-list 'js2-post-parse-callbacks 'js2-imenu-record-declarations t)) + (add-hook 'js2-post-parse-callbacks 'js2-imenu-record-declarations t t)) (when (or js2-imenu-show-other-functions js2-imenu-show-module-pattern) - (add-to-list 'js2-post-parse-callbacks 'js2-imenu-walk-ast t))) + (add-hook 'js2-post-parse-callbacks 'js2-imenu-walk-ast t t))) + +(defun js2-imenu-extras-remove () + (remove-hook 'js2-post-parse-callbacks 'js2-imenu-record-declarations t) + (remove-hook 'js2-post-parse-callbacks 'js2-imenu-walk-ast t)) (defun js2-imenu-record-declarations () (let* ((styles (loop for style in js2-imenu-extension-styles @@ -208,4 +211,12 @@ NODE must be `js2-assign-node'." (js2-record-imenu-entry fn target-qname (js2-node-abs-pos target)))))))))) +;;;###autoload +(define-minor-mode js2-imenu-extras-mode + "Toggle Imenu support for frameworks and structural patterns." + :lighter "" + (if js2-imenu-extras-mode + (js2-imenu-extras-setup) + (js2-imenu-extras-remove))) + (provide 'js2-imenu-extras) diff --git a/js2-mode.el b/js2-mode.el index b48945864..f7efc53a2 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -7136,8 +7136,7 @@ Scanner should be initialized." ;; Give extensions a chance to muck with things before highlighting starts. (let ((js2-additional-externs js2-additional-externs)) (save-excursion - (dolist (callback js2-post-parse-callbacks) - (funcall callback))) + (run-hooks 'js2-post-parse-callbacks)) (js2-highlight-undeclared-vars)) root))