Emacs 23.2 includes js-mode, which is a renamed and touched-up Espresso. I just did "indent-region" on your redunkulous code and got this:
var o = { foo : 'bar'
, baz : 'foo'
}
, p
, q = new Squash( o
, { start: 0
, limit: 50
}
)
I guess that's not exactly what you want. The commas are offset differently than you probably like.
(Gosh that's ugly.)
EDIT
Ok I looked into js-mode and the indentation seems to be done by js--proper-indentation
. It looks at the current line and then tries to make decisions about how to indent.
It's got a bunch of conditions it tests, for various syntax patterns. I just put in a check for a line starting with a comma, and got these results:
var o = { foo : 'bar'
, baz : 'foo'
}
, p
, q = new Squash( o
, { start: 0
, limit: 50
}
)
I think that is what you want, but it still looks totally broken to me. Anyway this is how I did it.
Inject this cond into the top of the list for js--proper-indentation
:
(defun js--proper-indentation (parse-status)
"Return the proper indentation for the current line."
(save-excursion
(back-to-indentation)
(cond
((looking-at ",")
(let ((spos
(save-excursion
(while (looking-back "}[\t\n ]*")
(backward-sexp)
(if (looking-back ",[\t\n ]*")
(re-search-backward ",[\t\n ]*")))
(cond
((looking-back "\\(,\\|(\\)[ \t]*\\<\\([^:=\n\t ]+\\)[ \t\n]*")
(re-search-backward "\\(,\\|(\\)[ \t]*\\<\\([^:=\n\t ]+\\)[ \t\n]*" (point-min) t)
(+ (current-column) 2))
((re-search-backward "\\<\\([^:=\n\t ]+\\)[ \t]*\\(:\\|=\\)" (point-min) t)
(current-column))
(t
nil)))))
(if spos
(- spos 2)
(+ js-indent-level js-expr-indent-offset))))
....
Be sure to keep the rest of the conditions in that defun - I don't know what they do but the're probably important.
No idea if this is robust, I haven't tested it except for your one test case. But this oughta get you started.