From 2a793f7f35d279ed7304772718613e40edfa917d Mon Sep 17 00:00:00 2001
From: Chong Yidong <cyd@stupidchicken.com>
Date: Sun, 28 Mar 2010 16:41:37 -0400
Subject: [PATCH] Revert 2009-08-15 change, restoring electric punctuation
 (Bug#5586)

* progmodes/js.el (js-auto-indent-flag, js-mode-map)
(js-insert-and-indent): Revert 2009-08-15 change, restoring
electric punctuation for "{}();,:" (Bug#5586).
---
 lisp/ChangeLog       |  4 ++++
 lisp/progmodes/js.el | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4cba32fe52c..3294db39d52 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
 2010-03-28  Chong Yidong  <cyd@stupidchicken.com>
 
+	* progmodes/js.el (js-auto-indent-flag, js-mode-map)
+	(js-insert-and-indent): Revert 2009-08-15 change, restoring
+	electric punctuation for "{}();,:" (Bug#5586).
+
 	* mail/sendmail.el (mail-default-directory): Doc fix.
 
 2010-03-27  Chong Yidong  <cyd@stupidchicken.com>
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 8c8d0553cfa..6bd22e4e6fa 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -436,6 +436,13 @@ The value must be no less than minus `js-indent-level'."
   :type 'integer
   :group 'js)
 
+(defcustom js-auto-indent-flag t
+  "Whether to automatically indent when typing punctuation characters.
+If non-nil, the characters {}();,: also indent the current line
+in Javascript mode."
+  :type 'boolean
+  :group 'js)
+
 (defcustom js-flat-functions nil
   "Treat nested functions as top-level functions in `js-mode'.
 This applies to function movement, marking, and so on."
@@ -483,6 +490,9 @@ getting timeout messages."
 
 (defvar js-mode-map
   (let ((keymap (make-sparse-keymap)))
+    (mapc (lambda (key)
+	    (define-key keymap key #'js-insert-and-indent))
+	  '("{" "}" "(" ")" ":" ";" ","))
     (define-key keymap [(control ?c) (meta ?:)] #'js-eval)
     (define-key keymap [(control ?c) (control ?j)] #'js-set-js-context)
     (define-key keymap [(control meta ?x)] #'js-eval-defun)
@@ -498,6 +508,21 @@ getting timeout messages."
     keymap)
   "Keymap for `js-mode'.")
 
+(defun js-insert-and-indent (key)
+  "Run the command bound to KEY, and indent if necessary.
+Indentation does not take place if point is in a string or
+comment."
+  (interactive (list (this-command-keys)))
+  (call-interactively (lookup-key (current-global-map) key))
+  (let ((syntax (save-restriction (widen) (syntax-ppss))))
+    (when (or (and (not (nth 8 syntax))
+                   js-auto-indent-flag)
+              (and (nth 4 syntax)
+                   (eq (current-column)
+                       (1+ (current-indentation)))))
+      (indent-according-to-mode))))
+
+
 ;;; Syntax table and parsing
 
 (defvar js-mode-syntax-table
-- 
2.39.5