0

When setting the js-indent-level to 4, my code is aligned in (1-based) columns 4, 8, 12, 16, ...

To me this makes perfect sense, but unfortunately I'm sharing code with others whose editors interpret such an indentation level to mean the code should align at (1-based) columns 5, 9, 13, 17, ...

Still more unfortunately, an automated style checker rejects code that is not aligned in those latter columns.

Can anyone help me configure javascript mode (or emacs in general) to align the code at (1-based) columns 5, 9, 13, 17, ... ?

EDIT

Some example code followed by the complaints from jshint:

/**
 * Foo header
 *
 * @module widgets/foo/views/foo-header-view
 */
define(["classes/layout",
        "services/foo-service",
        "utils/util",
        "hbs!widgets/foo/templates/foo-header"
       ],
       function (Layout, FooService, util, headerTmpl) {
           /**
            * Foo Header View
            */
           var FooHeaderView = Layout.extend({
               /**
                * Header template
                *
                * @property Template
                * @type {Template}
                */
               template: headerTmpl,

               hubEvents: {
                   "foo:list:change": "_reloadData"
               },

               initialize: function () {
                   this.foo = null;
                   this.fooService = FooService.getInstance();
               }
           });
           return FooHeaderView;
       });



[L15:C12] W015: Expected 'var' to have an indentation at 13 instead at 12.
           var FooHeaderView = Layout.extend({
[L22:C16] W015: Expected 'template' to have an indentation at 17 instead at 16.
               template: headerTmpl,
[L24:C16] W015: Expected 'hubEvents' to have an indentation at 17 instead at 16.
               hubEvents: {
[L25:C20] W015: Expected 'foo:list:change' to have an indentation at 21 instead at 20.
                   "foo:list:change": "_reloadData"
[L26:C16] W015: Expected '}' to have an indentation at 17 instead at 16.
               },
[L28:C16] W015: Expected 'initialize' to have an indentation at 17 instead at 16.
               initialize: function () {
[L29:C20] W015: Expected 'this' to have an indentation at 21 instead at 20.
                   this.foo = null;
[L30:C20] W015: Expected 'this' to have an indentation at 21 instead at 20.
                   this.fooService = FooService.getInstance();
[L31:C16] W015: Expected '}' to have an indentation at 17 instead at 16.
               }
[L32:C12] W015: Expected '}' to have an indentation at 13 instead at 12.
           });
[L33:C12] W015: Expected 'return' to have an indentation at 13 instead at 12.
           return FooHeaderView;
[L34:C8] W015: Expected '}' to have an indentation at 9 instead at 8.
  • js.el provides a few offset customizations, does setting js-expr-indent-offset, js-paren-indent-offset, js-square-indent-offset, js-curly-indent-offset and js-switch-indent-offset to 1 achieve the desired result? – wasamasa Mar 30 '15 at 9:42
  • Thanks @wasamasa, definitely a good avenue to explore. Setting all of them to 1 isn't quite giving me what I need, but it does change things up, so let's see if the right combination of settings will do it. – jas Mar 30 '15 at 10:16
  • Emacs's indentation normally doesn't care about absolute column numbers, so to fix your problem, you need to look elsewhere. Show us some sample code where the indentation is not as you need it. – Stefan Mar 30 '15 at 14:08
  • Thanks, @Stefan, I've added a concrete example of what's tripping me up. – jas Mar 30 '15 at 15:38
  • Well, that indentation sample looks normal, and reindent in Emacs-24.4 doesn't modify it. So I don't see where is the problem. – Stefan Mar 30 '15 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.