Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-indent doesn't work? #159

Closed
mindplay-dk opened this issue Mar 6, 2015 · 12 comments
Closed

Auto-indent doesn't work? #159

mindplay-dk opened this issue Mar 6, 2015 · 12 comments
Assignees

Comments

@mindplay-dk
Copy link

The only problem I have with this plugin so far, is it seems to mess up auto-indent?

Using ATOM 0.186, with "Auto Indent" enabled, "Show Indent Guide" switched on, "Tab Length" set to 4 and "Soft Tabs" enabled.

Whenever I press ENTER in the editor, the cursor positions itself at the beginning of the line.

I have no other community packages installed, just this one.

PS: Thank you for this incredible plugin! I have tried every other Typescript plugin for ATOM (typescript-atomizer, language-typescript and atom-typescript-tools) some of which threw errors, none of which were able to even auto-complete. Excellent work!

Are you getting paid for this work, or where can we donate?

@basarat basarat self-assigned this Mar 6, 2015
@basarat
Copy link
Member

basarat commented Mar 6, 2015

Are you getting paid for this work, or where can we donate?

No plan for a financial donation mechanism at the moment ❤️. It would be great if you can [leave a review on twitter](https://twitter.com/intent/tweet?text=Silky smooth TypeScript development&url=https://atom.io/packages/atom-typescript&hashtags=Atom,TypeScript&via=basarat)

ref : #66

@basarat
Copy link
Member

basarat commented Mar 6, 2015

autoindent

It doesn't work. We didn't do any special work to tweak to so it was expected. As you can see in the gif Atom is doing something for TypeScript files in that the brackets are placed correctly but you still need to indent the cursor into place. I suspect its done because of scope being source (we set the grammar scope to be source.ts). This magic done by atom is the reason why it hasn't been crucial. Going all the way with great auto-indent shouldn't be too hard if it goes according to my plan. Expect it soon.

@basarat
Copy link
Member

basarat commented Mar 6, 2015

research : https://github.com/griiin/atom-auto-indent/blob/master/lib/auto-indent.coffee

      editor = atom.workspace.activePaneItem
      cursor = editor.getCursor()
      savedPosition = cursor.getScreenPosition()
      editor.selectAll()
      editor.autoIndentSelectedRows()
      cursor = editor.getCursor()
      cursor.setScreenPosition(savedPosition)

More : editor.autoIndentBufferRow(editor.getCursorBufferPosition().row)

@basarat
Copy link
Member

basarat commented Mar 6, 2015

The non dynamic grammars get their indent settings from : https://github.com/atom/language-javascript/blob/master/settings/language-javascript.cson

basarat added a commit that referenced this issue Mar 6, 2015
@basarat
Copy link
Member

basarat commented Mar 6, 2015

Based on my last commit atom.config.get('editor.increaseIndentPattern', {scope: ['.source.ts']}) gives "(?x) \{ [^}"']* $ | \[ [^\]"']* $ | \( [^)"']* $ | case[\s\S]*: $ | default: $"

This is now same as atom.config.get('editor.increaseIndentPattern', {scope: ['.source.js']}). Previously it was really just atom.config.get('editor.increaseIndentPattern', {scope: ['.source']}) that was triggered for TS.

image

my new suspicion

Now a larger issue is that js gets tokenized seperately for each { and } as shown :
image

Whereas TS merges the two:

image

basarat added a commit that referenced this issue Mar 6, 2015
@basarat
Copy link
Member

basarat commented Mar 6, 2015

I've differentiated the punctuation. TS was classifying each seperately. Atom is just efficient to collapse adjacent similar classifications into a single DOM node. I still pushed my commit as it make it easier for us to reuse (){} js theme styles (if any).

@basarat
Copy link
Member

basarat commented Mar 6, 2015

However this was not the source of the problem and I am still looking for a solution

@basarat
Copy link
Member

basarat commented Mar 6, 2015

@basarat basarat closed this as completed in 9b9862d Mar 6, 2015
@basarat
Copy link
Member

basarat commented Mar 6, 2015

Well figured it out myself. There are plenty for dragons in writing our dynamic grammar. The tricky one here was that atom wants you to tokenize an empty line as whitespace (or anything with a name) for autoindent to work ❤️

@basarat
Copy link
Member

basarat commented Mar 6, 2015

watch it ➿ and 🔁
autoindent

@basarat
Copy link
Member

basarat commented Mar 6, 2015

v0.82.0

@mindplay-dk
Copy link
Author

Looks good! Thanks :-)

Something that confused me is, in ATOM's core settings, there's an "Auto Indent" checkbox, which apparently does nothing at all. In the "Edit" menu, in the "Lines" submenu, there's also an "Auto Indent" checkbox menu item, which doesn't appear to be the same setting - it's unchecked, even though I checked the one on the core settings screen... Anyway, checked the one in the menu, and, behold, that one actually works - the one in the core settings screen doesn't seem to have any effect at all. I wonder why there's two of these...

@TypeStrong TypeStrong locked and limited conversation to collaborators Jan 20, 2019
angelestelar5z added a commit to angelestelar5z/atom-typescript that referenced this issue Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants