diff --git a/spec/extensions/command-interpreter-spec.coffee b/spec/extensions/command-interpreter-spec.coffee index 816bb5bd8..b4c7c1e46 100644 --- a/spec/extensions/command-interpreter-spec.coffee +++ b/spec/extensions/command-interpreter-spec.coffee @@ -1,4 +1,4 @@ -CommandInterpreter = require 'command-interpreter' +CommandInterpreter = require 'command-panel/command-interpreter' Buffer = require 'buffer' EditSession = require 'edit-session' Editor = require 'editor' diff --git a/spec/extensions/command-panel-spec.coffee b/spec/extensions/command-panel-spec.coffee index 049c2d931..8edbd2f50 100644 --- a/spec/extensions/command-panel-spec.coffee +++ b/spec/extensions/command-panel-spec.coffee @@ -9,7 +9,7 @@ describe "CommandPanel", -> rootView.open(require.resolve 'fixtures/sample.js') rootView.enableKeymap() editor = rootView.getActiveEditor() - commandPanel = rootView.activateExtension(CommandPanel) + commandPanel = requireExtension('command-panel') afterEach -> rootView.remove() diff --git a/spec/extensions/snippets-spec.coffee b/spec/extensions/snippets-spec.coffee index cf91d57c3..2533b4675 100644 --- a/spec/extensions/snippets-spec.coffee +++ b/spec/extensions/snippets-spec.coffee @@ -9,7 +9,7 @@ describe "Snippets extension", -> [buffer, editor] = [] beforeEach -> rootView = new RootView(require.resolve('fixtures/sample.js')) - rootView.activateExtension(Snippets) + requireExtension("snippets") editor = rootView.getActiveEditor() buffer = editor.getBuffer() rootView.simulateDomAttachment() diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index 6acdd2061..2dd302f6e 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -215,16 +215,11 @@ describe "TreeView", -> expect(treeView.find('.selected').length).toBe 1 it "selected a file's parent dir if the file's entry is not visible", -> - # treeView.attachToDom() rootView.open(require.resolve('fixtures/dir/a-dir/oh-git')) dirView = treeView.root.find('.directory:contains(dir)').view() expect(dirView).toHaveClass 'selected' - # dirView.expand() - # aDirView = dirView.find('.directory:contains(a-dir)').view() - # expect(aDirView).toHaveClass 'selected' - describe "when a different editor becomes active", -> it "selects the file in that is open in that editor", -> sampleJs.click() @@ -493,15 +488,15 @@ describe "TreeView", -> describe "when the path with a trailing '/' is changed and confirmed", -> describe "when no file or directory exists at the given path", -> it "adds a directory and closes the dialog", -> - newPath = fs.join(dirPath, "new-dir") - addDialog.miniEditor.insertText("new-dir/") + newPath = fs.join(dirPath, "new/dir") + addDialog.miniEditor.insertText("new/dir/") addDialog.trigger 'tree-view:confirm' expect(fs.exists(newPath)).toBeTruthy() expect(fs.isDirectory(newPath)).toBeTruthy() expect(addDialog.parent()).not.toExist() expect(rootView.getActiveEditor().getBuffer().getPath()).not.toBe newPath - describe "when a or directory already exists at the given path", -> + describe "when a file or directory already exists at the given path", -> it "shows an error message and does not close the dialog", -> newPath = fs.join(dirPath, "new-dir") fs.makeDirectory(newPath) @@ -592,7 +587,7 @@ describe "TreeView", -> describe "when the directories along the new path don't exist", -> it "creates the target directory before moving the file", -> runs -> - newPath = fs.join(rootDirPath, 'new-directory', 'renamed-test-file.txt') + newPath = fs.join(rootDirPath, 'new/directory', 'renamed-test-file.txt') moveDialog.miniEditor.setText(newPath) moveDialog.trigger 'tree-view:confirm' diff --git a/spec/stdlib/fs-spec.coffee b/spec/stdlib/fs-spec.coffee index ad7c29bd9..f5abc6c38 100644 --- a/spec/stdlib/fs-spec.coffee +++ b/spec/stdlib/fs-spec.coffee @@ -21,8 +21,9 @@ describe "fs", -> describe "when called with a directory path", -> it "return the path it was given", -> - expect(fs.directory(require.resolve('fixtures/dir'))).toBe require.resolve('fixtures') - expect(fs.directory(require.resolve('fixtures/dir/'))).toBe require.resolve('fixtures') + expect(fs.directory("/a/b/c")).toBe "/a/b" + expect(fs.directory("/a")).toBe "" + expect(fs.directory("a")).toBe "" describe ".exists(path)", -> it "returns true when path exsits", -> @@ -32,7 +33,6 @@ describe "fs", -> expect(fs.exists(require.resolve("fixtures") + "/-nope-does-not-exist")).toBe false expect(fs.exists("")).toBe false expect(fs.exists(null)).toBe false - #expect(fs.exists(undefined)).toBe false describe ".join(paths...)", -> it "concatenates the given paths with the directory seperator", -> @@ -41,6 +41,11 @@ describe "fs", -> expect(fs.join('/a/b/', 'c', 'd')).toBe '/a/b/c/d' expect(fs.join('a', 'b/c/', 'd/')).toBe 'a/b/c/d/' + describe ".split(path)", -> + it "returns path components", -> + expect(fs.split("/a/b/c.txt")).toEqual ["", "a", "b", "c.txt"] + expect(fs.split("a/b/c.txt")).toEqual ["a", "b", "c.txt"] + describe ".extension(path)", -> it "returns the extension of a file", -> expect(fs.extension("a/b/corey.txt")).toBe '.txt' @@ -49,6 +54,14 @@ describe "fs", -> it "returns an empty string for paths without an extension", -> expect(fs.extension("a/b.not-extension/a-dir")).toBe '' + describe "makeTree(path)", -> + beforeEach -> + fs.remove("/tmp/a") if fs.exists("/tmp/a") + + it "creates all directories in path including any missing parent directories", -> + fs.makeTree("/tmp/a/b/c") + expect(fs.exists("/tmp/a/b/c")).toBeTruthy() + describe ".traverseTree(path, fn)", -> fixturesDir = null diff --git a/src/app/window.coffee b/src/app/window.coffee index 8415e04fc..35382f5a0 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -55,6 +55,15 @@ windowAdditions = return if $("head style[path='#{fullPath}']").length $('head').append "" + requireExtension: (name) -> + extensionPath = require.resolve name + extension = rootView.activateExtension require(extensionPath) + + extensionKeymapPath = fs.join(fs.directory(extensionPath), "keymap.coffee") + require extensionKeymapPath if fs.exists(extensionKeymapPath) + + extension + reload: -> if rootView.getModifiedBuffers().length > 0 message = "There are unsaved buffers, reload anyway?" diff --git a/src/extensions/autocomplete.coffee b/src/extensions/autocomplete/autocomplete.coffee similarity index 100% rename from src/extensions/autocomplete.coffee rename to src/extensions/autocomplete/autocomplete.coffee diff --git a/src/extensions/autocomplete/index.coffee b/src/extensions/autocomplete/index.coffee new file mode 100644 index 000000000..6cf3142ba --- /dev/null +++ b/src/extensions/autocomplete/index.coffee @@ -0,0 +1 @@ +module.exports = require 'autocomplete/autocomplete.coffee' \ No newline at end of file diff --git a/src/app/keymaps/autocomplete.coffee b/src/extensions/autocomplete/keymap.coffee similarity index 100% rename from src/app/keymaps/autocomplete.coffee rename to src/extensions/autocomplete/keymap.coffee diff --git a/src/extensions/command-interpreter.coffee b/src/extensions/command-panel/command-interpreter.coffee similarity index 83% rename from src/extensions/command-interpreter.coffee rename to src/extensions/command-panel/command-interpreter.coffee index 18dd8d114..0190a5e71 100644 --- a/src/extensions/command-interpreter.coffee +++ b/src/extensions/command-panel/command-interpreter.coffee @@ -4,7 +4,7 @@ PEG = require 'pegjs' module.exports = class CommandInterpreter constructor: -> - @parser = PEG.buildParser(fs.read(require.resolve 'command-interpreter/commands.pegjs')) + @parser = PEG.buildParser(fs.read(require.resolve 'command-panel/commands.pegjs')) eval: (editor, string) -> compositeCommand = @parser.parse(string) diff --git a/src/extensions/command-panel.coffee b/src/extensions/command-panel/command-panel.coffee similarity index 93% rename from src/extensions/command-panel.coffee rename to src/extensions/command-panel/command-panel.coffee index cfd304f70..0573f2ff3 100644 --- a/src/extensions/command-panel.coffee +++ b/src/extensions/command-panel/command-panel.coffee @@ -1,7 +1,7 @@ {View} = require 'space-pen' -CommandInterpreter = require 'command-interpreter' -RegexAddress = require 'command-interpreter/regex-address' -CompositeCommand = require 'command-interpreter/composite-command' +CommandInterpreter = require 'command-panel/command-interpreter' +RegexAddress = require 'command-panel/commands/regex-address' +CompositeCommand = require 'command-panel/commands/composite-command' Editor = require 'editor' {SyntaxError} = require('pegjs').parser diff --git a/src/extensions/command-interpreter/commands.pegjs b/src/extensions/command-panel/commands.pegjs similarity index 65% rename from src/extensions/command-interpreter/commands.pegjs rename to src/extensions/command-panel/commands.pegjs index 925845f8a..1a3b92307 100644 --- a/src/extensions/command-interpreter/commands.pegjs +++ b/src/extensions/command-panel/commands.pegjs @@ -1,12 +1,12 @@ { - var CompositeCommand = require('command-interpreter/composite-command') - var Substitution = require('command-interpreter/substitution'); - var LineAddress = require('command-interpreter/line-address'); - var AddressRange = require('command-interpreter/address-range'); - var EofAddress = require('command-interpreter/eof-address'); - var CurrentSelectionAddress = require('command-interpreter/current-selection-address') - var RegexAddress = require('command-interpreter/regex-address') - var SelectAllMatches = require('command-interpreter/select-all-matches') + var CompositeCommand = require('command-panel/commands/composite-command') + var Substitution = require('command-panel/commands/substitution'); + var LineAddress = require('command-panel/commands/line-address'); + var AddressRange = require('command-panel/commands/address-range'); + var EofAddress = require('command-panel/commands/eof-address'); + var CurrentSelectionAddress = require('command-panel/commands/current-selection-address') + var RegexAddress = require('command-panel/commands/regex-address') + var SelectAllMatches = require('command-panel/commands/select-all-matches') } start = expressions:(expression+) { diff --git a/src/extensions/command-interpreter/address-range.coffee b/src/extensions/command-panel/commands/address-range.coffee similarity index 87% rename from src/extensions/command-interpreter/address-range.coffee rename to src/extensions/command-panel/commands/address-range.coffee index 01aaab1f5..e8f3c68dd 100644 --- a/src/extensions/command-interpreter/address-range.coffee +++ b/src/extensions/command-panel/commands/address-range.coffee @@ -1,4 +1,4 @@ -Address = require 'command-interpreter/address' +Address = require 'command-panel/commands/address' Range = require 'range' module.exports = diff --git a/src/extensions/command-interpreter/address.coffee b/src/extensions/command-panel/commands/address.coffee similarity index 73% rename from src/extensions/command-interpreter/address.coffee rename to src/extensions/command-panel/commands/address.coffee index 5cdf3e5d6..e6ef1e11b 100644 --- a/src/extensions/command-interpreter/address.coffee +++ b/src/extensions/command-panel/commands/address.coffee @@ -1,4 +1,4 @@ -Command = require 'command-interpreter/command' +Command = require 'command-panel/commands/command' module.exports = class Address extends Command diff --git a/src/extensions/command-interpreter/command.coffee b/src/extensions/command-panel/commands/command.coffee similarity index 100% rename from src/extensions/command-interpreter/command.coffee rename to src/extensions/command-panel/commands/command.coffee diff --git a/src/extensions/command-interpreter/composite-command.coffee b/src/extensions/command-panel/commands/composite-command.coffee similarity index 100% rename from src/extensions/command-interpreter/composite-command.coffee rename to src/extensions/command-panel/commands/composite-command.coffee diff --git a/src/extensions/command-interpreter/current-selection-address.coffee b/src/extensions/command-panel/commands/current-selection-address.coffee similarity index 76% rename from src/extensions/command-interpreter/current-selection-address.coffee rename to src/extensions/command-panel/commands/current-selection-address.coffee index 3c426f8f3..fe4b67f2b 100644 --- a/src/extensions/command-interpreter/current-selection-address.coffee +++ b/src/extensions/command-panel/commands/current-selection-address.coffee @@ -1,4 +1,4 @@ -Address = require 'command-interpreter/address' +Address = require 'command-panel/commands/address' Range = require 'range' module.exports = diff --git a/src/extensions/command-interpreter/eof-address.coffee b/src/extensions/command-panel/commands/eof-address.coffee similarity index 83% rename from src/extensions/command-interpreter/eof-address.coffee rename to src/extensions/command-panel/commands/eof-address.coffee index f2db31217..c4f41b577 100644 --- a/src/extensions/command-interpreter/eof-address.coffee +++ b/src/extensions/command-panel/commands/eof-address.coffee @@ -1,4 +1,4 @@ -Address = require 'command-interpreter/address' +Address = require 'command-panel/commands/address' Range = require 'range' module.exports = diff --git a/src/extensions/command-interpreter/line-address.coffee b/src/extensions/command-panel/commands/line-address.coffee similarity index 80% rename from src/extensions/command-interpreter/line-address.coffee rename to src/extensions/command-panel/commands/line-address.coffee index 245c3d669..aaebc7a40 100644 --- a/src/extensions/command-interpreter/line-address.coffee +++ b/src/extensions/command-panel/commands/line-address.coffee @@ -1,4 +1,4 @@ -Address = require 'command-interpreter/address' +Address = require 'command-panel/commands/address' Range = require 'range' module.exports = diff --git a/src/extensions/command-interpreter/regex-address.coffee b/src/extensions/command-panel/commands/regex-address.coffee similarity index 95% rename from src/extensions/command-interpreter/regex-address.coffee rename to src/extensions/command-panel/commands/regex-address.coffee index 4848ed6af..8fbf13b78 100644 --- a/src/extensions/command-interpreter/regex-address.coffee +++ b/src/extensions/command-panel/commands/regex-address.coffee @@ -1,4 +1,4 @@ -Address = require 'command-interpreter/address' +Address = require 'command-panel/commands/address' Range = require 'range' module.exports = diff --git a/src/extensions/command-interpreter/select-all-matches.coffee b/src/extensions/command-panel/commands/select-all-matches.coffee similarity index 87% rename from src/extensions/command-interpreter/select-all-matches.coffee rename to src/extensions/command-panel/commands/select-all-matches.coffee index 4fd759b86..2d29dded9 100644 --- a/src/extensions/command-interpreter/select-all-matches.coffee +++ b/src/extensions/command-panel/commands/select-all-matches.coffee @@ -1,4 +1,4 @@ -Command = require 'command-interpreter/command' +Command = require 'command-panel/commands/command' Range = require 'range' module.exports = diff --git a/src/extensions/command-interpreter/substitution.coffee b/src/extensions/command-panel/commands/substitution.coffee similarity index 89% rename from src/extensions/command-interpreter/substitution.coffee rename to src/extensions/command-panel/commands/substitution.coffee index d58a0d388..5daf680b4 100644 --- a/src/extensions/command-interpreter/substitution.coffee +++ b/src/extensions/command-panel/commands/substitution.coffee @@ -1,4 +1,4 @@ -Command = require 'command-interpreter/command' +Command = require 'command-panel/commands/command' module.exports = class Substitution extends Command diff --git a/src/extensions/command-panel/index.coffee b/src/extensions/command-panel/index.coffee new file mode 100644 index 000000000..761d95578 --- /dev/null +++ b/src/extensions/command-panel/index.coffee @@ -0,0 +1 @@ +module.exports = require 'command-panel/command-panel' \ No newline at end of file diff --git a/src/app/keymaps/command-panel.coffee b/src/extensions/command-panel/keymap.coffee similarity index 100% rename from src/app/keymaps/command-panel.coffee rename to src/extensions/command-panel/keymap.coffee diff --git a/src/extensions/fuzzy-finder.coffee b/src/extensions/fuzzy-finder/fuzzy-finder.coffee similarity index 100% rename from src/extensions/fuzzy-finder.coffee rename to src/extensions/fuzzy-finder/fuzzy-finder.coffee diff --git a/src/extensions/fuzzy-finder/index.coffee b/src/extensions/fuzzy-finder/index.coffee new file mode 100644 index 000000000..c1518b670 --- /dev/null +++ b/src/extensions/fuzzy-finder/index.coffee @@ -0,0 +1 @@ +module.exports = require 'fuzzy-finder/fuzzy-finder' diff --git a/src/app/keymaps/fuzzy-finder.coffee b/src/extensions/fuzzy-finder/keymap.coffee similarity index 100% rename from src/app/keymaps/fuzzy-finder.coffee rename to src/extensions/fuzzy-finder/keymap.coffee diff --git a/src/app/keymaps/keybindings-view.coffee b/src/extensions/keybindings-view/keymap.coffee similarity index 100% rename from src/app/keymaps/keybindings-view.coffee rename to src/extensions/keybindings-view/keymap.coffee diff --git a/src/app/keymaps/snippets.coffee b/src/extensions/snippets/keymap.coffee similarity index 100% rename from src/app/keymaps/snippets.coffee rename to src/extensions/snippets/keymap.coffee diff --git a/src/app/keymaps/tree-view.coffee b/src/extensions/tree-view/keymap.coffee similarity index 100% rename from src/app/keymaps/tree-view.coffee rename to src/extensions/tree-view/keymap.coffee diff --git a/src/extensions/tree-view/tree-view.coffee b/src/extensions/tree-view/tree-view.coffee index 10179c7fa..ade0c9226 100644 --- a/src/extensions/tree-view/tree-view.coffee +++ b/src/extensions/tree-view/tree-view.coffee @@ -171,7 +171,7 @@ class TreeView extends View newPath = @rootView.project.resolve(newPath) directoryPath = fs.directory(newPath) try - fs.makeDirectory(directoryPath) unless fs.exists(directoryPath) + fs.makeTree(directoryPath) unless fs.exists(directoryPath) fs.move(oldPath, newPath) catch e dialog.showError("Error: " + e.message + " Try a different path:") @@ -208,15 +208,15 @@ class TreeView extends View endsWithDirectorySeperator = /\/$/.test(relativePath) path = @rootView.project.resolve(relativePath) try - if endsWithDirectorySeperator - fs.makeDirectory(path) + if fs.exists(path) + pathType = if fs.isFile(path) then "file" else "directory" + dialog.showError("Error: A #{pathType} already exists at path '#{path}'. Try a different path:") + false + else if endsWithDirectorySeperator + fs.makeTree(path) else - if fs.exists(path) - dialog.showError("Error: A file already exists at path '#{path}'. Try a different path:") - false - else - fs.write(path, "") - @rootView.open(path) + fs.write(path, "") + @rootView.open(path) catch e dialog.showError("Error: " + e.message + " Try a different path:") return false diff --git a/src/extensions/vim-mode.coffee b/src/extensions/vim-mode/index.coffee similarity index 100% rename from src/extensions/vim-mode.coffee rename to src/extensions/vim-mode/index.coffee diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index b873e453f..4e1516fb9 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -21,7 +21,9 @@ module.exports = # parent directory if the file is a directory. A terminal directory # separator is ignored. directory: (path) -> - path.replace(new RegExp("/#{@base(path)}\/?$"), '') + parentPath = path.replace(new RegExp("/#{@base(path)}\/?$"), '') + return "" if path == parentPath + parentPath # Returns true if the file specified by path exists exists: (path) -> @@ -75,6 +77,15 @@ module.exports = read: (path) -> $native.read(path) + # Returns an array of path components. If the path is absolute, the first + # component will be an indicator of the root of the file system; for file + # systems with drives (such as Windows), this is the drive identifier with a + # colon, like "c:"; on Unix, this is an empty string "". The intent is that + # calling "join.apply" with the result of "split" as arguments will + # reconstruct the path. + split: (path) -> + path.split("/") + # Open, write, flush, and close a file, writing the given content. write: (path, content) -> $native.write(path, content) @@ -82,6 +93,14 @@ module.exports = makeDirectory: (path) -> $native.makeDirectory(path) + # Creates the directory specified by "path" including any missing parent + # directories. + makeTree: (path) -> + return unless path + if not @exists(path) + @makeTree(@directory(path)) + @makeDirectory(path) + traverseTree: (rootPath, fn) -> recurse = null prune = -> recurse = false diff --git a/src/stdlib/require.coffee b/src/stdlib/require.coffee index cf760ec5b..46f6fbb55 100644 --- a/src/stdlib/require.coffee +++ b/src/stdlib/require.coffee @@ -106,12 +106,15 @@ __exists = (path) -> __coffeeCache = (filePath) -> {CoffeeScript} = require 'coffee-script' - cacheKey = 'coffee.' + $native.md5ForPath(filePath) - if compiled = localStorage.getItem(cacheKey) - compiled + tmpPath = "/tmp/atom-compiled-scripts" + cacheFilePath = [tmpPath, $native.md5ForPath(filePath)].join("/") + + console.log cacheFilePath + if __exists(cacheFilePath) + __read(cacheFilePath) else compiled = CoffeeScript.compile(__read(filePath), filename: filePath) - localStorage.setItem(cacheKey, compiled) + $native.write(cacheFilePath, compiled) compiled __read = (path) ->