Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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: </p> <pre><code>var o = { foo : 'bar' , baz : 'foo' } , p , q = new Squash( o , { start: 0 , limit: 50 } ) </code></pre> <p>I guess that's not exactly what you want. The commas are offset differently than you probably like. </p> <p>(Gosh that's ugly.)</p> <hr> <p><strong>EDIT</strong><br> Ok I looked into js-mode and the indentation seems to be done by <code>js--proper-indentation</code>. It looks at the current line and then tries to make decisions about how to indent. </p> <p>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: </p> <pre><code>var o = { foo : 'bar' , baz : 'foo' } , p , q = new Squash( o , { start: 0 , limit: 50 } ) </code></pre> <p>I think that is what you want, but it still looks totally broken to me. Anyway this is how I did it. </p> <p>Inject this cond into the top of the list for <code>js--proper-indentation</code>: </p> <pre><code>(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]*\\&lt;\\([^:=\n\t ]+\\)[ \t\n]*") (re-search-backward "\\(,\\|(\\)[ \t]*\\&lt;\\([^:=\n\t ]+\\)[ \t\n]*" (point-min) t) (+ (current-column) 2)) ((re-search-backward "\\&lt;\\([^:=\n\t ]+\\)[ \t]*\\(:\\|=\\)" (point-min) t) (current-column)) (t nil))))) (if spos (- spos 2) (+ js-indent-level js-expr-indent-offset)))) .... </code></pre> <p>Be sure to keep the rest of the conditions in that defun - I don't know what they do but the're probably important. </p> <p>No idea if this is robust, I haven't tested it except for your one test case. But this oughta get you started. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload