diff options
| author | Stefan Monnier | 2011-08-12 11:32:39 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2011-08-12 11:32:39 -0400 |
| commit | 6cd18349b892a5c432991e8231364e7a4d1ea33d (patch) | |
| tree | ef929607fcc46316b05b0af07ad43233056d899a | |
| parent | a3dae87a1b5405d2bffde7c2d829a5dbfc7ff274 (diff) | |
| download | emacs-6cd18349b892a5c432991e8231364e7a4d1ea33d.tar.gz emacs-6cd18349b892a5c432991e8231364e7a4d1ea33d.zip | |
* lisp/progmodes/js.el (js-syntax-propertize, js-syntax-propertize-regexp):
New function.
(js--regexp-literal, js-syntax-propertize-function): Remove.
(js-mode): Use js-syntax-propertize to handle multilines.
(js-mode-map): Don't rebind electric keys.
(js-insert-and-indent): Remove.
(js-mode): Setup electric-layout and electric-indent instead.
Fixes: debbugs:9183
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/progmodes/js.el | 74 |
2 files changed, 44 insertions, 38 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a75c5330ed9..bde9d54cfa2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,13 @@ | |||
| 1 | 2011-08-12 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2011-08-12 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * progmodes/js.el (js-syntax-propertize, js-syntax-propertize-regexp): | ||
| 4 | New function. | ||
| 5 | (js--regexp-literal, js-syntax-propertize-function): Remove. | ||
| 6 | (js-mode): Use js-syntax-propertize to handle multilines (bug#9183). | ||
| 7 | (js-mode-map): Don't rebind electric keys. | ||
| 8 | (js-insert-and-indent): Remove. | ||
| 9 | (js-mode): Setup electric-layout and electric-indent instead. | ||
| 10 | |||
| 3 | * epa-file.el (epa-file-select-keys): Revert to nil default (bug#9280). | 11 | * epa-file.el (epa-file-select-keys): Revert to nil default (bug#9280). |
| 4 | 12 | ||
| 5 | 2011-08-12 Daiki Ueno <ueno@unixuser.org> | 13 | 2011-08-12 Daiki Ueno <ueno@unixuser.org> |
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 4abbe3b895f..5505e8e94b2 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el | |||
| @@ -61,6 +61,7 @@ | |||
| 61 | (defvar inferior-moz-buffer) | 61 | (defvar inferior-moz-buffer) |
| 62 | (defvar moz-repl-name) | 62 | (defvar moz-repl-name) |
| 63 | (defvar ido-cur-list) | 63 | (defvar ido-cur-list) |
| 64 | (defvar electric-layout-rules) | ||
| 64 | (declare-function ido-mode "ido") | 65 | (declare-function ido-mode "ido") |
| 65 | (declare-function inferior-moz-process "ext:mozrepl" ()) | 66 | (declare-function inferior-moz-process "ext:mozrepl" ()) |
| 66 | 67 | ||
| @@ -507,9 +508,6 @@ getting timeout messages." | |||
| 507 | 508 | ||
| 508 | (defvar js-mode-map | 509 | (defvar js-mode-map |
| 509 | (let ((keymap (make-sparse-keymap))) | 510 | (let ((keymap (make-sparse-keymap))) |
| 510 | (mapc (lambda (key) | ||
| 511 | (define-key keymap key #'js-insert-and-indent)) | ||
| 512 | '("{" "}" "(" ")" ":" ";" ",")) | ||
| 513 | (define-key keymap [(control ?c) (meta ?:)] #'js-eval) | 511 | (define-key keymap [(control ?c) (meta ?:)] #'js-eval) |
| 514 | (define-key keymap [(control ?c) (control ?j)] #'js-set-js-context) | 512 | (define-key keymap [(control ?c) (control ?j)] #'js-set-js-context) |
| 515 | (define-key keymap [(control meta ?x)] #'js-eval-defun) | 513 | (define-key keymap [(control meta ?x)] #'js-eval-defun) |
| @@ -525,21 +523,6 @@ getting timeout messages." | |||
| 525 | keymap) | 523 | keymap) |
| 526 | "Keymap for `js-mode'.") | 524 | "Keymap for `js-mode'.") |
| 527 | 525 | ||
| 528 | (defun js-insert-and-indent (key) | ||
| 529 | "Run the command bound to KEY, and indent if necessary. | ||
| 530 | Indentation does not take place if point is in a string or | ||
| 531 | comment." | ||
| 532 | (interactive (list (this-command-keys))) | ||
| 533 | (call-interactively (lookup-key (current-global-map) key)) | ||
| 534 | (let ((syntax (save-restriction (widen) (syntax-ppss)))) | ||
| 535 | (when (or (and (not (nth 8 syntax)) | ||
| 536 | js-auto-indent-flag) | ||
| 537 | (and (nth 4 syntax) | ||
| 538 | (eq (current-column) | ||
| 539 | (1+ (current-indentation))))) | ||
| 540 | (indent-according-to-mode)))) | ||
| 541 | |||
| 542 | |||
| 543 | ;;; Syntax table and parsing | 526 | ;;; Syntax table and parsing |
| 544 | 527 | ||
| 545 | (defvar js-mode-syntax-table | 528 | (defvar js-mode-syntax-table |
| @@ -1653,25 +1636,35 @@ This performs fontification according to `js--class-styles'." | |||
| 1653 | js--font-lock-keywords-3) | 1636 | js--font-lock-keywords-3) |
| 1654 | "Font lock keywords for `js-mode'. See `font-lock-keywords'.") | 1637 | "Font lock keywords for `js-mode'. See `font-lock-keywords'.") |
| 1655 | 1638 | ||
| 1656 | ;; XXX: Javascript can continue a regexp literal across lines so long | 1639 | (defun js-syntax-propertize-regexp (end) |
| 1657 | ;; as the newline is escaped with \. Account for that in the regexp | 1640 | (when (eq (nth 3 (syntax-ppss)) ?/) |
| 1658 | ;; below. | 1641 | ;; A /.../ regexp. |
| 1659 | (eval-and-compile | 1642 | (when (re-search-forward "\\(?:\\=\\|[^\\]\\)\\(?:\\\\\\\\\\)*/" end 'move) |
| 1660 | (defconst js--regexp-literal | 1643 | (put-text-property (1- (point)) (point) |
| 1661 | (concat | 1644 | 'syntax-table (string-to-syntax "\"/"))))) |
| 1662 | ;; We want to match regular expressions only at the beginning of | 1645 | |
| 1663 | ;; expressions. | 1646 | (defun js-syntax-propertize (start end) |
| 1664 | ;; FIXME: Should we also allow /regexp/ after infix operators such as +, | 1647 | ;; Javascript allows immediate regular expression objects, written /.../. |
| 1665 | ;; /, -, *, >, ...? | 1648 | (goto-char start) |
| 1666 | "\\(?:\\`\\|[=([{,:;]\\)\\(?:\\s-\\|\n\\)*" | 1649 | (js-syntax-propertize-regexp end) |
| 1667 | "\\(/\\)\\(?:\\\\.\\|[^/*\\]\\)\\(?:\\\\.\\|[^/\\]\\)*\\(/\\)") | 1650 | (funcall |
| 1668 | "Regexp matching a JavaScript regular expression literal. | 1651 | (syntax-propertize-rules |
| 1669 | Match groups 1 and 2 are the characters forming the beginning and | 1652 | ;; Distinguish /-division from /-regexp chars (and from /-comment-starter). |
| 1670 | end of the literal.")) | 1653 | ("\\(?:^\\|[=([{,:;]\\)\\(?:[ \t]\\)*\\(/\\)[^/*]" |
| 1671 | 1654 | (1 (ignore | |
| 1672 | (defconst js-syntax-propertize-function | 1655 | (forward-char -1) |
| 1673 | (syntax-propertize-rules | 1656 | (when (or (not (memq (char-after (match-beginning 0)) '(?\s ?\t))) |
| 1674 | (js--regexp-literal (1 "\"") (2 "\"")))) | 1657 | ;; If the / is at the beginning of line, we have to check |
| 1658 | ;; the end of the previous text. | ||
| 1659 | (save-excursion | ||
| 1660 | (goto-char (match-beginning 0)) | ||
| 1661 | (forward-comment (- (point))) | ||
| 1662 | (memq (char-before) | ||
| 1663 | (eval-when-compile (append "=({[,:;" '(nil)))))) | ||
| 1664 | (put-text-property (match-beginning 1) (match-end 1) | ||
| 1665 | 'syntax-table (string-to-syntax "\"/")) | ||
| 1666 | (js-syntax-propertize-regexp end)))))) | ||
| 1667 | (point) end)) | ||
| 1675 | 1668 | ||
| 1676 | ;;; Indentation | 1669 | ;;; Indentation |
| 1677 | 1670 | ||
| @@ -3302,7 +3295,7 @@ If one hasn't been set, or if it's stale, prompt for a new one." | |||
| 3302 | (set (make-local-variable 'font-lock-defaults) | 3295 | (set (make-local-variable 'font-lock-defaults) |
| 3303 | (list js--font-lock-keywords)) | 3296 | (list js--font-lock-keywords)) |
| 3304 | (set (make-local-variable 'syntax-propertize-function) | 3297 | (set (make-local-variable 'syntax-propertize-function) |
| 3305 | js-syntax-propertize-function) | 3298 | #'js-syntax-propertize) |
| 3306 | 3299 | ||
| 3307 | (set (make-local-variable 'parse-sexp-ignore-comments) t) | 3300 | (set (make-local-variable 'parse-sexp-ignore-comments) t) |
| 3308 | (set (make-local-variable 'parse-sexp-lookup-properties) t) | 3301 | (set (make-local-variable 'parse-sexp-lookup-properties) t) |
| @@ -3335,6 +3328,11 @@ If one hasn't been set, or if it's stale, prompt for a new one." | |||
| 3335 | c-comment-start-regexp "/[*/]\\|\\s!" | 3328 | c-comment-start-regexp "/[*/]\\|\\s!" |
| 3336 | comment-start-skip "\\(//+\\|/\\*+\\)\\s *") | 3329 | comment-start-skip "\\(//+\\|/\\*+\\)\\s *") |
| 3337 | 3330 | ||
| 3331 | (set (make-local-variable 'electric-indent-chars) | ||
| 3332 | (append "{}():;," electric-indent-chars)) | ||
| 3333 | (set (make-local-variable 'electric-layout-rules) | ||
| 3334 | '((?\; . after) (?\{ . after) (?\} . before))) | ||
| 3335 | |||
| 3338 | (let ((c-buffer-is-cc-mode t)) | 3336 | (let ((c-buffer-is-cc-mode t)) |
| 3339 | ;; FIXME: These are normally set by `c-basic-common-init'. Should | 3337 | ;; FIXME: These are normally set by `c-basic-common-init'. Should |
| 3340 | ;; we call it instead? (Bug#6071) | 3338 | ;; we call it instead? (Bug#6071) |