Commits

scop  committed 04cf6c8

javascript-mode imenu support <1042981327.32594.15.camel@bobcat.ods.org>.

  • Participants
  • Parent commits a244672

Comments (0)

Files changed (2)

+2003-01-19  Ville Skyttä  <scop@xemacs.org>
+
+	* javascript-mode.el: Add imenu support.
+
 2003-01-13  Rendhalver [Peter Brown]  <rendhalver@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 1.70 released.

File javascript-mode.el

 
 ;; ------------------------------------------------------------------------ ;;
 
-(defconst javascript-mode-version "1.7" "Version of `javascript-mode'.")
+(defconst javascript-mode-version "1.8" "Version of `javascript-mode'.")
 
 ;; ------------------------------------------------------------------------ ;;
 
 ;; ------------------------------------------------------------------------ ;;
 
 ;; Font lock keywords
+
+(defconst javascript-function-re
+  (concat "\\(^\\|[ \t;{]\\)function[ \t]+\\("
+          javascript-identifier
+          "\\)"))
+
+(defconst javascript-variable-re
+  (concat "\\(^\\|[ \t;{(]\\)\\(const\\|var\\)[ \t]+\\("
+          javascript-identifier
+          "\\)"))
+
 (defconst javascript-font-lock-keywords
   (list
 
          '(2 'font-lock-keyword-face))
 
    ;; Function declarations.
-   (cons (concat
-          "\\(^\\|[ \t;{]\\)function[ \t]+\\("
-          javascript-identifier
-          "\\)")
-         '(2 'font-lock-function-name-face))
+   (cons javascript-function-re '(2 'font-lock-function-name-face))
    ;; This would catch both declarations and calls.
    ;(cons (concat
    ;       "\\(^\\|[ \t.;{(]\\)\\("
    ;      '(2 'font-lock-function-name-face))
 
    ;; Variables and constants.
-   (cons (concat
-          "\\(^\\|[ \t;{(]\\)\\(const\\|var\\)[ \t]+\\("
-          javascript-identifier
-          "\\)")
-         '(3 'font-lock-variable-name-face))
+   (cons javascript-variable-re '(3 'font-lock-variable-name-face))
    ;; This would catch more of them and properties as well.
    ;(cons (concat
    ;       "\\(^\\|[ \t(\\[\\.{;]\\)\\("
 
 ;; ------------------------------------------------------------------------ ;;
 
+(defvar javascript-imenu-generic-expression
+  `((nil ,javascript-function-re 2)
+    ;; ("Variables" ,javascript-variable-re 3)
+    )
+  "Imenu generic expression for JavaScript mode.
+See `imenu-generic-expression'.")
+
+;; ------------------------------------------------------------------------ ;;
+
 ;;;###autoload
 (defun javascript-mode ()
   "Major mode for editing JavaScript code.
     (set (make-local-variable 'c-lambda-key) "function")
     (c-set-offset 'inlambda 0)
 
+    ;; imenu support.
+    (set (make-local-variable 'imenu-generic-expression)
+         javascript-imenu-generic-expression)
+
     ;; Restore the original c++-mode-hook.
     (setq c++-mode-hook current-c++-mode-hook)