changeset 107692:831fbe6bd8c0

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).
author Chong Yidong <cyd@stupidchicken.com>
date Sun, 28 Mar 2010 16:41:37 -0400
parents 214eecafd6fb
children 02814963489b 360db9adc347
files lisp/ChangeLog lisp/progmodes/js.el
diffstat 2 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sun Mar 28 15:09:21 2010 -0400
+++ b/lisp/ChangeLog	Sun Mar 28 16:41:37 2010 -0400
@@ -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>
--- a/lisp/progmodes/js.el	Sun Mar 28 15:09:21 2010 -0400
+++ b/lisp/progmodes/js.el	Sun Mar 28 16:41:37 2010 -0400
@@ -436,6 +436,13 @@
   :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 @@
 
 (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 @@
     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