emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r101196: * progmodes/js.el: Make inde


From: Chong Yidong
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r101196: * progmodes/js.el: Make indentation more customizable (Bug#6914).
Date: Thu, 26 Aug 2010 16:09:31 -0400
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 101196
author: Nathan Weizenbaum <address@hidden>
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Thu 2010-08-26 16:09:31 -0400
message:
  * progmodes/js.el: Make indentation more customizable (Bug#6914).
  (js-paren-indent-offset, js-square-indent-offset)
  (js-curly-indent-offset): New options.
  (js--proper-indentation): Use them.
modified:
  lisp/ChangeLog
  lisp/progmodes/js.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-08-26 15:26:33 +0000
+++ b/lisp/ChangeLog    2010-08-26 20:09:31 +0000
@@ -1,3 +1,10 @@
+2010-08-26  Nathan Weizenbaum  <address@hidden>  (tiny change)
+
+       * progmodes/js.el: Make indentation more customizable (Bug#6914).
+       (js-paren-indent-offset, js-square-indent-offset)
+       (js-curly-indent-offset): New options.
+       (js--proper-indentation): Use them.
+
 2010-08-26  Daniel Colascione  <address@hidden>
 
        * progmodes/sh-script.el (sh-get-indent-info): Use syntax-ppss

=== modified file 'lisp/progmodes/js.el'
--- a/lisp/progmodes/js.el      2010-07-27 16:37:25 +0000
+++ b/lisp/progmodes/js.el      2010-08-26 20:09:31 +0000
@@ -431,11 +431,32 @@
   :group 'js)
 
 (defcustom js-expr-indent-offset 0
-  "Number of additional spaces used for indentation of continued expressions.
+  "Number of additional spaces for indenting continued expressions.
 The value must be no less than minus `js-indent-level'."
   :type 'integer
   :group 'js)
 
+(defcustom js-paren-indent-offset 0
+  "Number of additional spaces for indenting expressions in parentheses.
+The value must be no less than minus `js-indent-level'."
+  :type 'integer
+  :group 'js
+  :version "24.1")
+
+(defcustom js-square-indent-offset 0
+  "Number of additional spaces for indenting expressions in square braces.
+The value must be no less than minus `js-indent-level'."
+  :type 'integer
+  :group 'js
+  :version "24.1")
+
+(defcustom js-curly-indent-offset 0
+  "Number of additional spaces for indenting expressions in curly braces.
+The value must be no less than minus `js-indent-level'."
+  :type 'integer
+  :group 'js
+  :version "24.1")
+
 (defcustom js-auto-indent-flag t
   "Whether to automatically indent when typing punctuation characters.
 If non-nil, the characters {}();,: also indent the current line
@@ -1769,14 +1790,17 @@
           ((eq (char-after) ?#) 0)
           ((save-excursion (js--beginning-of-macro)) 4)
           ((nth 1 parse-status)
+          ;; A single closing paren/bracket should be indented at the
+          ;; same level as the opening statement. Same goes for
+          ;; "case" and "default".
            (let ((same-indent-p (looking-at
                                  "[]})]\\|\\_<case\\_>\\|\\_<default\\_>"))
                  (continued-expr-p (js--continued-expression-p)))
-             (goto-char (nth 1 parse-status))
+             (goto-char (nth 1 parse-status)) ; go to the opening char
              (if (looking-at "[({[]\\s-*\\(/[/*]\\|$\\)")
-                 (progn
+                 (progn ; nothing following the opening paren/bracket
                    (skip-syntax-backward " ")
-                  (when (eq (char-before) ?\)) (backward-list))
+                   (when (eq (char-before) ?\)) (backward-list))
                    (back-to-indentation)
                    (cond (same-indent-p
                           (current-column))
@@ -1784,7 +1808,14 @@
                           (+ (current-column) (* 2 js-indent-level)
                              js-expr-indent-offset))
                          (t
-                          (+ (current-column) js-indent-level))))
+                          (+ (current-column) js-indent-level
+                             (case (char-after (nth 1 parse-status))
+                               (?\( js-paren-indent-offset)
+                               (?\[ js-square-indent-offset)
+                               (?\{ js-curly-indent-offset))))))
+               ;; If there is something following the opening
+               ;; paren/bracket, everything else should be indented at
+               ;; the same level.
                (unless same-indent-p
                  (forward-char)
                  (skip-chars-forward " \t"))


reply via email to

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