User: scop
Date: 06/05/06 20:38:55
Modified: packages/xemacs-packages/prog-modes ChangeLog
javascript-mode.el
Log:
javascript-mode function regexp improvements
<1146940688.2735.27.camel(a)localhost.localdomain>
Revision Changes Path
1.235 +6 -0 XEmacs/packages/xemacs-packages/prog-modes/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/prog-modes/ChangeLog,v
retrieving revision 1.234
retrieving revision 1.235
diff -u -p -r1.234 -r1.235
--- ChangeLog 2005/12/05 06:19:41 1.234
+++ ChangeLog 2006/05/06 18:38:54 1.235
@@ -1,3 +1,9 @@
+2006-05-06 Ville Skyttä <scop(a)xemacs.org>
+
+ * javascript-mode.el: Improve regexps for finding prototype and
+ property style function declarations (thanks to Tsirkin Evgeny),
+ miscellaneous other cleanups.
+
2005-12-05 Norbert Koch <viteno(a)xemacs.org>
* Makefile (VERSION): XEmacs package 2.06 released.
1.12 +49 -13 XEmacs/packages/xemacs-packages/prog-modes/javascript-mode.el
Index: javascript-mode.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/prog-modes/javascript-mode.el,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -p -r1.11 -r1.12
--- javascript-mode.el 2004/07/26 09:07:20 1.11
+++ javascript-mode.el 2006/05/06 18:38:54 1.12
@@ -1,7 +1,7 @@
;;; javascript-mode.el --- major mode for editing JavaScript code
;; Copyright (C) 1997-2001 Steven Champeon
-;; 2002-2004 Ville Skyttä
+;; 2002-2006 Ville Skyttä
;; Author: 1997 Steven Champeon <schampeo(a)hesketh.com>
;; Maintainer: Ville Skyttä <scop(a)xemacs.org>
@@ -21,8 +21,8 @@
;; You should have received a copy of the GNU General Public License
;; along with XEmacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;; Synched up with: not in GNU Emacs.
@@ -37,6 +37,7 @@
;; Sebastian Delmont (fix for prototype function indentation problems)
;; Stefan Schlee (GNU Emacs compatibility fixes)
;; Igor Rayak (ditto)
+;; Tsirkin Evgeny (regexp improvement ideas)
;; TODO:
;; - Multiple font-lock/highlight levels.
@@ -56,7 +57,7 @@
;; ------------------------------------------------------------------------ ;;
-(defconst javascript-mode-version "1.9" "Version of
`javascript-mode'.")
+(defconst javascript-mode-version "1.10" "Version of
`javascript-mode'.")
;; ------------------------------------------------------------------------ ;;
@@ -181,8 +182,8 @@ Set arguments for this command in `javas
) t))
"Expression for matching reserved words in `javascript-mode' buffers.
-From Core JavaScript Reference 1.5, Appendix A (Reserved Words):
-<http://developer.netscape.com/docs/manuals/js/core/jsref15/keywords.html>")
+From Core JavaScript Reference 1.5, Reserved Words:
+<http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Reserved_Words>")
;; JavaScript identifiers
@@ -191,22 +192,53 @@ From Core JavaScript Reference 1.5, Appe
"[a-zA-Z_\\$][a-zA-Z0-9_\\$]*"
"Expression for matching identifiers in `javascript-mode' buffers.
-From Core JavaScript Guide 1.5, Chapter 2 (Values, Variables and Literals):
-<http://developer.netscape.com/docs/manuals/js/core/jsguide15/ident.html>")
+From Core JavaScript Guide 1.5, Core Language Features:
+<http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:About:Core_Language_Features>")
;; ------------------------------------------------------------------------ ;;
-;; Font lock keywords
+;; Font lock keywords etc
+;; eg. function foo(bar, quux)
(defconst javascript-function-re
- (concat "\\(^\\|[ \t;{]\\)function[ \t]+\\("
+ (concat "\\(^\\|[ \t;{]\\)"
+ "function[ \t]+"
+ "\\("
+ "\\(" javascript-identifier "\\.\\)*"
javascript-identifier
- "\\)"))
+ "\\)")
+ "Regular expression for matching \"normal\" function
declarations.")
+;; eg. foo: function(bar, quux)
+(defconst javascript-property-function-re
+ (concat "\\(^\\|[ \t;{]+\\)"
+ "\\("
+ "\\(" javascript-identifier "\\.\\)*"
+ javascript-identifier
+ "\\)"
+ "[ \t]*:[ \t]*"
+ "\\(new[ \t]+Function\\|function\\)"
+ "[ \t]*(")
+ "Regular expression for matching property style function declarations.")
+
+;; eg. foo.bar.quux = function(baz)
+(defconst javascript-prototype-function-re
+ (concat "\\(^\\|[ \t;{]+\\)"
+ "\\("
+ "\\(" javascript-identifier "\\.\\)*"
+ javascript-identifier
+ "\\)"
+ "[ \t]*=[ \t]*"
+ "\\(new[ \t]+Function\\|function\\)"
+ "[ \t]*(")
+ "Regular expression for matching prototype style function declarations.")
+
(defconst javascript-variable-re
- (concat "\\(^\\|[ \t;{(]\\)\\(const\\|var\\)[ \t]+\\("
+ (concat "\\(^\\|[ \t;{(]\\)\\(const\\|var\\)[ \t]+"
+ "\\("
javascript-identifier
- "\\)"))
+ "\\)")
+ "Regular expression for matching variables.")
(defconst javascript-font-lock-keywords
(list
@@ -220,6 +252,8 @@ From Core JavaScript Guide 1.5, Chapter
;; Function declarations.
(cons javascript-function-re '(2 'font-lock-function-name-face))
+ (cons javascript-property-function-re '(2 'font-lock-function-name-face))
+ (cons javascript-prototype-function-re '(2 'font-lock-function-name-face))
;; This would catch both declarations and calls.
;(cons (concat
; "\\(^\\|[ \t.;{(]\\)\\("
@@ -243,6 +277,8 @@ From Core JavaScript Guide 1.5, Chapter
(defvar javascript-imenu-generic-expression
`((nil ,javascript-function-re 2)
+ (nil ,javascript-property-function-re 2)
+ (nil ,javascript-prototype-function-re 2)
;; ("Variables" ,javascript-variable-re 3)
)
"Imenu generic expression for JavaScript mode.