diff --git a/Cocoa/Classes/AtomWindowController.m b/Cocoa/Classes/AtomWindowController.m
index ae6c4e469..27bf20a70 100644
--- a/Cocoa/Classes/AtomWindowController.m
+++ b/Cocoa/Classes/AtomWindowController.m
@@ -33,9 +33,11 @@
else {
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *bootstrapPath = [resourcePath stringByAppendingString:@"/src/bootstrap.js"];
+ NSString *coffeePath = [resourcePath stringByAppendingString:@"/vendor/coffee-script.js"];
JSCocoa* jsc = [[JSCocoa alloc] initWithGlobalContext:[[webView mainFrame] globalContext]];
[jsc setObject:self withName:@"WindowController"];
[jsc evalJSFile:bootstrapPath];
+ [jsc evalJSFile:coffeePath];
NSURL *resourceURL = [[NSBundle mainBundle] resourceURL];
NSURL *htmlURL = [resourceURL URLByAppendingPathComponent:@"static"];
diff --git a/plugins/project/project.coffee b/plugins/project/project.coffee
index 215179439..c0a9bd0c8 100644
--- a/plugins/project/project.coffee
+++ b/plugins/project/project.coffee
@@ -1,29 +1,31 @@
-define (require, exports, module) ->
- {Chrome, Dir, File, Process} = require 'osx'
- {bindKey} = require 'editor'
+$ = require 'jquery'
+_ = require 'underscore'
- exports.init = ->
- @html = File.read(Chrome.appRoot() + "/plugins/project/project.html")
+{Chrome, Dir, File, Process} = require 'osx'
+{bindKey} = require 'editor'
- bindKey 'toggleProjectDrawer', 'Command-Ctrl-N', (env) =>
- @toggle()
+exports.init = ->
+ @html = File.read(Chrome.appRoot() + "/plugins/project/project.html")
- exports.toggle = ->
- if @showing
- $('#project').parent().remove()
- else
- Chrome.addPane 'left', @html
- @reload()
+ bindKey 'toggleProjectDrawer', 'Command-Ctrl-N', (env) =>
+ @toggle()
- @showing = not @showing
+exports.toggle = ->
+ if @showing
+ $('#project').parent().remove()
+ else
+ Chrome.addPane 'left', @html
+ @reload()
- exports.reload = ->
- dir = OSX.NSFileManager.defaultManager.currentDirectoryPath
- $('#project .cwd').text(dir)
+ @showing = not @showing
- files = Dir.list(dir)
- listItems = _.map files, (file) ->
- file = file.replace(dir, "")
- "
#{file}"
+exports.reload = ->
+ dir = OSX.NSFileManager.defaultManager.currentDirectoryPath
+ $('#project .cwd').text(dir)
- $('#project .files').append(listItems.join('\n'))
+ files = Dir.list(dir)
+ listItems = _.map files, (file) ->
+ file = file.replace(dir, "")
+ "#{file}"
+
+ $('#project .files').append(listItems.join('\n'))
diff --git a/plugins/tabs/index.coffee b/plugins/tabs/index.coffee
index 183d71a50..c4b2470b2 100644
--- a/plugins/tabs/index.coffee
+++ b/plugins/tabs/index.coffee
@@ -1,2 +1 @@
-define (require, exports, module) ->
- exports.Tabs = Tabs = require('tabs/tabs')
+exports.Tabs = Tabs = require('tabs/tabs')
diff --git a/plugins/tabs/tabs.coffee b/plugins/tabs/tabs.coffee
index 3da62c5f0..e976096fa 100644
--- a/plugins/tabs/tabs.coffee
+++ b/plugins/tabs/tabs.coffee
@@ -1,47 +1,49 @@
-define (require, exports, module) ->
- {Chrome, File, Dir, Process} = require 'osx'
- {bindKey} = require 'editor'
+$ = require 'jquery'
+_ = require 'underscore'
+
+{Chrome, File, Dir, Process} = require 'osx'
+{bindKey} = require 'editor'
- # click tab
- $(document).delegate '#tabs ul li:not(.add) a', 'click', ->
- switchToTab this
- false
+# click tab
+$(document).delegate '#tabs ul li:not(.add) a', 'click', ->
+ switchToTab this
+ false
- # click 'add' tab
- $(document).delegate '#tabs .add a', 'click', ->
- addTab()
- false
+# click 'add' tab
+$(document).delegate '#tabs .add a', 'click', ->
+ addTab()
+ false
- # toggle
- bindKey 'toggleTabs', 'Command-Ctrl-T', (env) ->
- if $('#tabs').length
- hideTabs()
- else
- showTabs()
+# toggle
+bindKey 'toggleTabs', 'Command-Ctrl-T', (env) ->
+ if $('#tabs').length
+ hideTabs()
+ else
+ showTabs()
- showTabs = ->
- Chrome.addPane 'top', require('tabs/tabs.html')
- $('#tabs').parents('.pane').css height: 'inherit'
- css = $('').html require('tabs/tabs.css')
- $('head').append css
+showTabs = ->
+ Chrome.addPane 'top', require('tabs/tabs.html')
+ $('#tabs').parents('.pane').css height: 'inherit'
+ css = $('').html require('tabs/tabs.css')
+ $('head').append css
- hideTabs = ->
- $('#tabs').parents('.pane').remove()
- $('#tabs-style').remove()
+hideTabs = ->
+ $('#tabs').parents('.pane').remove()
+ $('#tabs-style').remove()
- addTab = ->
- $('#tabs ul .add').before 'untitled'
- $('#tabs ul .active').removeClass()
- $('#tabs ul .add').prev().addClass 'active'
+addTab = ->
+ $('#tabs ul .add').before 'untitled'
+ $('#tabs ul .active').removeClass()
+ $('#tabs ul .add').prev().addClass 'active'
- switchToTab = (tab) ->
- $('#tabs ul .active').removeClass()
- $(tab).parents('li').addClass 'active'
+switchToTab = (tab) ->
+ $('#tabs ul .active').removeClass()
+ $(tab).parents('li').addClass 'active'
- exports.show = exports.showTabs = showTabs
- exports.hideTabs = hideTabs
- exports.addTab = addTab
- exports.switchToTab = switchToTab
\ No newline at end of file
+exports.show = exports.showTabs = showTabs
+exports.hideTabs = hideTabs
+exports.addTab = addTab
+exports.switchToTab = switchToTab
\ No newline at end of file
diff --git a/src/editor.coffee b/src/editor.coffee
index e106c0446..c91493a03 100644
--- a/src/editor.coffee
+++ b/src/editor.coffee
@@ -1,125 +1,128 @@
# nice!
-define (require, exports, module) ->
- {Chrome, File, Process, Dir} = require 'osx'
+$ = require 'jquery'
+_ = require 'underscore'
- ace = require 'ace/ace'
- canon = require 'pilot/canon'
+{Chrome, File, Process, Dir} = require 'osx'
- Chrome.addPane 'main', ''
+ace = require 'ace/ace'
+canon = require 'pilot/canon'
- editor = ace.edit "editor"
- editor.setTheme require "ace/theme/twilight"
- JavaScriptMode = require("ace/mode/javascript").Mode
- CoffeeMode = require("ace/mode/coffee").Mode
- HTMLMode = require("ace/mode/html").Mode
- editor.getSession().setMode new JavaScriptMode
- editor.getSession().setUseSoftTabs true
- editor.getSession().setTabSize 2
+Chrome.addPane 'main', ''
- # fuuuuu, ui bug
- setTimeout ->
- editor.focus()
- editor.resize()
- , 50
+editor = ace.edit "editor"
+editor.setTheme require "ace/theme/twilight"
+JavaScriptMode = require("ace/mode/javascript").Mode
+CoffeeMode = require("ace/mode/coffee").Mode
+HTMLMode = require("ace/mode/html").Mode
+editor.getSession().setMode new JavaScriptMode
+editor.getSession().setUseSoftTabs true
+editor.getSession().setTabSize 2
- filename = null
- editor.getSession().on 'change', ->
- Chrome.setDirty true
- save = ->
- File.write filename, editor.getSession().getValue()
+# fuuuuu, ui bug
+setTimeout ->
+ editor.focus()
+ editor.resize()
+, 50
+
+filename = null
+editor.getSession().on 'change', ->
+ Chrome.setDirty true
+save = ->
+ File.write filename, editor.getSession().getValue()
+ setMode()
+ Chrome.setDirty false
+open = ->
+ if /png|jpe?g|gif/i.test filename
+ Chrome.openURL filename
+ else
+ Chrome.title _.last filename.split('/')
+ editor.getSession().setValue File.read filename
setMode()
Chrome.setDirty false
- open = ->
- if /png|jpe?g|gif/i.test filename
- Chrome.openURL filename
- else
- Chrome.title _.last filename.split('/')
- editor.getSession().setValue File.read filename
- setMode()
- Chrome.setDirty false
- setMode = ->
- if /\.js$/.test filename
- editor.getSession().setMode new JavaScriptMode
- else if /\.coffee$/.test filename
- editor.getSession().setMode new CoffeeMode
- else if /\.html/.test filename
- editor.getSession().setMode new HTMLMode
- saveAs = ->
- if file = Chrome.savePanel()
- filename = file
- Chrome.title _.last filename.split('/')
- save()
- exports.bindKey = bindKey = (name, shortcut, callback) ->
- canon.addCommand
- name: name
- exec: callback
- bindKey:
- win: null
- mac: shortcut
- sender: 'editor'
+setMode = ->
+ if /\.js$/.test filename
+ editor.getSession().setMode new JavaScriptMode
+ else if /\.coffee$/.test filename
+ editor.getSession().setMode new CoffeeMode
+ else if /\.html/.test filename
+ editor.getSession().setMode new HTMLMode
+saveAs = ->
+ if file = Chrome.savePanel()
+ filename = file
+ Chrome.title _.last filename.split('/')
+ save()
+exports.bindKey = bindKey = (name, shortcut, callback) ->
+ canon.addCommand
+ name: name
+ exec: callback
+ bindKey:
+ win: null
+ mac: shortcut
+ sender: 'editor'
- bindKey 'open', 'Command-O', (env, args, request) ->
- if file = Chrome.openPanel()
- filename = file
- open()
+bindKey 'open', 'Command-O', (env, args, request) ->
+ if file = Chrome.openPanel()
+ filename = file
+ open()
- bindKey 'openURL', 'Command-Shift-O', (env, args, request) ->
- if url = prompt "Enter URL:"
- Chrome.openURL url
+bindKey 'openURL', 'Command-Shift-O', (env, args, request) ->
+ if url = prompt "Enter URL:"
+ Chrome.openURL url
- bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
- saveAs()
+bindKey 'saveAs', 'Command-Shift-S', (env, args, request) ->
+ saveAs()
- bindKey 'save', 'Command-S', (env, args, request) ->
- if filename then save() else saveAs()
+bindKey 'save', 'Command-S', (env, args, request) ->
+ if filename then save() else saveAs()
- bindKey 'new', 'Command-N', (env, args, request) ->
- Chrome.createWindow()
+bindKey 'new', 'Command-N', (env, args, request) ->
+ console.log 'hi mom'
+ Chrome.createWindow()
- bindKey 'copy', 'Command-C', (env, args, request) ->
- text = editor.getSession().doc.getTextRange editor.getSelectionRange()
- Chrome.writeToPasteboard text
+bindKey 'copy', 'Command-C', (env, args, request) ->
+ text = editor.getSession().doc.getTextRange editor.getSelectionRange()
+ Chrome.writeToPasteboard text
- bindKey 'cut', 'Command-X', (env, args, request) ->
- text = editor.getSession().doc.getTextRange editor.getSelectionRange()
- Chrome.writeToPasteboard text
- editor.session.remove editor.getSelectionRange()
+bindKey 'cut', 'Command-X', (env, args, request) ->
+ text = editor.getSession().doc.getTextRange editor.getSelectionRange()
+ Chrome.writeToPasteboard text
+ editor.session.remove editor.getSelectionRange()
- bindKey 'eval', 'Command-R', (env, args, request) ->
- eval env.editor.getSession().getValue()
+bindKey 'eval', 'Command-R', (env, args, request) ->
+ eval env.editor.getSession().getValue()
- # textmate
+# textmate
- bindKey 'togglecomment', 'Command-/', (env) ->
- env.editor.toggleCommentLines()
+bindKey 'togglecomment', 'Command-/', (env) ->
+ env.editor.toggleCommentLines()
- bindKey 'tmoutdent', 'Command-[', (env) ->
- env.editor.blockOutdent()
+bindKey 'tmoutdent', 'Command-[', (env) ->
+ env.editor.blockOutdent()
- bindKey 'tmindent', 'Command-]', (env) ->
- env.editor.indent()
+bindKey 'tmindent', 'Command-]', (env) ->
+ env.editor.indent()
- # emacs > you
+# emacs > you
- bindKey 'moveforward', 'Alt-F', (env) ->
- env.editor.navigateWordRight()
+bindKey 'moveforward', 'Alt-F', (env) ->
+ env.editor.navigateWordRight()
- bindKey 'moveback', 'Alt-B', (env) ->
- env.editor.navigateWordLeft()
+bindKey 'moveback', 'Alt-B', (env) ->
+ env.editor.navigateWordLeft()
- bindKey 'deleteword', 'Alt-D', (env) ->
- env.editor.removeWordRight()
+bindKey 'deleteword', 'Alt-D', (env) ->
+ env.editor.removeWordRight()
- bindKey 'selectwordright', 'Alt-B', (env) ->
- env.editor.navigateWordLeft()
+bindKey 'selectwordright', 'Alt-B', (env) ->
+ env.editor.navigateWordLeft()
- bindKey 'home', 'Alt-Shift-,', (env) ->
- env.editor.navigateFileStart()
+bindKey 'home', 'Alt-Shift-,', (env) ->
+ env.editor.navigateFileStart()
- bindKey 'end', 'Alt-Shift-.', (env) ->
- env.editor.navigateFileEnd()
+bindKey 'end', 'Alt-Shift-.', (env) ->
+ env.editor.navigateFileEnd()
- bindKey 'fullscreen', 'Command-Shift-Return', (env) ->
- Chrome.toggleFullscreen()
+bindKey 'fullscreen', 'Command-Shift-Return', (env) ->
+ Chrome.toggleFullscreen()
diff --git a/src/osx.coffee b/src/osx.coffee
index f9f3af50d..0b0177c30 100644
--- a/src/osx.coffee
+++ b/src/osx.coffee
@@ -1,118 +1,121 @@
# This is the CoffeeScript API that wraps all of Cocoa.
-define (require, exports, module) ->
- # Handles the UI chrome
- Chrome =
- addPane: (position, html) ->
- verticalDiv = $('#app-vertical')
- horizontalDiv = $('#app-horizontal')
- el = document.createElement("div")
- el.setAttribute('class', "pane " + position)
- el.innerHTML = html
+$ = require 'jquery'
+_ = require 'underscore'
- switch position
- when 'top', 'main'
- verticalDiv.prepend(el)
- when 'left'
- horizontalDiv.prepend(el)
- when 'bottom'
- verticalDiv.append(el)
- when 'right'
- horizontalDiv.append(el)
- else
- throw "I DON'T KNOW HOW TO DEAL WITH #{position}"
+# Handles the UI chrome
+Chrome =
+ addPane: (position, html) ->
+ verticalDiv = $('#app-vertical')
+ horizontalDiv = $('#app-horizontal')
- # path - Optional. The String path to the file to base it on.
- createWindow: (path) ->
- c = OSX.AtomWindowController.alloc.initWithWindowNibName "AtomWindow"
- c.window
- c.window.makeKeyAndOrderFront null
+ el = document.createElement("div")
+ el.setAttribute('class', "pane " + position)
+ el.innerHTML = html
- # Set the active window's dirty status.
- setDirty: (bool) ->
- Chrome.activeWindow().setDocumentEdited bool
-
- # Returns a boolean
- dirty: ->
- Chrome.activeWindow().isDocumentEdited()
-
- # Returns the active NSWindow object
- activeWindow: ->
- OSX.NSApplication.sharedApplication.keyWindow
-
- # Returns null or a file path.
- openPanel: ->
- panel = OSX.NSOpenPanel.openPanel
- panel.setCanChooseDirectories(true)
- if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
- return null
- panel.filenames.lastObject
-
- # Returns null or a file path.
- savePanel: ->
- panel = OSX.NSSavePanel.savePanel
- if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
- return null
- panel.filenames.lastObject
-
- writeToPasteboard: (text) ->
- pb = OSX.NSPasteboard.generalPasteboard
- pb.declareTypes_owner [OSX.NSStringPboardType], null
- pb.setString_forType text, OSX.NSStringPboardType
-
- openURL: (url) ->
- window.location = url
- Chrome.title _.last url.replace(/\/$/,'').split '/'
-
- title: (text) ->
- WindowController.window.title = text
-
- appRoot: ->
- OSX.NSBundle.mainBundle.resourcePath
-
- # Handles the file system
- File =
- read: (path) ->
- OSX.NSString.stringWithContentsOfFile File.expand path
- write: (path, contents) ->
- str = OSX.NSString.stringWithString contents
- str.writeToFile_atomically File.expand(path), true
- expand: (path) ->
- if /~/.test path
- OSX.NSString.stringWithString(path).stringByExpandingTildeInPath
- else if path.indexOf('./') is 0
- "#{Chrome.appRoot}/#{path}"
+ switch position
+ when 'top', 'main'
+ verticalDiv.prepend(el)
+ when 'left'
+ horizontalDiv.prepend(el)
+ when 'bottom'
+ verticalDiv.append(el)
+ when 'right'
+ horizontalDiv.append(el)
else
- path
- isFile: (path) ->
- isDir = new outArgument
- exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
- exists and not isDir.valueOf()
+ throw "I DON'T KNOW HOW TO DEAL WITH #{position}"
- Dir =
- list: (path, recursive) ->
- path = File.expand path
- fm = OSX.NSFileManager.defaultManager
- if recursive
- paths = fm.subpathsAtPath path
- else
- paths = fm.contentsOfDirectoryAtPath_error path, null
- _.map paths, (entry) -> "#{path}/#{entry}"
- isDir: (path) ->
- isDir = new outArgument
- exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
- exists and isDir.valueOf()
+ # path - Optional. The String path to the file to base it on.
+ createWindow: (path) ->
+ c = OSX.AtomWindowController.alloc.initWithWindowNibName "AtomWindow"
+ c.window
+ c.window.makeKeyAndOrderFront null
- Process =
- cwd: (path) ->
- if dir?
- OSX.NSFileManager.defaultManager.changeCurrentDirectoryPath(path)
- else
- OSX.NSFileManager.defaultManager.currentDirectoryPath()
+ # Set the active window's dirty status.
+ setDirty: (bool) ->
+ Chrome.activeWindow().setDocumentEdited bool
- env: ->
- OSX.NSProcess.processInfo.environment()
+ # Returns a boolean
+ dirty: ->
+ Chrome.activeWindow().isDocumentEdited()
- exports.Chrome = Chrome
- exports.File = File
- exports.Dir = Dir
+ # Returns the active NSWindow object
+ activeWindow: ->
+ OSX.NSApplication.sharedApplication.keyWindow
+
+ # Returns null or a file path.
+ openPanel: ->
+ panel = OSX.NSOpenPanel.openPanel
+ panel.setCanChooseDirectories(true)
+ if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
+ return null
+ panel.filenames.lastObject
+
+ # Returns null or a file path.
+ savePanel: ->
+ panel = OSX.NSSavePanel.savePanel
+ if panel.runModal isnt OSX.NSFileHandlingPanelOKButton
+ return null
+ panel.filenames.lastObject
+
+ writeToPasteboard: (text) ->
+ pb = OSX.NSPasteboard.generalPasteboard
+ pb.declareTypes_owner [OSX.NSStringPboardType], null
+ pb.setString_forType text, OSX.NSStringPboardType
+
+ openURL: (url) ->
+ window.location = url
+ Chrome.title _.last url.replace(/\/$/,'').split '/'
+
+ title: (text) ->
+ WindowController.window.title = text
+
+ appRoot: ->
+ OSX.NSBundle.mainBundle.resourcePath
+
+# Handles the file system
+File =
+ read: (path) ->
+ OSX.NSString.stringWithContentsOfFile(File.expand path).toString()
+ write: (path, contents) ->
+ str = OSX.NSString.stringWithString contents
+ str.writeToFile_atomically File.expand(path), true
+ expand: (path) ->
+ if /~/.test path
+ OSX.NSString.stringWithString(path).stringByExpandingTildeInPath
+ else if path.indexOf('./') is 0
+ "#{Chrome.appRoot}/#{path}"
+ else
+ path
+ isFile: (path) ->
+ isDir = new outArgument
+ exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
+ exists and not isDir.valueOf()
+
+Dir =
+ list: (path, recursive) ->
+ path = File.expand path
+ fm = OSX.NSFileManager.defaultManager
+ if recursive
+ paths = fm.subpathsAtPath path
+ else
+ paths = fm.contentsOfDirectoryAtPath_error path, null
+ _.map paths, (entry) -> "#{path}/#{entry}"
+ isDir: (path) ->
+ isDir = new outArgument
+ exists = OSX.NSFileManager.defaultManager.fileExistsAtPath_isDirectory(path, isDir)
+ exists and isDir.valueOf()
+
+Process =
+ cwd: (path) ->
+ if dir?
+ OSX.NSFileManager.defaultManager.changeCurrentDirectoryPath(path)
+ else
+ OSX.NSFileManager.defaultManager.currentDirectoryPath()
+
+ env: ->
+ OSX.NSProcess.processInfo.environment()
+
+exports.Chrome = Chrome
+exports.File = File
+exports.Dir = Dir
diff --git a/src/plugins.coffee b/src/plugins.coffee
index 7082bb6f6..57ee33c30 100644
--- a/src/plugins.coffee
+++ b/src/plugins.coffee
@@ -1,3 +1,6 @@
+$ = require 'jquery'
+_ = require 'underscore'
+
{Chrome, Dir, File} = require 'osx'
_.map Dir.list(Chrome.appRoot() + "/plugins"), (plugin) ->
diff --git a/src/require.coffee b/src/require.coffee
index 83b014e58..a46c557e6 100644
--- a/src/require.coffee
+++ b/src/require.coffee
@@ -25,12 +25,19 @@ define = (cb) ->
defines.push ->
exports = {}
module = exports: exports
- cb.call exports, require, exports, module
- exports
+ cb.call exports, require, exports, module, window
+ module.exports or exports
exts =
js: (file, code) ->
code or= __read file
+
+ if not /define\(/.test code
+ code = """
+ define(function(require, exports, module, window) {
+ #{code};
+ });
+ """
__jsc__.evalJSString_withScriptPath code, file
defines.pop()?.call()
coffee: (file) ->