// Compiled by ClojureScript 0.0-2138
goog.provide('lt.plugins.auto_paren');
goog.require('cljs.core');
goog.require('lt.objs.keyboard');
goog.require('lt.objs.context');
goog.require('lt.objs.context');
goog.require('lt.objs.editor.pool');
goog.require('lt.objs.command');
goog.require('lt.objs.keyboard');
goog.require('lt.objs.editor');
goog.require('lt.object');
goog.require('lt.object');
goog.require('lt.objs.editor');
goog.require('lt.objs.editor.pool');
goog.require('lt.objs.command');
goog.require('lt.objs.keyboard');
lt.plugins.auto_paren.pairs = new cljs.core.PersistentArrayMap(null, 5, ["(",")","{","}","[","]","\"","\"","<",">"], null);
lt.plugins.auto_paren.word_char = /[^\s\)\}\]\(\{\[]/;
lt.plugins.auto_paren.adjust_loc = (function adjust_loc(loc,dir){return cljs.core.update_in.call(null,loc,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"ch","ch",1013907415)], null),cljs.core._PLUS_,dir);
});
lt.plugins.auto_paren.get_char = (function get_char(ed,dir){var loc = lt.objs.editor.__GT_cursor.call(null,ed);if((dir > 0))
{return lt.objs.editor.range.call(null,ed,loc,lt.plugins.auto_paren.adjust_loc.call(null,loc,dir));
} else
{return lt.objs.editor.range.call(null,ed,lt.plugins.auto_paren.adjust_loc.call(null,loc,dir),loc);
}
});
lt.plugins.auto_paren.move_cursor = (function move_cursor(ed,dir){var loc = lt.objs.editor.__GT_cursor.call(null,ed);return lt.objs.editor.move_cursor.call(null,ed,lt.plugins.auto_paren.adjust_loc.call(null,loc,dir));
});
lt.plugins.auto_paren.__BEH__open_pair = (function __BEH__open_pair(this$,ch){return lt.objs.editor.operation.call(null,this$,(function (){var current_selection = lt.objs.editor.selection.call(null,this$);if(!(cljs.core._EQ_.call(null,current_selection,"")))
{return lt.objs.editor.replace_selection.call(null,this$,[cljs.core.str(ch),cljs.core.str(current_selection),cljs.core.str(lt.plugins.auto_paren.pairs.call(null,ch))].join(''),new cljs.core.Keyword(null,"around","around",3899636031));
} else
{if(cljs.core.truth_(cljs.core.re_seq.call(null,lt.plugins.auto_paren.word_char,lt.plugins.auto_paren.get_char.call(null,this$,1))))
{return lt.objs.editor.insert_at_cursor.call(null,this$,ch);
} else
{lt.objs.editor.insert_at_cursor.call(null,this$,[cljs.core.str(ch),cljs.core.str(lt.plugins.auto_paren.pairs.call(null,ch))].join(''));
return lt.plugins.auto_paren.move_cursor.call(null,this$,-1);
}
}
}));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.plugins.auto-paren","open-pair","lt.plugins.auto-paren/open-pair",1001093559),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.plugins.auto_paren.__BEH__open_pair,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"open-pair!","open-pair!",4565354166),null], null), null));
lt.plugins.auto_paren.__BEH__close_pair = (function __BEH__close_pair(this$,ch){if(cljs.core._EQ_.call(null,ch,lt.plugins.auto_paren.get_char.call(null,this$,1)))
{return lt.plugins.auto_paren.move_cursor.call(null,this$,1);
} else
{return lt.objs.keyboard.passthrough.call(null);
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.plugins.auto-paren","close-pair","lt.plugins.auto-paren/close-pair",4607377033),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.plugins.auto_paren.__BEH__close_pair,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"close-pair!","close-pair!",4389766116),null], null), null));
lt.plugins.auto_paren.__BEH__repeat_pair = (function __BEH__repeat_pair(this$,ch){return lt.objs.editor.operation.call(null,this$,(function (){var current_selection = lt.objs.editor.selection.call(null,this$);if(!(cljs.core._EQ_.call(null,current_selection,"")))
{return lt.objs.editor.replace_selection.call(null,this$,[cljs.core.str(ch),cljs.core.str(current_selection),cljs.core.str(ch)].join(''));
} else
{if(cljs.core._EQ_.call(null,ch,lt.plugins.auto_paren.get_char.call(null,this$,1)))
{return lt.plugins.auto_paren.move_cursor.call(null,this$,1);
} else
{if(cljs.core.truth_(cljs.core.re_seq.call(null,lt.plugins.auto_paren.word_char,lt.plugins.auto_paren.get_char.call(null,this$,1))))
{return lt.objs.editor.insert_at_cursor.call(null,this$,ch);
} else
{if(cljs.core.truth_(cljs.core.re_seq.call(null,lt.plugins.auto_paren.word_char,lt.plugins.auto_paren.get_char.call(null,this$,-1))))
{return lt.objs.editor.insert_at_cursor.call(null,this$,ch);
} else
{if(new cljs.core.Keyword(null,"else","else",1017020587))
{lt.objs.editor.insert_at_cursor.call(null,this$,[cljs.core.str(ch),cljs.core.str(ch)].join(''));
return lt.plugins.auto_paren.move_cursor.call(null,this$,-1);
} else
{return null;
}
}
}
}
}
}));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.plugins.auto-paren","repeat-pair","lt.plugins.auto-paren/repeat-pair",948310982),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.plugins.auto_paren.__BEH__repeat_pair,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"repeat-pair!","repeat-pair!",1856851271),null], null), null));
lt.plugins.auto_paren.__BEH__try_remove_pair = (function __BEH__try_remove_pair(this$){if(cljs.core.not.call(null,lt.objs.editor.selection_QMARK_.call(null,this$)))
{var ch = lt.plugins.auto_paren.get_char.call(null,this$,-1);if(cljs.core.truth_((function (){var and__3508__auto__ = lt.plugins.auto_paren.pairs.call(null,ch);if(cljs.core.truth_(and__3508__auto__))
{return cljs.core._EQ_.call(null,lt.plugins.auto_paren.get_char.call(null,this$,1),lt.plugins.auto_paren.pairs.call(null,ch));
} else
{return and__3508__auto__;
}
})()))
{var loc = lt.objs.editor.__GT_cursor.call(null,this$);lt.objs.editor.replace.call(null,this$,lt.plugins.auto_paren.adjust_loc.call(null,loc,-1),lt.plugins.auto_paren.adjust_loc.call(null,loc,1),"");
return lt.objs.keyboard.stop_commands_BANG_.call(null);
} else
{return lt.objs.keyboard.passthrough.call(null);
}
} else
{return lt.objs.keyboard.passthrough.call(null);
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.plugins.auto-paren","try-remove-pair","lt.plugins.auto-paren/try-remove-pair",1181077163),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.plugins.auto_paren.__BEH__try_remove_pair,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"backspace!","backspace!",4317945588),null], null), null));
lt.objs.command.command.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"command","command",1964298941),new cljs.core.Keyword(null,"editor.close-pair","editor.close-pair",2068601890),new cljs.core.Keyword(null,"hidden","hidden",4091384092),true,new cljs.core.Keyword(null,"desc","desc",1016984067),"Editor: Close pair character",new cljs.core.Keyword(null,"exec","exec",1017031683),(function (c){return lt.object.raise.call(null,lt.objs.context.__GT_obj.call(null,new cljs.core.Keyword(null,"editor.keys.normal","editor.keys.normal",2927389330)),new cljs.core.Keyword(null,"close-pair!","close-pair!",4389766116),c);
})], null));
lt.objs.command.command.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"command","command",1964298941),new cljs.core.Keyword(null,"editor.open-pair","editor.open-pair",4001431726),new cljs.core.Keyword(null,"hidden","hidden",4091384092),true,new cljs.core.Keyword(null,"desc","desc",1016984067),"Editor: Open pair character",new cljs.core.Keyword(null,"exec","exec",1017031683),(function (c){return lt.object.raise.call(null,lt.objs.context.__GT_obj.call(null,new cljs.core.Keyword(null,"editor.keys.normal","editor.keys.normal",2927389330)),new cljs.core.Keyword(null,"open-pair!","open-pair!",4565354166),c);
})], null));
lt.objs.command.command.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"command","command",1964298941),new cljs.core.Keyword(null,"editor.repeat-pair","editor.repeat-pair",1820110909),new cljs.core.Keyword(null,"hidden","hidden",4091384092),true,new cljs.core.Keyword(null,"desc","desc",1016984067),"Editor: Repeat pair character",new cljs.core.Keyword(null,"exec","exec",1017031683),(function (c){return lt.object.raise.call(null,lt.objs.context.__GT_obj.call(null,new cljs.core.Keyword(null,"editor.keys.normal","editor.keys.normal",2927389330)),new cljs.core.Keyword(null,"repeat-pair!","repeat-pair!",1856851271),c);
})], null));
lt.objs.command.command.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"command","command",1964298941),new cljs.core.Keyword(null,"editor.backspace-pair","editor.backspace-pair",3593263483),new cljs.core.Keyword(null,"hidden","hidden",4091384092),true,new cljs.core.Keyword(null,"desc","desc",1016984067),"Editor: Pair aware backspace",new cljs.core.Keyword(null,"exec","exec",1017031683),(function (c){return lt.object.raise.call(null,lt.objs.context.__GT_obj.call(null,new cljs.core.Keyword(null,"editor.keys.normal","editor.keys.normal",2927389330)),new cljs.core.Keyword(null,"backspace!","backspace!",4317945588),c);
})], null));
lt.plugins.auto_paren.pre_cursor_indent = (function pre_cursor_indent(ed,p__14142){var map__14144 = p__14142;var map__14144__$1 = ((cljs.core.seq_QMARK_.call(null,map__14144))?cljs.core.apply.call(null,cljs.core.hash_map,map__14144):map__14144);var ch = cljs.core.get.call(null,map__14144__$1,new cljs.core.Keyword(null,"ch","ch",1013907415));var line = cljs.core.get.call(null,map__14144__$1,new cljs.core.Keyword(null,"line","line",1017226086));var tabs = lt.objs.editor.option.call(null,ed,new cljs.core.Keyword(null,"indentWithTabs","indentWithTabs",4541079970));var unit = lt.objs.editor.option.call(null,ed,new cljs.core.Keyword(null,"indentUnit","indentUnit",1493236674));var precursor = lt.objs.editor.line.call(null,ed,line).substring(0,ch);var whitespace = cljs.core.count.call(null,cljs.core.re_find.call(null,(cljs.core.truth_(tabs)?/^\t*$/:/^ *$/),precursor));return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.quot.call(null,whitespace,unit),cljs.core.mod.call(null,whitespace,unit)], null);
});
lt.plugins.auto_paren.backspace_indent = (function backspace_indent(ed){if(cljs.core.not.call(null,(function (){var or__3520__auto__ = lt.objs.editor.selection_QMARK_.call(null,ed);if(cljs.core.truth_(or__3520__auto__))
{return or__3520__auto__;
} else
{return (lt.objs.editor.__GT_cm_ed.call(null,ed).getSelections().length > 1);
}
})()))
{var cursor = lt.objs.editor.__GT_cursor.call(null,ed);var unit = lt.objs.editor.option.call(null,ed,new cljs.core.Keyword(null,"indentUnit","indentUnit",1493236674));var vec__14147 = lt.plugins.auto_paren.pre_cursor_indent.call(null,ed,cursor);var indent = cljs.core.nth.call(null,vec__14147,0,null);var rem = cljs.core.nth.call(null,vec__14147,1,null);var cursor__$1 = (((rem > 0))?lt.plugins.auto_paren.adjust_loc.call(null,lt.objs.editor.__GT_cursor.call(null,ed),(unit - rem)):cursor);var vec__14148 = (((rem > 0))?lt.plugins.auto_paren.pre_cursor_indent.call(null,ed,cursor__$1):new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [indent,rem], null));var indent__$1 = cljs.core.nth.call(null,vec__14148,0,null);var rem__$1 = cljs.core.nth.call(null,vec__14148,1,null);if(((indent__$1 > 0)) && ((rem__$1 === 0)))
{lt.objs.editor.replace.call(null,ed,lt.plugins.auto_paren.adjust_loc.call(null,cursor__$1,(- unit)),cursor__$1,"");
return lt.objs.keyboard.stop_commands_BANG_.call(null);
} else
{return lt.objs.keyboard.passthrough.call(null);
}
} else
{return lt.objs.keyboard.passthrough.call(null);
}
});
lt.objs.command.command.call(null,new cljs.core.PersistentArrayMap(null, 4, [new cljs.core.Keyword(null,"command","command",1964298941),new cljs.core.Keyword(null,"editor.backspace-indent","editor.backspace-indent",1393448845),new cljs.core.Keyword(null,"hidden","hidden",4091384092),true,new cljs.core.Keyword(null,"desc","desc",1016984067),"Editor: Indent aware backspace",new cljs.core.Keyword(null,"exec","exec",1017031683),(function (){return lt.plugins.auto_paren.backspace_indent.call(null,lt.objs.context.__GT_obj.call(null,new cljs.core.Keyword(null,"editor.keys.normal","editor.keys.normal",2927389330)));
})], null));
