emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-23 r99694: Revert 2009-08-15 change,


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-23 r99694: Revert 2009-08-15 change, restoring electric punctuation (Bug#5586)
Date: Sun, 28 Mar 2010 16:41:37 -0400
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 99694
committer: Chong Yidong <address@hidden>
branch nick: emacs-23
timestamp: Sun 2010-03-28 16:41:37 -0400
message:
  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).
modified:
  lisp/ChangeLog
  lisp/progmodes/js.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-03-28 03:52:17 +0000
+++ b/lisp/ChangeLog    2010-03-28 20:41:37 +0000
@@ -1,5 +1,9 @@
 2010-03-28  Chong Yidong  <address@hidden>
 
+       * 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  <address@hidden>

=== modified file 'lisp/progmodes/js.el'
--- a/lisp/progmodes/js.el      2010-01-13 08:35:10 +0000
+++ b/lisp/progmodes/js.el      2010-03-28 20:41:37 +0000
@@ -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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]