Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 702 lines (589 sloc) 23.854 kB
fccc685 Initial open-source release
MLstate authored
1 ;;; javascript.el --- Major mode for editing JavaScript source text
2
3 ;; Copyright (C) 2008 Free Software Foundation, Inc.
4
5 ;; Author: Karl Landstrom <karl.landstrom@brgeight.se>
6 ;; Maintainer: Karl Landstrom <karl.landstrom@brgeight.se>
7 ;; Version: 2.2.1
8 ;; Date: 2008-12-27
9 ;; Keywords: languages, oop
10
11 ;; This file is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This file is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27 ;;
28 ;; The main features of this JavaScript mode are syntactic
29 ;; highlighting (enabled with `font-lock-mode' or
30 ;; `global-font-lock-mode'), automatic indentation and filling of
31 ;; comments.
32 ;;
33 ;; This package has (only) been tested with GNU Emacs 21.4 (the latest
34 ;; stable release).
35 ;;
36 ;; Installation:
37 ;;
38 ;; Put this file in a directory where Emacs can find it (`C-h v
39 ;; load-path' for more info). Then add the following lines to your
40 ;; Emacs initialization file:
41 ;;
42 ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))
43 ;; (autoload 'javascript-mode "javascript" nil t)
44 ;;
45 ;; General Remarks:
46 ;;
47 ;; This mode assumes that block comments are not nested inside block
48 ;; comments and that strings do not contain line breaks.
49 ;;
50 ;; Exported names start with "javascript-" whereas private names start
51 ;; with "js-".
52 ;;
53 ;; Changes:
54 ;;
55 ;; See javascript.el.changelog.
56
57 ;;; Code:
58
59 (require 'cc-mode)
60 (require 'font-lock)
61 (require 'newcomment)
62
63 (defgroup javascript nil
64 "Customization variables for `javascript-mode'."
65 :tag "JavaScript"
66 :group 'languages)
67
68 (defcustom javascript-indent-level 4
69 "Number of spaces for each indentation step."
70 :type 'integer
71 :group 'javascript)
72
73 (defcustom javascript-expr-indent-offset 0
74 "Number of additional spaces used for indentation of continued
75 expressions. The value must be no less than minus
76 `javascript-indent-level'."
77 :type 'integer
78 :group 'javascript)
79
80 (defcustom javascript-auto-indent-flag t
81 "Automatic indentation with punctuation characters. If non-nil, the
82 current line is indented when certain punctuations are inserted."
83 :type 'boolean
84 :group 'javascript)
85
86
87 ;; --- Keymap ---
88
89 (defvar javascript-mode-map nil
90 "Keymap used in JavaScript mode.")
91
92 (unless javascript-mode-map
93 (setq javascript-mode-map (make-sparse-keymap)))
94
95 (when javascript-auto-indent-flag
96 (mapc (lambda (key)
97 (define-key javascript-mode-map key 'javascript-insert-and-indent))
98 '("{" "}" "(" ")" ":" ";" ",")))
99
100 (defun javascript-insert-and-indent (key)
101 "Run command bound to key and indent current line. Runs the command
102 bound to KEY in the global keymap and indents the current line."
103 (interactive (list (this-command-keys)))
104 (call-interactively (lookup-key (current-global-map) key))
105 (indent-according-to-mode))
106
107
108 ;; --- Syntax Table And Parsing ---
109
110 (defvar javascript-mode-syntax-table
111 (let ((table (make-syntax-table)))
112 (c-populate-syntax-table table)
113 (modify-syntax-entry ?$ "_" table)
114 table)
115 "Syntax table used in JavaScript mode.")
116
117 (defvar js-ident-as-word-syntax-table
118 (let ((table (copy-syntax-table javascript-mode-syntax-table)))
119 (modify-syntax-entry ?$ "w" table)
120 (modify-syntax-entry ?_ "w" table)
121 table)
122 "Alternative syntax table used internally to simplify detection
123 of identifiers and keywords and its boundaries.")
124
125
126 (defun js-re-search-forward-inner (regexp &optional bound count)
127 "Auxiliary function for `js-re-search-forward'."
128 (let ((parse)
129 (saved-point (point-min)))
130 (while (> count 0)
131 (re-search-forward regexp bound)
132 (setq parse (parse-partial-sexp saved-point (point)))
133 (cond ((nth 3 parse)
134 (re-search-forward
135 (concat "\\([^\\]\\|^\\)" (string (nth 3 parse)))
136 (save-excursion (end-of-line) (point)) t))
137 ((nth 7 parse)
138 (forward-line))
139 ((or (nth 4 parse)
140 (and (eq (char-before) ?\/) (eq (char-after) ?\*)))
141 (re-search-forward "\\*/"))
142 (t
143 (setq count (1- count))))
144 (setq saved-point (point))))
145 (point))
146
147
148 (defun js-re-search-forward (regexp &optional bound noerror count)
149 "Search forward but ignore strings and comments. Invokes
150 `re-search-forward' but treats the buffer as if strings and
151 comments have been removed."
152 (let ((saved-point (point))
153 (search-expr
154 (cond ((null count)
155 '(js-re-search-forward-inner regexp bound 1))
156 ((< count 0)
157 '(js-re-search-backward-inner regexp bound (- count)))
158 ((> count 0)
159 '(js-re-search-forward-inner regexp bound count)))))
160 (condition-case err
161 (eval search-expr)
162 (search-failed
163 (goto-char saved-point)
164 (unless noerror
165 (error (error-message-string err)))))))
166
167
168 (defun js-re-search-backward-inner (regexp &optional bound count)
169 "Auxiliary function for `js-re-search-backward'."
170 (let ((parse)
171 (saved-point (point-min)))
172 (while (> count 0)
173 (re-search-backward regexp bound)
174 (when (and (> (point) (point-min))
175 (save-excursion (backward-char) (looking-at "/[/*]")))
176 (backward-char))
177 (setq parse (parse-partial-sexp saved-point (point)))
178 (cond ((nth 3 parse)
179 (re-search-backward
180 (concat "\\([^\\]\\|^\\)" (string (nth 3 parse)))
181 (save-excursion (beginning-of-line) (point)) t))
182 ((nth 7 parse)
183 (goto-char (nth 8 parse)))
184 ((or (nth 4 parse)
185 (and (eq (char-before) ?/) (eq (char-after) ?*)))
186 (re-search-backward "/\\*"))
187 (t
188 (setq count (1- count))))))
189 (point))
190
191
192 (defun js-re-search-backward (regexp &optional bound noerror count)
193 "Search backward but ignore strings and comments. Invokes
194 `re-search-backward' but treats the buffer as if strings and
195 comments have been removed."
196 (let ((saved-point (point))
197 (search-expr
198 (cond ((null count)
199 '(js-re-search-backward-inner regexp bound 1))
200 ((< count 0)
201 '(js-re-search-forward-inner regexp bound (- count)))
202 ((> count 0)
203 '(js-re-search-backward-inner regexp bound count)))))
204 (condition-case err
205 (eval search-expr)
206 (search-failed
207 (goto-char saved-point)
208 (unless noerror
209 (error (error-message-string err)))))))
210
211
212 ;; --- Font Lock ---
213
214 (defun js-inside-param-list-p ()
215 "Return non-nil if point is inside a function parameter list."
216 (condition-case err
217 (save-excursion
218 (up-list -1)
219 (and (looking-at "(")
220 (progn (backward-word 1)
221 (or (looking-at "function")
222 (progn (backward-word 1) (looking-at "function"))))))
223 (error nil)))
224
225
226 (defconst js-function-heading-1-re
227 "^[ \t]*function[ \t]+\\(\\w+\\)"
228 "Regular expression matching the start of a function header.")
229
230 (defconst js-function-heading-2-re
231 "^[ \t]*\\(\\w+\\)[ \t]*:[ \t]*function\\>"
232 "Regular expression matching the start of a function entry in
233 an associative array.")
234
235 (defconst js-keyword-re
236 (regexp-opt '("abstract" "break" "case" "catch" "class" "const"
237 "continue" "debugger" "default" "delete" "do" "else"
238 "enum" "export" "extends" "final" "finally" "for"
239 "function" "goto" "if" "implements" "import" "in"
240 "instanceof" "interface" "native" "new" "package"
241 "private" "protected" "public" "return" "static"
242 "super" "switch" "synchronized" "this" "throw"
243 "throws" "transient" "try" "typeof" "var" "void"
244 "volatile" "while" "with") 'words)
245 "Regular expression matching any JavaScript keyword.")
246
247 (defconst js-basic-type-re
248 (regexp-opt '("boolean" "byte" "char" "double" "float" "int" "long"
249 "short" "void") 'words)
250 "Regular expression matching any predefined type in JavaScript.")
251
252 (defconst js-constant-re
253 (regexp-opt '("false" "null" "true") 'words)
254 "Regular expression matching any future reserved words in JavaScript.")
255
256
257 (defconst js-font-lock-keywords-1
258 (list
259 "\\<import\\>"
260 (list js-function-heading-1-re 1 font-lock-function-name-face)
261 (list js-function-heading-2-re 1 font-lock-function-name-face))
262 "Level one font lock.")
263
264 (defconst js-font-lock-keywords-2
265 (append js-font-lock-keywords-1
266 (list (list js-keyword-re 1 font-lock-keyword-face)
267 (cons js-basic-type-re font-lock-type-face)
268 (cons js-constant-re font-lock-constant-face)))
269 "Level two font lock.")
270
271
272 ;; Limitations with variable declarations: There seems to be no
273 ;; sensible way to highlight variables occuring after an initialized
274 ;; variable in a variable list. For instance, in
275 ;;
276 ;; var x, y = f(a, b), z
277 ;;
278 ;; z will not be highlighted. Also, in variable declaration lists
279 ;; spanning several lines only variables on the first line will be
280 ;; highlighted. To get correct fontification, every line with variable
281 ;; declarations must contain a `var' keyword.
282
283 (defconst js-font-lock-keywords-3
284 (append
285 js-font-lock-keywords-2
286 (list
287
288 ;; variable declarations
289 (list
290 (concat "\\<\\(const\\|var\\)\\>\\|" js-basic-type-re)
291 (list "\\(\\w+\\)[ \t]*\\([=;].*\\|\\<in\\>.*\\|,\\|/[/*]\\|$\\)"
292 nil
293 nil
294 '(1 font-lock-variable-name-face)))
295
296 ;; formal parameters
297 (list
298 "\\<function\\>\\([ \t]+\\w+\\)?[ \t]*([ \t]*\\w"
299 (list "\\(\\w+\\)\\([ \t]*).*\\)?"
300 '(backward-char)
301 '(end-of-line)
302 '(1 font-lock-variable-name-face)))
303
304 ;; continued formal parameter list
305 (list
306 "^[ \t]*\\w+[ \t]*[,)]"
307 (list "\\w+"
308 '(if (save-excursion (backward-char) (js-inside-param-list-p))
309 (backward-word 1)
310 (end-of-line))
311 '(end-of-line)
312 '(0 font-lock-variable-name-face)))
313 ))
314 "Level three font lock.")
315
316 (defconst js-font-lock-keywords
317 '(js-font-lock-keywords-3 js-font-lock-keywords-1 js-font-lock-keywords-2
318 js-font-lock-keywords-3)
319 "See `font-lock-keywords'.")
320
321 (defconst js-font-lock-syntactic-keywords
322 '(("[=(][ \t\n]*\\(/\\)[^/*]\\(.*?[^\\]\\)?\\(/\\)" (1 '(7)) (3 '(7)))
323 ("##\\(register\\|extern-type\\)[^\n]*" 0 " ")
324 )
325 "Highlighting of regular expressions. See also the variable
326 `font-lock-keywords'.")
327
328
329 ;; --- Indentation ---
330
331 (defconst js-possibly-braceless-keyword-re
332 (regexp-opt
333 '("catch" "do" "else" "finally" "for" "if" "try" "while" "with")
334 'words)
335 "Regular expression matching keywords that are optionally
336 followed by an opening brace.")
337
338 (defconst js-indent-operator-re
339 (concat "[-+*/%<>=&^|?:.]\\([^-+*/]\\|$\\)\\|"
340 (regexp-opt '("in" "instanceof") 'words))
341 "Regular expression matching operators that affect indentation
342 of continued expressions.")
343
344
345 (defun js-looking-at-operator-p ()
346 "Return non-nil if text after point is an operator (that is not
347 a comma)."
348 (save-match-data
349 (and (looking-at js-indent-operator-re)
350 (or (not (looking-at ":"))
351 (save-excursion
352 (and (js-re-search-backward "[?:{]\\|\\<case\\>" nil t)
353 (looking-at "?")))))))
354
355
356 (defun js-continued-expression-p ()
357 "Returns non-nil if the current line continues an expression."
358 (save-excursion
359 (back-to-indentation)
360 (or (js-looking-at-operator-p)
361 (and (js-re-search-backward "\n" nil t)
362 (progn
363 (skip-chars-backward " \t")
364 (backward-char)
365 (and (> (point) (point-min))
366 (save-excursion (backward-char) (not (looking-at "[/*]/")))
367 (js-looking-at-operator-p)
368 (and (progn (backward-char)
369 (not (looking-at "++\\|--\\|/[/*]"))))))))))
370
371
372 (defun js-end-of-do-while-loop-p ()
373 "Returns non-nil if word after point is `while' of a do-while
374 statement, else returns nil. A braceless do-while statement
375 spanning several lines requires that the start of the loop is
376 indented to the same column as the current line."
377 (interactive)
378 (save-excursion
379 (save-match-data
380 (when (looking-at "\\s-*\\<while\\>")
381 (if (save-excursion
382 (skip-chars-backward "[ \t\n]*}")
383 (looking-at "[ \t\n]*}"))
384 (save-excursion
385 (backward-list) (backward-word 1) (looking-at "\\<do\\>"))
386 (js-re-search-backward "\\<do\\>" (point-at-bol) t)
387 (or (looking-at "\\<do\\>")
388 (let ((saved-indent (current-indentation)))
389 (while (and (js-re-search-backward "^[ \t]*\\<" nil t)
390 (/= (current-indentation) saved-indent)))
391 (and (looking-at "[ \t]*\\<do\\>")
392 (not (js-re-search-forward
393 "\\<while\\>" (point-at-eol) t))
394 (= (current-indentation) saved-indent)))))))))
395
396
397 (defun js-ctrl-statement-indentation ()
398 "Returns the proper indentation of the current line if it
399 starts the body of a control statement without braces, else
400 returns nil."
401 (save-excursion
402 (back-to-indentation)
403 (when (save-excursion
404 (and (not (looking-at "[{]"))
405 (progn
406 (js-re-search-backward "[[:graph:]]" nil t)
407 (forward-char)
408 (when (= (char-before) ?\)) (backward-list))
409 (skip-syntax-backward " ")
410 (skip-syntax-backward "w")
411 (looking-at js-possibly-braceless-keyword-re))
412 (not (js-end-of-do-while-loop-p))))
413 (save-excursion
414 (goto-char (match-beginning 0))
415 (+ (current-indentation) javascript-indent-level)))))
416
417
418 (defun js-proper-indentation (parse-status)
419 "Return the proper indentation for the current line."
420 (save-excursion
421 (back-to-indentation)
422 (let ((ctrl-stmt-indent (js-ctrl-statement-indentation))
423 (same-indent-p (looking-at "[]})]\\|\\<case\\>\\|\\<default\\>"))
424 (continued-expr-p (js-continued-expression-p)))
425 (cond (ctrl-stmt-indent)
426 ((nth 1 parse-status)
427 (goto-char (nth 1 parse-status))
428 (if (looking-at "[({[][ \t]*\\(/[/*]\\|$\\)")
429 (progn
430 (skip-syntax-backward " ")
431 (when (= (char-before) ?\)) (backward-list))
432 (back-to-indentation)
433 (cond (same-indent-p
434 (current-column))
435 (continued-expr-p
436 (+ (current-column) (* 2 javascript-indent-level)
437 javascript-expr-indent-offset))
438 (t
439 (+ (current-column) javascript-indent-level))))
440 (unless same-indent-p
441 (forward-char)
442 (skip-chars-forward " \t"))
443 (current-column)))
444 (continued-expr-p (+ javascript-indent-level
445 javascript-expr-indent-offset))
446 (t 0)))))
447
448
449 (defun javascript-indent-line ()
450 "Indent the current line as JavaScript source text."
451 (interactive)
452 (with-syntax-table js-ident-as-word-syntax-table
453 (let ((parse-status
454 (save-excursion (parse-partial-sexp (point-min) (point-at-bol))))
455 (offset (- (current-column) (current-indentation))))
456 (when (not (nth 8 parse-status))
457 (indent-line-to (js-proper-indentation parse-status))
458 (when (> offset 0) (forward-char offset))))))
459
460
461 ;; --- Filling ---
462
463 ;; FIXME: It should be possible to use the more sofisticated function
464 ;; `c-fill-paragraph' in `cc-cmds.el' instead. However, just setting
465 ;; `fill-paragraph-function' to `c-fill-paragraph' does not work;
466 ;; inside `c-fill-paragraph', `fill-paragraph-function' evaluates to
467 ;; nil!?
468
469 (defun js-backward-paragraph ()
470 "Move backward to start of paragraph. Postcondition: Point is at
471 beginning of buffer or the previous line contains only whitespace."
472 (forward-line -1)
473 (while (not (or (bobp) (looking-at "^[ \t]*$")))
474 (forward-line -1))
475 (when (not (bobp)) (forward-line 1)))
476
477
478 (defun js-forward-paragraph ()
479 "Move forward to end of paragraph. Postcondition: Point is at
480 end of buffer or the next line contains only whitespace."
481 (forward-line 1)
482 (while (not (or (eobp) (looking-at "^[ \t]*$")))
483 (forward-line 1))
484 (when (not (eobp)) (backward-char 1)))
485
486
487 (defun js-fill-block-comment-paragraph (parse-status justify)
488 "Fill current paragraph as a block comment. PARSE-STATUS is the
489 result of `parse-partial-regexp' from beginning of buffer to
490 point. JUSTIFY has the same meaning as in `fill-paragraph'."
491 (let ((offset (save-excursion
492 (goto-char (nth 8 parse-status)) (current-indentation))))
493 (save-excursion
494 (save-restriction
495 (narrow-to-region (save-excursion
496 (goto-char (nth 8 parse-status)) (point-at-bol))
497 (save-excursion
498 (goto-char (nth 8 parse-status))
499 (re-search-forward "*/")))
500 (narrow-to-region (save-excursion
501 (js-backward-paragraph)
502 (when (looking-at "^[ \t]*$") (forward-line 1))
503 (point))
504 (save-excursion
505 (js-forward-paragraph)
506 (when (looking-at "^[ \t]*$") (backward-char))
507 (point)))
508 (goto-char (point-min))
509 (while (not (eobp))
510 (delete-horizontal-space)
511 (forward-line 1))
512 (let ((fill-column (- fill-column offset))
513 (fill-paragraph-function nil))
514 (fill-paragraph justify))
515
516 ;; In Emacs 21.4 as opposed to CVS Emacs 22,
517 ;; `fill-paragraph' seems toadd a newline at the end of the
518 ;; paragraph. Remove it!
519 (goto-char (point-max))
520 (when (looking-at "^$") (backward-delete-char 1))
521
522 (goto-char (point-min))
523 (while (not (eobp))
524 (indent-to offset)
525 (forward-line 1))))))
526
527
528 (defun js-sline-comment-par-start ()
529 "Return point at the beginning of the line where the current
530 single-line comment paragraph starts."
531 (save-excursion
532 (beginning-of-line)
533 (while (and (not (bobp))
534 (looking-at "^[ \t]*//[ \t]*[[:graph:]]"))
535 (forward-line -1))
536 (unless (bobp) (forward-line 1))
537 (point)))
538
539
540 (defun js-sline-comment-par-end ()
541 "Return point at end of current single-line comment paragraph."
542 (save-excursion
543 (beginning-of-line)
544 (while (and (not (eobp))
545 (looking-at "^[ \t]*//[ \t]*[[:graph:]]"))
546 (forward-line 1))
547 (unless (bobp) (backward-char))
548 (point)))
549
550
551 (defun js-sline-comment-offset (line)
552 "Return the column at the start of the current single-line
553 comment paragraph."
554 (save-excursion
555 (goto-line line)
556 (re-search-forward "//" (point-at-eol))
557 (goto-char (match-beginning 0))
558 (current-column)))
559
560
561 (defun js-sline-comment-text-offset (line)
562 "Return the column at the start of the text of the current
563 single-line comment paragraph."
564 (save-excursion
565 (goto-line line)
566 (re-search-forward "//[ \t]*" (point-at-eol))
567 (current-column)))
568
569
570 (defun js-at-empty-sline-comment-p ()
571 "Return non-nil if inside an empty single-line comment."
572 (and (save-excursion
573 (beginning-of-line)
574 (not (looking-at "^.*//.*[[:graph:]]")))
575 (save-excursion
576 (re-search-backward "//" (point-at-bol) t))))
577
578
579 (defun js-fill-sline-comments (parse-status justify)
580 "Fill current paragraph as a sequence of single-line comments.
581 PARSE-STATUS is the result of `parse-partial-regexp' from
582 beginning of buffer to point. JUSTIFY has the same meaning as in
583 `fill-paragraph'."
584 (when (not (js-at-empty-sline-comment-p))
585 (let* ((start (js-sline-comment-par-start))
586 (start-line (1+ (count-lines (point-min) start)))
587 (end (js-sline-comment-par-end))
588 (offset (js-sline-comment-offset start-line))
589 (text-offset (js-sline-comment-text-offset start-line)))
590 (save-excursion
591 (save-restriction
592 (narrow-to-region start end)
593 (goto-char (point-min))
594 (while (re-search-forward "^[ \t]*//[ \t]*" nil t)
595 (replace-match "")
596 (forward-line 1))
597 (let ((fill-paragraph-function nil)
598 (fill-column (- fill-column text-offset)))
599 (fill-paragraph justify))
600
601 ;; In Emacs 21.4 as opposed to CVS Emacs 22,
602 ;; `fill-paragraph' seems to add a newline at the end of the
603 ;; paragraph. Remove it!
604 (goto-char (point-max))
605 (when (looking-at "^$") (backward-delete-char 1))
606
607 (goto-char (point-min))
608 (while (not (eobp))
609 (indent-to offset)
610 (insert "//")
611 (indent-to text-offset)
612 (forward-line 1)))))))
613
614
615 (defun js-trailing-comment-p (parse-status)
616 "Return non-nil if inside a trailing comment. PARSE-STATUS is
617 the result of `parse-partial-regexp' from beginning of buffer to
618 point."
619 (save-excursion
620 (when (nth 4 parse-status)
621 (goto-char (nth 8 parse-status))
622 (skip-chars-backward " \t")
623 (not (bolp)))))
624
625
626 (defun js-block-comment-p (parse-status)
627 "Return non-nil if inside a block comment. PARSE-STATUS is the
628 result of `parse-partial-regexp' from beginning of buffer to
629 point."
630 (save-excursion
631 (save-match-data
632 (when (nth 4 parse-status)
633 (goto-char (nth 8 parse-status))
634 (looking-at "/\\*")))))
635
636
637 (defun javascript-fill-paragraph (&optional justify)
638 "If inside a comment, fill the current comment paragraph.
639 Trailing comments are ignored."
640 (interactive)
641 (let ((parse-status (parse-partial-sexp (point-min) (point))))
642 (when (and (nth 4 parse-status)
643 (not (js-trailing-comment-p parse-status)))
644 (if (js-block-comment-p parse-status)
645 (js-fill-block-comment-paragraph parse-status justify)
646 (js-fill-sline-comments parse-status justify))))
647 t)
648
649
650 ;; --- Imenu ---
651
652 (defconst js-imenu-generic-expression
653 (list
654 (list
655 nil
656 "function\\s-+\\(\\(\\w\\|\\s_\\)+\\)\\s-*("
657 1))
658 "Regular expression matching top level procedures. Used by imenu.")
659
660
661 ;; --- Main Function ---
662
663 ;;;###autoload
664 (defun javascript-mode ()
665 "Major mode for editing JavaScript source text.
666
667 Key bindings:
668
669 \\{javascript-mode-map}"
670 (interactive)
671 (kill-all-local-variables)
672
673 (use-local-map javascript-mode-map)
674 (set-syntax-table javascript-mode-syntax-table)
675 (set (make-local-variable 'indent-line-function) 'javascript-indent-line)
676
677 (set (make-local-variable 'font-lock-defaults)
678 (list js-font-lock-keywords
679 nil nil '((?$ . "w") (?_ . "w")) nil
680 '(font-lock-syntactic-keywords . js-font-lock-syntactic-keywords)))
681
682 (set (make-local-variable 'parse-sexp-ignore-comments) t)
683
684 ;; Comments
685 (set (make-local-variable 'comment-start) "// ")
686 (set (make-local-variable 'comment-end) "")
687 (set (make-local-variable 'fill-paragraph-function)
688 'javascript-fill-paragraph)
689
690 ;; Imenu
691 (setq imenu-case-fold-search nil)
692 (set (make-local-variable 'imenu-generic-expression)
693 js-imenu-generic-expression)
694
695 (setq major-mode 'javascript-mode)
696 (setq mode-name "JavaScript")
697 (run-hooks 'javascript-mode-hook))
698
699
700 (provide 'javascript-mode)
701 ;;; javascript.el ends here
Something went wrong with that request. Please try again.