diff options
Diffstat (limited to 'lisp/progmodes/js.el')
-rw-r--r-- | lisp/progmodes/js.el | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 5ec6da48d95..c25e52cdc6a 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -248,7 +248,7 @@ name as matched contains (defconst js--function-heading-1-re (concat - "^\\s-*function\\s-+\\(" js--name-re "\\)") + "^\\s-*function\\(?:\\s-\\|\\*\\)+\\(" js--name-re "\\)") "Regexp matching the start of a JavaScript function header. Match group 1 is the name of the function.") @@ -796,6 +796,9 @@ determined. Otherwise, return nil." (let ((name t)) (forward-word) (forward-comment most-positive-fixnum) + (when (eq (char-after) ?*) + (forward-char) + (forward-comment most-positive-fixnum)) (when (looking-at js--name-re) (setq name (match-string-no-properties 0)) (goto-char (match-end 0))) @@ -1637,12 +1640,29 @@ This performs fontification according to `js--class-styles'." js--font-lock-keywords-3) "Font lock keywords for `js-mode'. See `font-lock-keywords'.") +(defconst js--syntax-propertize-regexp-syntax-table + (let ((st (make-char-table 'syntax-table (string-to-syntax ".")))) + (modify-syntax-entry ?\[ "(]" st) + (modify-syntax-entry ?\] ")[" st) + (modify-syntax-entry ?\\ "\\" st) + st)) + (defun js-syntax-propertize-regexp (end) - (when (eq (nth 3 (syntax-ppss)) ?/) - ;; A /.../ regexp. - (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" end 'move) - (put-text-property (1- (point)) (point) - 'syntax-table (string-to-syntax "\"/"))))) + (let ((ppss (syntax-ppss))) + (when (eq (nth 3 ppss) ?/) + ;; A /.../ regexp. + (while + (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" + end 'move) + (if (nth 1 (with-syntax-table + js--syntax-propertize-regexp-syntax-table + (let ((parse-sexp-lookup-properties nil)) + (parse-partial-sexp (nth 8 ppss) (point))))) + ;; A / within a character class is not the end of a regexp. + t + (put-text-property (1- (point)) (point) + 'syntax-table (string-to-syntax "\"/")) + nil)))))) (defun js-syntax-propertize (start end) ;; Javascript allows immediate regular expression objects, written /.../. @@ -3479,6 +3499,10 @@ If one hasn't been set, or if it's stale, prompt for a new one." '(when (fboundp 'folding-add-to-marks-list) (folding-add-to-marks-list 'js-mode "// {{{" "// }}}" ))) +;;;###autoload +(dolist (name (list "node" "nodejs" "gjs" "rhino")) + (add-to-list 'interpreter-mode-alist (cons (purecopy name) 'js-mode))) + (provide 'js) ;; js.el ends here |