CoffeeScript auto-indent broken?


#1

I know the auto-indent library does not belong to atom per-say, however I find it ironic that CoffeeScript auto indentation does not work correctly. Does anyone know of any conflicting packages that would cause this?

atom-auto-indent Issue #5


Autoindent not working properly in python?
#2

Well, the package to which you are referring depends on Atom’s own autoIndentSelectedRows method:

So the case could be made that this is Atom’s bug. But

Given how CoffeeScript does not have any “end block” syntax other than indentation, how is an auto-indentation algorithm supposed to know when to undent a line from the line above it? Take the example in the bug. Let’s remove all the indentation and see if we can create an algorithm to correctly indent it … even given the prior knowledge of what the code is supposed to look like:

@namespace 'App.OO.Basics', ->
baseObjectKeywords = ['extended', 'included']

class @BaseObject
@extend: (obj) ->
for key, value of obj when key not in baseObjectKeywords
@[key] = value
obj.extended?.apply(0)
this
@include: (obj) ->
for key, value of obj when key not in baseObjectKeywords
#Assign properties to the prototype
@::[key] = value
obj.included?.apply(0)
this

#3

I am not really sure, maybe someone should ask jetbrains. I have never had this issue in intellij nor in sublime 2 (i guess find it’s indent algo). Should this answer not be close to identical to how python works?


#4

I guess that what it should do is to try fixing existing indentation, instead of indenting from scratch.

For example, some lines can possibly be start of a block and some can’t. Autoindent should remove indentation after lines that can’t start a block.


But in general, I aggree with @leedohm, auto-indenting coffeescript seems quite silly.


#5

Regardless how it should work the consensus that it is silly is ridiculous. Especially since the creators of this tool are pro-coffeescript. Your argument is like saying you do not need indenting help in haml, jade, or python.


#6

I wasn’t saying that indentation help for indentation-significant languages isn’t helpful, necessary or possible. I was actually attempting to get help determining the proper algorithm … or at least a better one.


#7

Ahh, any progress on this from anyone?


#8

I think the best you can do is indent to the same indent as the next line up. So, if I have:

myFunc = ->
    console.log "Hello world"
    <CURSOR HERE>

and I try to paste: x = x + 1, it should indent the x to one tab, same as the console on the line above.

Edit: Actually, it’s not as simple as that. If the line above the cursor starts with if, else, while, try, catch, when, switch, then we probably want to indent the current line one indent in from the line above.

If in doubt, do what sublime text does, which is not auto-indent coffee-script. :stuck_out_tongue:


#9

Oh, it’s not actually auto-indent that’s broken for me, it’s this: Normalize indent on paste doesn’t work as expected


#10

I was about and hoping to say thanks and I’ll have your children (jk). However, I did this and the Coffee indent problems persist. I also have these problems in Python as well.


#11

Any update here? I noticed the same issue with python as well.


#12

In v0.148.0 “Automatic indent on paste is now disabled by default in
whitespace-sensitive languages such as CoffeeScript, Python, Sass, and
YAML.” — from releases page


#13

This is driving me nuts! And worse, literally breaking code by bizarre results!

At this point, I’m looking for survival, not optimal behavior. So this is a question:

What is the *sanest* set of settings for CS indenting?

There seems to be two or three settings that may be at play. There are the standard editor settings: Auto Indent and Auto Indent On Paste. Then both of these appear in the CS package. Are there more?

Do these take effect immediately? Or do I have to quit and restart Atom?

And what are their semantics? At this point I forget what my settings have been but sometimes when I paste, all the code ends up at the far left! I can’t imagine a case where I’d want that!

I guess what I’m looking for is simply having cut/paste make no changes in indentation, simply mirror the original text at the same indent level with exactly the same relative indentation. I.e. an exact clone paste.

The test for that sort of block cut/paste would be: select some CS, and copy then paste twice. The first should simply replace the original exactly, the second create a mirror image copy.

A second solution would be to paste relative to the current cursor. I.e. copy, go to the paste site, tab into where the code should go, then get an exact past like the above, but shifted by the cursor’s indent.

This is starting to frighten me … I think its gotten worse or my settings screwed up beyond belief.

People, This is breaking code. Lets at least have a standard set of settings, a profile so t speak, that does the paste behavior I suggested above. Then we can go on from there.


#14

@backspaces There have been a number of changes to the indentation on paste functionality. You should take a look and share your feedback here:

I think that things have been improved/fixed on the latest version of Atom … but I’m not sure, I’ve been working mostly with Java and Ruby code the past few days, not CS or other indentation-sensitive languages.

To try to answer some of your questions:

To my understanding, those are all of them … and the CS ones are optional in that you only have to set them if you want them to be different from the standard ones.

As with all Atom configuration settings, they should take effect immediately. If they do not, it is a bug.


#15

My problem has nothing to do with indent on paste. Automatic indentation simply does not work. Everything keeps getting right aligned.


#16

How do I test a customized version of this library against atom? Do I use apm link or apm install? I am trying to use the regex patterns provided by sublime text to see if it fixes anything.


#17

If you mean the auto-indent package, then you would use both potentially:

  • apm install inside the cloned package directory installs any package dependencies (such as Node modules) the package might have listed in its package.json
  • apm link inside the cloned package directory creates a symlink between the cloned package directory and either ~/.atom/packages or ~/.atom/dev/packages depending on whether you want it to be loaded always or only loaded when running Atom in Dev Mode (atom --dev)

#18

Do you mean https://atom.io/packages/auto-indent ? If so that library doesn’t do much but define key shortcuts and call autoindent. So I doubt the problem is in the autoindent library. If anything it is the regex’s or in atoms editor.autoIndentSelectedRows() call.


#19

Yes, that’s the one I meant. Updated. I don’t know anything about the issue you’re talking about. I was just answering your question regarding the use of apm link and apm install.


#20

May I suggest you switch to Brackets or Sublime Text for now? I’m a big fan of Atom but had to switch temporarily because I like CoffeeScript and these two support it well in my experience. Also look into Komodo Edit and TextMate