Can't get the loop working in


I’m trying to get a custom command into to run multiple regex replaces consequently. Here is what I’m trying:

atom.commands.add 'atom-text-editor', 'custom:process-report', ->
  editor = atom.workspace.getActiveTextEditor()
  regs[0] = /""(?!;)/g
  res[0]="'" # double quotes to single
  regs[1] = /;"([A-Z])/g
  res[1]=";$1" # quoted descriptions
  for (i=0,len=regs.length;i<len;i++){
     editor.scan(regs[i], (match) -> match.replace(res[i]))

Upon loading I get

Failed to load C:\Users\Vitaly.Sokolov\.atom\
unexpected (

Syntax is more or less taken from the CoffeeScript documentation. What am I doing wrong? Are loops not supported in the How do I do it properly then? I have about 7 regex to implement and I don’t want to hard-code variables for them.



You are mixing Coffeescript and Javascript with each other. Web search how a for-loop looks like in Coffeescript. example

Else… if you could import Javascript code into your would it help you? LINK



This is the part that’s causing an error. CoffeeScript doesn’t use parentheses in its for loops. You should write it like this:

for i in [0..regs.length]
  editor.scan(regs[i], (match) -> match.replace(res[i]))


CoffeeScript on the left, compiled JavaScript output on the right. - missed that part, went with more familiar example on the right


(smile) No worries friend. It happens - especially when working alone.
Thank you for your reply. Good luck.