Giter Club home page Giter Club logo

Comments (26)

dgutov avatar dgutov commented on July 23, 2024

Did you try bounce-indent?
(setq js2-bounce-indent-p t)
(setq js2-auto-indent-p nil)
;; should be set before js2-mode is loaded
It's not automatic, but should be workable.

from js2-mode.

joshrtay avatar joshrtay commented on July 23, 2024

Thanks for the quick response.

It works, but isn't great. Takes 3-4 tabs to get line to the right spot.

If you reversed the order of bounce tab or provided shift-tab to bounce in
reverse order, then it would be workable.

On Tue, Mar 22, 2011 at 7:09 AM, dgutov <
[email protected]>wrote:

Did you try bounce-indent?
(setq js2-bounce-indent-p t)
(setq js2-auto-indent-p nil)
;; should be set before js2-mode is loaded
It's not automatic, but should be workable.

Reply to this email directly or view it on GitHub:
#9 (comment)

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

Ok, see if this helps: dgutov/js2-mode@9e8d316f98ee52d9a982dcda22d46a5d4e24bede

I could also sort positions by indent amount.

from js2-mode.

joshrtay avatar joshrtay commented on July 23, 2024

That helps. Thanks.

Sorting indent by position makes a lot of sense.

On Wed, Mar 23, 2011 at 5:38 AM, dgutov <
[email protected]>wrote:

Ok, see if this helps:
dgutov/js2-mode@9e8d316f98ee52d9a982dcda22d46a5d4e24bede

I could also sort positions by indent amount.

Reply to this email directly or view it on GitHub:
#9 (comment)

from js2-mode.

magnars avatar magnars commented on July 23, 2024

There's also a js3-mode: https://github.com/thomblake/js3-mode

From the project page:

A chimeric fork of js-mode (included with emacs 24) and js2-mode that supports comma-first style and other quirks.

The goal of this project was to get a javascript mode working that supports npm style, but it turns out this mode is compatible with other styles as well.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

@magnars I've tried it but there are some quirks, e.g. this one tamzinblake/js3-mode#76

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

I don't write JS comma-first, but here's a small patch that should work, to some extent: https://gist.github.com/4677890/ae2443093d294704c2536f0ae6722d327a5148a5

Are there many cases it doesn't handle?

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

@dgutov It works almost like I want it to, but if I have basic offset set to 2, I want the commas to be indented 2 extra spaces in e.g. an object literal (using '(js2-pretty-multiline-declarations 'all) in .emacs). Example:

var foo = function () {
      return 'foo'
    }

  , bar = function () {
      return 'bar'
    }

var obj1 = {
      name: 'magnus'
    , age: 40
    }

  , obj2 = {
      name: 'magnus'
    , age: 41
    }

The return statements in the functions are properly indented, but the properties in the object literals should have one level of indentation more:

var obj1 = {
        name: 'magnus'
      , age: 40
    }

  , obj2 = {
        name: 'magnus'
      , age: 41
    }

The reason for this is for symmetry, the properties should be aligned with respect to obj2 as ', obj2' is aligned with respect to the leftmost position. And the same with arrays obviously.

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

So, an extra two spaces just to see the comma in the center of an indent rectangle? Doesn't seem too useful to me.
But for the sake of the argument, could you point to a code example in the wild, like in Node or something?
Also, with offset 4, would that also be 4 extra spaces?

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

I also like the same type of indentation when invoking a function and putting the arguments to the function on multiple lines, e.g.

var foo = function (options, param) {
      return ifOptionsHaveBlahSet(options)
        ? doSomeStuffWithOptionsAndParam(
              options  // <--
            , param    // <--
          )
        : options
    }

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

Here's an example file: https://github.com/rvagg/node-levelup/blob/master/lib/levelup.js#L19-L35

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

So, this was more complicated: https://gist.github.com/4677890

I'm probably not going to commit this to either of the main branches, but if you ever have a problem with applying/merging this, feel free to ping me.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

@dgutov magnus@emachines|16:10|~/src/js2-mode (emacs24) $ emacs --batch -f
batch-byte-compile js2-mode.el

In end of data:
js2-mode.el:11402:1:Warning: the function `beginning-of-thing' is not known
to
be defined.
Wrote /home/magnus/src/js2-mode/js2-mode.elc

On 31 January 2013 03:17, Dmitry Gutov [email protected] wrote:

So, this was more complicated: https://gist.github.com/4677890

I'm probably not going to commit this to either of the main branches, but
if you ever have a problem with applying/merging this, feel free to ping me.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-12924359.

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

Missing require added.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

@dgutov It works perfectly! I'm very grateful for your help. Thank you very much! I'll commit this to a branch of my own, in case there is someone else that wants the same functionality.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

The patch can be found on this branch in my repository, in case someone else is interested. https://github.com/ralphtheninja/js2-mode/tree/emacs24-comma-first

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

No problem!

I'm sure it's less than perfect (some of js3-mode's test cases look pretty daunting), but the patch should provide a starting point for you or anyone else who would like to improve it.

Also note that the patch itself has somewhat broken indentation inside the first (+ ... form, mainly so that the changes are easier to see, and it's more resilient against future changes in js2-proper-indentation. Not sure if you should change that.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

I'm just happy to get this working for now. Need to improve my emacs lisp
skillz so I can start contributing :)

On 31 January 2013 16:41, Dmitry Gutov [email protected] wrote:

No problem!

I'm sure it's less than perfect (some of js3-mode's test cases look pretty
daunting), but the patch should provide a starting point for you or anyone
else who would like to improve it.

Also note that the patch itself has a bit of a broken indentation inside
the first (+ ... form, mainly so that the changes are easier to see, and
it's more resilient against future changes in js2-proper-indentation. Not
sure if you should change that.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-12948259.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

Found an issue. Apparently the else-case get the wrong indentation:

if (true) {
  console.log('true')
} else {
    console.log('false')
}

I tested that this works on the emacs24 branch.

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

Uh, that's unfortunate. :)

See da2a0be.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

Thanks a million! :)

On 2 February 2013 23:19, Dmitry Gutov [email protected] wrote:

Uh, that's unfortunate. :)

See da2a0behttps://github.com/mooz/js2-mode/commit/da2a0be26c81bc4fce3163d338d7237ff0b9aabd
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/9#issuecomment-13038408.

from js2-mode.

ralphtheninja avatar ralphtheninja commented on July 23, 2024

@dgutov I rebased my emacs24-comma-first branch onto your updated master and renamed it comma-first, in case you want to fetch it from me.

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

Sure, thanks.

from js2-mode.

ashnur avatar ashnur commented on July 23, 2024

Guess I should travel back in time in 2013.

from js2-mode.

dgutov avatar dgutov commented on July 23, 2024

2013 was a good year.

from js2-mode.

ashnur avatar ashnur commented on July 23, 2024

Last year I tried to merge the master into the comma-first branch, but it did not turned out well :(

from js2-mode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.