// Compiled by ClojureScript 0.0-2138
goog.provide('lt.objs.editor.file');
goog.require('cljs.core');
goog.require('lt.objs.files');
goog.require('lt.objs.notifos');
goog.require('lt.objs.notifos');
goog.require('clojure.string');
goog.require('lt.objs.command');
goog.require('lt.objs.files');
goog.require('clojure.string');
goog.require('lt.objs.editor');
goog.require('lt.object');
goog.require('lt.object');
goog.require('lt.objs.command');
goog.require('lt.objs.document');
goog.require('lt.objs.editor');
goog.require('lt.objs.document');
lt.objs.editor.file.__BEH__file_save = (function __BEH__file_save(editor){var map__11259 = cljs.core.deref.call(null,editor).call(null,new cljs.core.Keyword(null,"info","info",1017141280));var map__11259__$1 = ((cljs.core.seq_QMARK_.call(null,map__11259))?cljs.core.apply.call(null,cljs.core.hash_map,map__11259):map__11259);var path = cljs.core.get.call(null,map__11259__$1,new cljs.core.Keyword(null,"path","path",1017337751));var final$ = lt.object.raise_reduce.call(null,editor,new cljs.core.Keyword(null,"save+","save+",1123115456),lt.objs.editor.__GT_val.call(null,editor));if(cljs.core.not_EQ_.call(null,final$,lt.objs.editor.__GT_val.call(null,editor)))
{var y_position_11260 = lt.objs.editor.__GT_cm_ed.call(null,editor).getScrollInfo().top;lt.objs.editor.set_val_and_keep_cursor.call(null,editor,final$);
lt.objs.editor.scroll_to.call(null,editor,0,y_position_11260);
} else
{}
return lt.objs.document.save.call(null,path,final$,(function (){lt.object.merge_BANG_.call(null,editor,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"dirty","dirty",1109497668),false,new cljs.core.Keyword(null,"editor.generation","editor.generation",4482163627),lt.objs.editor.__GT_generation.call(null,editor)], null));
lt.object.raise.call(null,editor,new cljs.core.Keyword(null,"saved","saved",1123115513));
return lt.object.raise.call(null,editor,new cljs.core.Keyword(null,"clean","clean",1108650427));
}));
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.editor.file","file-save","lt.objs.editor.file/file-save",3045255915),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.editor.file.__BEH__file_save,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"save","save",1017427183),null], null), null));
lt.objs.editor.file.__BEH__dirty_on_change = (function __BEH__dirty_on_change(obj){var dirty_QMARK_ = lt.objs.editor.dirty_QMARK_.call(null,obj,new cljs.core.Keyword(null,"editor.generation","editor.generation",4482163627).cljs$core$IFn$_invoke$arity$2(cljs.core.deref.call(null,obj),0));if(cljs.core.not_EQ_.call(null,new cljs.core.Keyword(null,"dirty","dirty",1109497668).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,obj)),dirty_QMARK_))
{if(dirty_QMARK_)
{lt.object.merge_BANG_.call(null,obj,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"dirty","dirty",1109497668),true], null));
return lt.object.raise.call(null,obj,new cljs.core.Keyword(null,"dirty","dirty",1109497668));
} else
{lt.object.merge_BANG_.call(null,obj,new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"dirty","dirty",1109497668),false], null));
return lt.object.raise.call(null,obj,new cljs.core.Keyword(null,"clean","clean",1108650427));
}
} else
{return null;
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.editor.file","dirty-on-change","lt.objs.editor.file/dirty-on-change",4496637698),new cljs.core.Keyword(null,"throttle","throttle",2497347228),100,new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.editor.file.__BEH__dirty_on_change,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"change","change",3947235106),null], null), null));
lt.objs.editor.file.__BEH__preserve_line_endings = (function __BEH__preserve_line_endings(editor,content){if(cljs.core._EQ_.call(null,"\r\n",(function (){var or__3520__auto__ = new cljs.core.Keyword(null,"line-ending","line-ending",4015468690).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"info","info",1017141280).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,editor)));if(cljs.core.truth_(or__3520__auto__))
{return or__3520__auto__;
} else
{return lt.objs.files.line_ending;
}
})()))
{return clojure.string.replace.call(null,content,(new RegExp("(\r?\n|\n)","gm")),"\r\n");
} else
{return content;
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.editor.file","preserve-line-endings","lt.objs.editor.file/preserve-line-endings",3854199025),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.editor.file.__BEH__preserve_line_endings,new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"save+","save+",1123115456),null], null), null));
lt.objs.editor.file.__BEH__remove_trailing_whitespace = (function __BEH__remove_trailing_whitespace(editor,content){return content.replace((new RegExp("[ \\t]+$","gm")),"");
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.editor.file","remove-trailing-whitespace","lt.objs.editor.file/remove-trailing-whitespace",1399383588),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.editor.file.__BEH__remove_trailing_whitespace,new cljs.core.Keyword(null,"desc","desc",1016984067),"Save: Remove trailing whitespace",new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"save+","save+",1123115456),null], null), null),new cljs.core.Keyword(null,"type","type",1017479852),new cljs.core.Keyword(null,"user","user",1017503549),new cljs.core.Keyword(null,"exclusive","exclusive",2700522000),true);
lt.objs.editor.file.__BEH__last_char_newline = (function __BEH__last_char_newline(editor,content){var line_ending = new cljs.core.Keyword(null,"line-ending","line-ending",4015468690).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"info","info",1017141280).cljs$core$IFn$_invoke$arity$1(cljs.core.deref.call(null,editor)));if(cljs.core._EQ_.call(null,cljs.core.last.call(null,content),"\n"))
{return content;
} else
{return [cljs.core.str(content),cljs.core.str(line_ending)].join('');
}
});
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.editor.file","last-char-newline","lt.objs.editor.file/last-char-newline",3282907185),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.editor.file.__BEH__last_char_newline,new cljs.core.Keyword(null,"desc","desc",1016984067),"Save: Ensure the file ends with a new-line",new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"save+","save+",1123115456),null], null), null),new cljs.core.Keyword(null,"type","type",1017479852),new cljs.core.Keyword(null,"user","user",1017503549),new cljs.core.Keyword(null,"exclusive","exclusive",2700522000),true);
/**
* @param {...*} var_args
*/
lt.objs.editor.file.__BEH__on_save = (function() { 
var __BEH__on_save__delegate = function (this$,cmd,args){return cljs.core.apply.call(null,lt.objs.command.exec_BANG_,cmd,args);
};
var __BEH__on_save = function (this$,cmd,var_args){
var args = null;if (arguments.length > 2) {
  args = cljs.core.array_seq(Array.prototype.slice.call(arguments, 2),0);} 
return __BEH__on_save__delegate.call(this,this$,cmd,args);};
__BEH__on_save.cljs$lang$maxFixedArity = 2;
__BEH__on_save.cljs$lang$applyTo = (function (arglist__11261){
var this$ = cljs.core.first(arglist__11261);
arglist__11261 = cljs.core.next(arglist__11261);
var cmd = cljs.core.first(arglist__11261);
var args = cljs.core.rest(arglist__11261);
return __BEH__on_save__delegate(this$,cmd,args);
});
__BEH__on_save.cljs$core$IFn$_invoke$arity$variadic = __BEH__on_save__delegate;
return __BEH__on_save;
})()
;
lt.object.behavior_STAR_.call(null,new cljs.core.Keyword("lt.objs.editor.file","on-save","lt.objs.editor.file/on-save",4413429866),new cljs.core.Keyword(null,"reaction","reaction",4441361819),lt.objs.editor.file.__BEH__on_save,new cljs.core.Keyword(null,"desc","desc",1016984067),"Editor: On save execute command",new cljs.core.Keyword(null,"params","params",4313443576),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"label","label",1116631654),"command"], null)], null),new cljs.core.Keyword(null,"triggers","triggers",2516997421),new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"save","save",1017427183),null], null), null),new cljs.core.Keyword(null,"type","type",1017479852),new cljs.core.Keyword(null,"user","user",1017503549));
