mwarrenus / js2-mode

Automatically exported from code.google.com/p/js2-mode
0 stars 0 forks source link

Extra indentation in object literal of lines with slot name IN #93

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use IN as a field name in a literal object. E.g.

var foo = {
  X : 10,
  IN : 20,
  OUT : 30,
  Y : 40
};

2. Indent lines with <TAB> (with bounce-mode indentation turned off)

3. Note that the IN line gets indented extra.

What is the expected output? What do you see instead?

I see this:

var foo = {
  X : 10,
    IN : 20,
  OUT : 30,
  Y : 40
};

I expect this:

var foo = {
  X : 10,
  IN : 20,
  OUT : 30,
  Y : 40
};

What version of the product are you using? On what operating system?

js2-20080616a.el on GNU Emacs 22.0.99.1 (powerpc-apple-darwin8.9.0, Carbon
Version 1.6.0) of 2007-05-06 on beagle

Please provide any additional information below.

I'm guessing that may have something to do with 'in' being a keyword. But
unless I'm confused Javascript is case sensitive so 'IN' should not be
treated specially. On the other hand, a quick look through the source
didn't show up any obvious places where case is ignored or smashed so that
guess may be totally wrong. And if I change the IN to say FOR or WHILE it
still indents correctly, so it's not all upcased keywords that are a prooblem.

Original issue reported on code.google.com by peter.se...@gmail.com on 6 Nov 2008 at 5:06

GoogleCodeExporter commented 9 years ago
Here's a patch that seems to fix the problem:

--- /Users/peter/Desktop/js2-20080616a.el   2008-11-06 08:11:37.000000000 -0800
+++ js2.el  2008-11-06 23:09:19.000000000 -0800
@@ -9985,11 +9985,12 @@
   "Return non-nil if text after point is an operator (that is not
 a comma)."
   (save-match-data
-    (and (looking-at js-indent-operator-re)
-         (or (not (looking-at ":"))
-             (save-excursion
-               (and (js-re-search-backward "[?:{]\\|\\<case\\>" nil t)
-                    (looking-at "?")))))))
+    (let ((case-fold-search nil))
+      (and (looking-at js-indent-operator-re)
+      (or (not (looking-at ":"))
+          (save-excursion
+        (and (js-re-search-backward "[?:{]\\|\\<case\\>" nil t)
+             (looking-at "?"))))))))

 (defun js-continued-expression-p ()
   "Returns non-nil if the current line continues an expression."

Original comment by peter.se...@gmail.com on 7 Nov 2008 at 7:10