Emacs 23.2 includes js-mode, which is a renamed and touched espresso. I just did "indent-region" on your reddish code and got the following:
var o = { foo : 'bar' , baz : 'foo' } , p , q = new Squash( o , { start: 0 , limit: 50 } )
I suppose that is not quite what you want. These commas are offset differently than you like.
(Gosh, that's ugly.)
EDIT
Ok, I looked in js-mode, and the indentation seems to be done using js--proper-indentation . He looks at the current line and then tries to make a decision on how to backtrack.
He got a bunch of conditions that he is testing for various syntax patterns. I just put the check on the line starting with a comma and got the following results:
var o = { foo : 'bar' , baz : 'foo' } , p , q = new Squash( o , { start: 0 , limit: 50 } )
I think this is what you want, but it still looks completely broken for me. In any case, that's what I did.
Paste this cond at 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 follow the rest of the conditions in this defun - I don't know what they are doing, but probably important.
I donβt know how safe it is, I have not tested it, except for one test case. But it should begin.