Jérôme Jérôme - 3 months ago 22
CoffeeScript Question

Unmatched outdent in coffeescript code

I have made this coffeescript piece of code but I get an error during the compilation


error: unmatched OUTDENT near 'callback newResults'


$('#ticket_message_content').textcomplete([{
match: /\B:([\-+\w]*)$/,
search: (term, callback) ->
results = []
results2 = []
results3 = []

$.each(emojiStrategy, (shortname, data) ->
if shortname.indexOf(term) > -1
results.push(shortname)
else
if data.aliases isnt null && data.aliases.indexOf(term) > -1
results2.push(shortname)
else if data.keywords isnt null && data.keywords.indexOf(term) > -1
results3.push(shortname)

if term.length >= 3
results.sort((a, b) ->
return (a.length > b.length))
results2.sort((a, b) ->
return (a.length > b.length))
results3.sort()

newResults = results.concat(results2).concat(results3)
callback newResults

template: (shortname) ->
return '<img class="emojione" src="//cdn.jsdelivr.net/emojione/assets/png/' + emojiStrategy[shortname].unicode + '.png"> :' + shortname + ':'

replace: (shortname) ->
return ':' + shortname + ': '

index: 1,
maxCount: 10
}], {
footer: '<a href="http://www.emoji.codes" target="_blank">Browse All<span class="arrow">ยป</span></a>'
})


I understand the error but I don't see any problem in the syntax/indent.

My first though was there is no comma after the
search
function, but the code is good when I delete all
search
function content.

This is what I'm trying to do in coffeescript

$('#ticket_message_content').textcomplete([{
match: /\B:([\-+\w]*)$/,
search: function(term, callback){},
template: function (shortname) {},
replace: function (shortname) {},
index: 1,
maxCount: 10
}]);


Thanks for your help

Answer

You have an opening parenthesis on this line:

$.each(emojiStrategy, (shortname, data) ->

But there is no matching closing parenthesis. The unmatched outdent error is displayed at the last possible line where you could close it before it causes a syntax error. Either omit the opening parenthesis or close it at the right location.