]> git.eshelyaron.com Git - emacs.git/commitdiff
Revert 2009-08-15 change, restoring electric punctuation (Bug#5586)
authorChong Yidong <cyd@stupidchicken.com>
Sun, 28 Mar 2010 20:41:37 +0000 (16:41 -0400)
committerChong Yidong <cyd@stupidchicken.com>
Sun, 28 Mar 2010 20:41:37 +0000 (16:41 -0400)
* 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
lisp/progmodes/js.el

index 4cba32fe52c8886ecc5123f721d0434ab41cf799..3294db39d522c82df87101d47dfd75867024df01 100644 (file)
@@ -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>
index 8c8d0553cfa72cade6405e1ff3eb865862baeabf..6bd22e4e6fa0f7840cce6416ba25c40cb11a8948 100644 (file)
@@ -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