Subject: bug#15956: 24.3.50; js.el: Indentation for control statements

From: Mihir Rege <[email-masked]>
Date: Sat, 23 Nov 2013 03:44:39 +0530

Hi,

If a control statement is the first statement in the source but is not on
the first line, the indentation keeps on increasing with each call.

For example:

---------------------------
//comment
if ( cond )
---------------------------

will indent to

---------------------------
//comment
        if (cond)
---------------------------

I have enclosed a patch that fixes the problem.

-- 
Mihir Rege
From e7ad799f7360eebc9b93176c3ce321967afc535e Mon Sep 17 00:00:00 2001
From: Mihir Rege <[email-masked]>
Date: Sat, 23 Nov 2013 03:14:27 +0530
Subject: [PATCH] Fix indentation for control statements

---
 lisp/ChangeLog       | 5 +++++
 lisp/progmodes/js.el | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 50e2ff6..ec356a5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2013-11-22  Mihir Rege  <[email-masked]>
+
+	* progmodes/js.el (js--ctrl-statement-indentation): Fix indent
+	if control-statement is first statement in buffer.
+
 2013-11-22  Leo Liu  <[email-masked]>
 
 	* progmodes/octave.el (inferior-octave-startup): Spit out error
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 49a2193..17c1360 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1749,8 +1749,8 @@ nil."
     (when (save-excursion
             (and (not (eq (point-at-bol) (point-min)))
                  (not (looking-at "[{]"))
+                 (js--re-search-backward "[[:graph:]]" nil t)
                  (progn
-                   (js--re-search-backward "[[:graph:]]" nil t)
                    (or (eobp) (forward-char))
                    (when (= (char-before) ?\)) (backward-list))
                    (skip-syntax-backward " ")
-- 
1.8.1.2