     contents = @getContents()
     @emit "ace.requests.saveAs", contents
 
-    
+
   fetchContents:(callback)->
-    
+
     file = @getData()
     unless /localfile:/.test file.path
       file.fetchContents callback
     else
       callback null, file.contents or ""
-    
+
   ###
   GETTERS
   ###
-  
+
   getContents:-> @editor.getSession().getValue()
-  
+
   getTheme:-> @editor.getTheme().replace "ace/theme/", ""
 
   getSyntax:-> @syntaxMode
 
-  getUseSoftTabs:-> @editor.getSession().getUseSoftTabs()
-
-  getShowGutter:-> @editor.renderer.getShowGutter()
-
-  getShowPrintMargin:-> @editor.getShowPrintMargin()
-
-  getHighlightActiveLine:-> @editor.getHighlightActiveLine()
-
-  getShowInvisibles:-> @editor.getShowInvisibles()
-
-  getFontSize:-> parseInt @$("#editor#{@getId()}").css("font-size"), 10
-
-  getTabSize:-> @editor.getSession().getTabSize()
-
-  getUseWordWrap:-> @editor.getSession().getUseWrapMode()
-
-  getSoftWrap:-> 
-
-    limit = @editor.getSession().getWrapLimitRange().max
+  getUseSoftTabs:->
+    @appStorage.getValue 'useSoftTabs', @editor.getSession().getUseSoftTabs()
+
+  getShowGutter:->
+    @appStorage.getValue 'showGutter', @editor.renderer.getShowGutter()
+
+  getShowPrintMargin:->
+    @appStorage.getValue 'showPrintMargin', @editor.getShowPrintMargin()
+
+  getHighlightActiveLine:->
+    @appStorage.getValue 'highlightActiveLine', @editor.getHighlightActiveLine()
+
+  getShowInvisibles:->
+    @appStorage.getValue 'showInvisibles', @editor.getShowInvisibles()
+
+  getFontSize:->
+    @appStorage.getValue 'fontSize', parseInt(@$("#editor#{@getId()}").css("font-size"), 10)
+
+  getTabSize:->
+    @appStorage.getValue 'tabSize', @editor.getSession().getTabSize()
+
+  getUseWordWrap:->
+    @appStorage.getValue 'useWordWrap', @editor.getSession().getUseWrapMode()
+
+  getSoftWrap:->
+
+    limit = @appStorage.getValue 'softWrap', @editor.getSession().getWrapLimitRange().max
     if limit then limit
     else
       if @getUseWordWrap() then "free" else "off"
-    
+
   getSettings:->
     theme               : @getTheme()
     syntax              : @getSyntax()

    fontSize            : @getFontSize()
    tabSize             : @getTabSize()
    softWrap            : @getSoftWrap()
    
  ###
  SETTERS
  ###

  setContents:(contents)-> @editor.getSession().setValue contents

  setTheme:(themeName = "merbivore_soft")->

    require ["ace/theme/#{themeName}"], (callback) =>
      @editor.setTheme "ace/theme/#{themeName}"
  
  setSyntax:(mode)->
    
    file = @getData()
    mode or= file.syntax
    
    unless mode
      ext  = @utils.getFileExtension file.path
      for name, [language, extensions] of __aceSettings.syntaxAssociations
        if ///^(?:#{extensions})$///i.test ext
          mode = name
      mode or= "text"
    
    require ["ace/mode/#{mode}"], ({Mode})=>
      @editor.getSession().setMode new Mode
      @syntaxMode = mode

  setUseSoftTabs:(value)-> @editor.getSession().setUseSoftTabs value
    
  setShowGutter:(value)-> @editor.renderer.setShowGutter value

  setShowPrintMargin:(value)-> @editor.setShowPrintMargin value
    
  setHighlightActiveLine:(value)-> @editor.setHighlightActiveLine value

  # setHighlightSelectedWord:(value)-> @editor.setHighlightActiveLine value

  setShowInvisibles:(value)-> @editor.setShowInvisibles value

  setFontSize:(value)-> @$("editor#{@getId()}").css fontSize : "#{value}px"

  setTabSize:(value)-> @editor.getSession().setTabSize value

  setUseWordWrap:(value)-> @editor.getSession().setUseWrapMode value
  
  softWrapValueMap = ->

    'off'  : [ null, 80 ]
    '40'   : [ 40,   40 ]
    '80'   : [ 80,   80 ]
    'free' : [ null, 80 ]
  
  setSoftWrap:(value)->
    
    [limit, margin] = softWrapValueMap()[value]

    @editor.getSession().setWrapLimitRange limit, limit
    @editor.renderer.setPrintMarginColumn margin
    @setUseWordWrap no if value is "off"

  ###
  HELPERS
  ###

###
  todo:

    - put search replace
    - fix setSoftWrap it goes back to off when you reopen the settings

