Comments (26)
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.
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.
Ok, see if this helps: dgutov/js2-mode@9e8d316f98ee52d9a982dcda22d46a5d4e24bede
I could also sort positions by indent amount.
from js2-mode.
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@9e8d316f98ee52d9a982dcda22d46a5d4e24bedeI could also sort positions by indent amount.
Reply to this email directly or view it on GitHub:
#9 (comment)
from js2-mode.
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.
@magnars I've tried it but there are some quirks, e.g. this one tamzinblake/js3-mode#76
from js2-mode.
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.
@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.
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.
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.
Here's an example file: https://github.com/rvagg/node-levelup/blob/master/lib/levelup.js#L19-L35
from js2-mode.
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.
@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.
Missing require added.
from js2-mode.
@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.
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.
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.
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.
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.
Uh, that's unfortunate. :)
See da2a0be.
from js2-mode.
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.
@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.
Sure, thanks.
from js2-mode.
Guess I should travel back in time in 2013.
from js2-mode.
2013 was a good year.
from js2-mode.
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)
- Syntax highlighting only applied after edit HOT 20
- Omitting parentheses and identifiers of CATCH should not raise errors HOT 1
- forward-sexp and backward-sexp are incoherent HOT 1
- Imenu support for mocha-like test files HOT 8
- private method and private property are not indenting HOT 2
- How to disable syntax highlight. HOT 2
- Make "Code has no side effects" warning optional HOT 2
- HTML tag regex inadvertently matches types. HOT 2
- js2-PRIVATE_NAME is breaking js2-skip-preprocessor-directives HOT 7
- No code highlighting without menu-bar? HOT 6
- Using '#' pound sign for 'private' properties in a .js file causes syntax issues to not be highlighted HOT 6
- Possible bug with js2-node-abs-pos and `new` expressions HOT 3
- Escaped expressions containing a real expression in a template literal inside a a lambda inside a class method break the parser HOT 2
- Static blocks not recognised as valid code HOT 2
- Does js2-mode become obsolete in Emacs 27.1? Or that the latest stable is not available via ELPA / MELPA? HOT 1
- Update README.md to explain the differences (incl. benefits and caveats) of `js2-mode` versus other packages HOT 11
- js2-mode doesn't recognize LS and PS line endings, leading to incorrect syntax highlighting HOT 6
- js2-mode does not recognize asynchronous generators within class or object HOT 3
- New static initialization blocks support has problems with named IIFE and 'use strict' HOT 4
- Feature request: insert closing delimiter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js2-mode.