Merge remote-tracking branch 'origin/master' into vim-core-changes

Conflicts:
	src/app/text-buffer.coffee
This commit is contained in:
Mutwin Kraus
2013-04-04 14:23:58 +02:00
105 changed files with 1034 additions and 3555 deletions

View File

@@ -1,4 +1,4 @@
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
Theme = require 'theme'
CSON = require 'cson'
@@ -9,17 +9,17 @@ class AtomTheme extends Theme
@stylesheets[stylesheetPath] = window.loadStylesheet(stylesheetPath)
load: ->
if fs.extension(@path) in ['.css', '.less']
if fsUtils.extension(@path) in ['.css', '.less']
@loadStylesheet(@path)
else
metadataPath = fs.resolveExtension(fs.join(@path, 'package'), ['cson', 'json'])
if fs.isFile(metadataPath)
metadataPath = fsUtils.resolveExtension(fsUtils.join(@path, 'package'), ['cson', 'json'])
if fsUtils.isFile(metadataPath)
stylesheetNames = CSON.readObject(metadataPath)?.stylesheets
if stylesheetNames
for name in stylesheetNames
filename = fs.resolveExtension(fs.join(@path, name), ['.css', '.less', ''])
filename = fsUtils.resolveExtension(fsUtils.join(@path, name), ['.css', '.less', ''])
@loadStylesheet(filename)
else
@loadStylesheet(stylesheetPath) for stylesheetPath in fs.list(@path, ['.css', '.less'])
@loadStylesheet(stylesheetPath) for stylesheetPath in fsUtils.list(@path, ['.css', '.less'])
super

View File

@@ -1,4 +1,4 @@
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
_ = require 'underscore'
Package = require 'package'
TextMatePackage = require 'text-mate-package'
@@ -74,9 +74,9 @@ _.extend atom,
throw new Error("Could not resolve '#{id}' to a package path")
resolvePackagePath: _.memoize (id) ->
return id if fs.isDirectory(id)
path = fs.resolve(config.packageDirPaths..., id)
path if fs.isDirectory(path)
return id if fsUtils.isDirectory(id)
path = fsUtils.resolve(config.packageDirPaths..., id)
path if fsUtils.isDirectory(path)
getLoadedPackage: (id) ->
if path = @resolvePackagePath(id)
@@ -90,13 +90,13 @@ _.extend atom,
isPackageDisabled: (id) ->
if path = @resolvePackagePath(id)
_.include(config.get('core.disabledPackages') ? [], fs.base(path))
_.include(config.get('core.disabledPackages') ? [], fsUtils.base(path))
getPackagePaths: ->
packagePaths = []
for packageDirPath in config.packageDirPaths
for packagePath in fs.list(packageDirPath)
packagePaths.push(packagePath) if fs.isDirectory(packagePath)
for packagePath in fsUtils.list(packageDirPath)
packagePaths.push(packagePath) if fsUtils.isDirectory(packagePath)
_.uniq(packagePaths)
loadThemes: ->
@@ -109,8 +109,8 @@ _.extend atom,
@loadedThemes.push Theme.load(name)
loadUserStylesheet: ->
userStylesheetPath = fs.resolve(fs.join(config.configDirPath, 'user'), ['css', 'less'])
if fs.isFile(userStylesheetPath)
userStylesheetPath = fsUtils.resolve(fsUtils.join(config.configDirPath, 'user'), ['css', 'less'])
if fsUtils.isFile(userStylesheetPath)
userStyleesheetContents = loadStylesheet(userStylesheetPath)
applyStylesheet(userStylesheetPath, userStyleesheetContents, 'userTheme')
@@ -233,10 +233,12 @@ _.extend atom,
null
getSavedWindowState: ->
localStorage[window.location.params.pathToOpen]
if pathToOpen = window.location.params.pathToOpen
localStorage[pathToOpen]
saveWindowState: ->
localStorage[@getPathToOpen()] = JSON.stringify(@getWindowState())
if pathToOpen = @getPathToOpen()
localStorage[pathToOpen] = JSON.stringify(@getWindowState())
update: ->
@sendMessageToBrowserProcess('update')
@@ -244,10 +246,16 @@ _.extend atom,
getUpdateStatus: (callback) ->
@sendMessageToBrowserProcess('getUpdateStatus', [], callback)
crashMainProcess: ->
@sendMessageToBrowserProcess('crash')
crashRenderProcess: ->
$native.crash()
requireUserInitScript: ->
userInitScriptPath = fs.join(config.configDirPath, "user.coffee")
userInitScriptPath = fsUtils.join(config.configDirPath, "user.coffee")
try
require userInitScriptPath if fs.isFile(userInitScriptPath)
require userInitScriptPath if fsUtils.isFile(userInitScriptPath)
catch error
console.error "Failed to load `#{userInitScriptPath}`", error.stack, error

View File

@@ -1,6 +1,6 @@
$ = require 'jquery'
_ = require 'underscore'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
Specificity = require 'specificity'
PEG = require 'pegjs'
@@ -17,7 +17,7 @@ class BindingSet
name: null
constructor: (@selector, commandsByKeystrokes, @index, @name) ->
BindingSet.parser ?= PEG.buildParser(fs.read(require.resolve 'keystroke-pattern.pegjs'))
BindingSet.parser ?= PEG.buildParser(fsUtils.read(require.resolve 'keystroke-pattern.pegjs'))
@specificity = Specificity(@selector)
@commandsByKeystrokes = @normalizeCommandsByKeystrokes(commandsByKeystrokes)

View File

@@ -1,15 +1,15 @@
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
_ = require 'underscore'
EventEmitter = require 'event-emitter'
CSON = require 'cson'
configDirPath = fs.absolute("~/.atom")
bundledPackagesDirPath = fs.join(resourcePath, "src/packages")
bundledThemesDirPath = fs.join(resourcePath, "themes")
vendoredPackagesDirPath = fs.join(resourcePath, "vendor/packages")
vendoredThemesDirPath = fs.join(resourcePath, "vendor/themes")
userThemesDirPath = fs.join(configDirPath, "themes")
userPackagesDirPath = fs.join(configDirPath, "packages")
configDirPath = fsUtils.absolute("~/.atom")
bundledPackagesDirPath = fsUtils.join(resourcePath, "src/packages")
bundledThemesDirPath = fsUtils.join(resourcePath, "themes")
vendoredPackagesDirPath = fsUtils.join(resourcePath, "vendor/packages")
vendoredThemesDirPath = fsUtils.join(resourcePath, "vendor/themes")
userThemesDirPath = fsUtils.join(configDirPath, "themes")
userPackagesDirPath = fsUtils.join(configDirPath, "packages")
module.exports =
class Config
@@ -26,34 +26,34 @@ class Config
core: _.clone(require('root-view').configDefaults)
editor: _.clone(require('editor').configDefaults)
@settings = {}
@configFilePath = fs.resolve(configDirPath, 'config', ['json', 'cson'])
@configFilePath ?= fs.join(configDirPath, 'config.cson')
@configFilePath = fsUtils.resolve(configDirPath, 'config', ['json', 'cson'])
@configFilePath ?= fsUtils.join(configDirPath, 'config.cson')
initializeConfigDirectory: ->
return if fs.exists(@configDirPath)
return if fsUtils.exists(@configDirPath)
fs.makeDirectory(@configDirPath)
fsUtils.makeDirectory(@configDirPath)
templateConfigDirPath = fs.resolve(window.resourcePath, 'dot-atom')
templateConfigDirPath = fsUtils.resolve(window.resourcePath, 'dot-atom')
onConfigDirFile = (path) =>
relativePath = path.substring(templateConfigDirPath.length + 1)
configPath = fs.join(@configDirPath, relativePath)
fs.write(configPath, fs.read(path))
fs.traverseTreeSync(templateConfigDirPath, onConfigDirFile, (path) -> true)
configPath = fsUtils.join(@configDirPath, relativePath)
fsUtils.write(configPath, fsUtils.read(path))
fsUtils.traverseTreeSync(templateConfigDirPath, onConfigDirFile, (path) -> true)
configThemeDirPath = fs.join(@configDirPath, 'themes')
configThemeDirPath = fsUtils.join(@configDirPath, 'themes')
onThemeDirFile = (path) ->
relativePath = path.substring(bundledThemesDirPath.length + 1)
configPath = fs.join(configThemeDirPath, relativePath)
fs.write(configPath, fs.read(path))
fs.traverseTreeSync(bundledThemesDirPath, onThemeDirFile, (path) -> true)
configPath = fsUtils.join(configThemeDirPath, relativePath)
fsUtils.write(configPath, fsUtils.read(path))
fsUtils.traverseTreeSync(bundledThemesDirPath, onThemeDirFile, (path) -> true)
load: ->
@initializeConfigDirectory()
@loadUserConfig()
loadUserConfig: ->
if fs.exists(@configFilePath)
if fsUtils.exists(@configFilePath)
try
userConfig = CSON.readObject(@configFilePath)
_.extend(@settings, userConfig)

View File

@@ -133,20 +133,20 @@ class Cursor
moveToFirstCharacterOfLine: ->
position = @getBufferPosition()
range = @getCurrentLineBufferRange()
scanRange = @getCurrentLineBufferRange()
newPosition = null
@editSession.scanInRange /^\s*/, range, (match, matchRange) =>
newPosition = matchRange.end
@editSession.scanInBufferRange /^\s*/, scanRange, ({range}) =>
newPosition = range.end
return unless newPosition
newPosition = [position.row, 0] if newPosition.isEqual(position)
@setBufferPosition(newPosition)
skipLeadingWhitespace: ->
position = @getBufferPosition()
range = @getCurrentLineBufferRange()
scanRange = @getCurrentLineBufferRange()
endOfLeadingWhitespace = null
@editSession.scanInRange /^[ \t]*/, range, (match, matchRange) =>
endOfLeadingWhitespace = matchRange.end
@editSession.scanInBufferRange /^[ \t]*/, scanRange, ({range}) =>
endOfLeadingWhitespace = range.end
@setBufferPosition(endOfLeadingWhitespace) if endOfLeadingWhitespace.isGreaterThan(position)
@@ -164,12 +164,12 @@ class Cursor
allowPrevious = options.allowPrevious ? true
currentBufferPosition = @getBufferPosition()
previousNonBlankRow = @editSession.buffer.previousNonBlankRow(currentBufferPosition.row)
range = [[previousNonBlankRow, 0], currentBufferPosition]
scanRange = [[previousNonBlankRow, 0], currentBufferPosition]
beginningOfWordPosition = null
@editSession.backwardsScanInRange (options.wordRegex ? @wordRegExp()), range, (match, matchRange, { stop }) =>
if matchRange.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious
beginningOfWordPosition = matchRange.start
@editSession.backwardsScanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
if range.end.isGreaterThanOrEqual(currentBufferPosition) or allowPrevious
beginningOfWordPosition = range.start
if not beginningOfWordPosition?.isEqual(currentBufferPosition)
stop()
@@ -178,12 +178,12 @@ class Cursor
getEndOfCurrentWordBufferPosition: (options = {}) ->
allowNext = options.allowNext ? true
currentBufferPosition = @getBufferPosition()
range = [currentBufferPosition, @editSession.getEofBufferPosition()]
scanRange = [currentBufferPosition, @editSession.getEofBufferPosition()]
endOfWordPosition = null
@editSession.scanInRange (options.wordRegex ? @wordRegExp()), range, (match, matchRange, { stop }) =>
if matchRange.start.isLessThanOrEqual(currentBufferPosition) or allowNext
endOfWordPosition = matchRange.end
@editSession.scanInBufferRange (options.wordRegex ? @wordRegExp()), scanRange, ({range, stop}) =>
if range.start.isLessThanOrEqual(currentBufferPosition) or allowNext
endOfWordPosition = range.end
if not endOfWordPosition?.isEqual(currentBufferPosition)
stop()

View File

@@ -8,12 +8,14 @@ EventEmitter = require 'event-emitter'
Subscriber = require 'subscriber'
Range = require 'range'
_ = require 'underscore'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
module.exports =
class EditSession
registerDeserializer(this)
@version: 1
@deserialize: (state) ->
session = project.buildEditSessionForBuffer(Buffer.deserialize(state.buffer))
if !session?
@@ -43,7 +45,7 @@ class EditSession
@buffer.retain()
@subscribe @buffer, "path-changed", =>
@project.setPath(fs.directory(@getPath())) unless @project.getPath()?
@project.setPath(fsUtils.directory(@getPath())) unless @project.getPath()?
@trigger "title-changed"
@trigger "path-changed"
@subscribe @buffer, "contents-conflicted", => @trigger "contents-conflicted"
@@ -55,21 +57,21 @@ class EditSession
@subscribe @displayBuffer, "changed", (e) =>
@trigger 'screen-lines-changed', e
@subscribe syntax, 'grammars-loaded', => @reloadGrammar()
@languageMode.on 'grammar-changed', => @handleGrammarChange()
getViewClass: ->
require 'editor'
getTitle: ->
if path = @getPath()
fs.base(path)
fsUtils.base(path)
else
'untitled'
getLongTitle: ->
if path = @getPath()
fileName = fs.base(path)
directory = fs.base(fs.directory(path))
fileName = fsUtils.base(path)
directory = fsUtils.base(fsUtils.directory(path))
"#{fileName} - #{directory}"
else
'untitled'
@@ -81,12 +83,14 @@ class EditSession
@buffer.release()
selection.destroy() for selection in @getSelections()
@displayBuffer.destroy()
@languageMode.destroy()
@project?.removeEditSession(this)
@trigger 'destroyed'
@off()
serialize: ->
deserializer: 'EditSession'
version: @constructor.version
buffer: @buffer.serialize()
scrollTop: @getScrollTop()
scrollLeft: @getScrollLeft()
@@ -160,8 +164,8 @@ class EditSession
bufferRangeForBufferRow: (row, options) -> @buffer.rangeForRow(row, options)
lineForBufferRow: (row) -> @buffer.lineForRow(row)
lineLengthForBufferRow: (row) -> @buffer.lineLengthForRow(row)
scanInRange: (args...) -> @buffer.scanInRange(args...)
backwardsScanInRange: (args...) -> @buffer.backwardsScanInRange(args...)
scanInBufferRange: (args...) -> @buffer.scanInRange(args...)
backwardsScanInBufferRange: (args...) -> @buffer.backwardsScanInRange(args...)
isModified: -> @buffer.isModified()
hasEditors: -> @buffer.hasEditors()
@@ -242,7 +246,7 @@ class EditSession
normalizeTabsInBufferRange: (bufferRange) ->
return unless @softTabs
@scanInRange /\t/, bufferRange, (match, range, {replace}) => replace(@getTabText())
@scanInBufferRange /\t/, bufferRange, ({replace}) => replace(@getTabText())
cutToEndOfLine: ->
maintainPasteboard = false
@@ -843,17 +847,14 @@ class EditSession
getGrammar: -> @languageMode.grammar
setGrammar: (grammar) ->
@languageMode.grammar = grammar
@handleGrammarChange()
@languageMode.setGrammar(grammar)
reloadGrammar: ->
@handleGrammarChange() if @languageMode.reloadGrammar()
@languageMode.reloadGrammar()
handleGrammarChange: ->
@unfoldAll()
@displayBuffer.tokenizedBuffer.resetScreenLines()
@trigger 'grammar-changed'
true
getDebugSnapshot: ->
[

View File

@@ -6,7 +6,7 @@ Range = require 'range'
EditSession = require 'edit-session'
CursorView = require 'cursor-view'
SelectionView = require 'selection-view'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
$ = require 'jquery'
_ = require 'underscore'
@@ -319,8 +319,8 @@ class Editor extends View
lineForBufferRow: (row) -> @getBuffer().lineForRow(row)
lineLengthForBufferRow: (row) -> @getBuffer().lineLengthForRow(row)
rangeForBufferRow: (row) -> @getBuffer().rangeForRow(row)
scanInRange: (args...) -> @getBuffer().scanInRange(args...)
backwardsScanInRange: (args...) -> @getBuffer().backwardsScanInRange(args...)
scanInBufferRange: (args...) -> @getBuffer().scanInRange(args...)
backwardsScanInBufferRange: (args...) -> @getBuffer().backwardsScanInRange(args...)
configure: ->
@observeConfig 'editor.showLineNumbers', (showLineNumbers) => @gutter.setShowLineNumbers(showLineNumbers)
@@ -1102,7 +1102,7 @@ class Editor extends View
range.detach()
leftPixels
pixelOffsetForScreenPosition: (position) ->
pixelOffsUtilsetForScreenPosition: (position) ->
{top, left} = @pixelPositionForScreenPosition(position)
offset = @renderedLines.offset()
{top: top + offset.top, left: left + offset.left}
@@ -1151,16 +1151,9 @@ class Editor extends View
setGrammar: (grammar) ->
throw new Error("Only mini-editors can explicity set their grammar") unless @mini
@activeEditSession.setGrammar(grammar)
@handleGrammarChange()
reloadGrammar: ->
grammarChanged = @activeEditSession.reloadGrammar()
@handleGrammarChange() if grammarChanged
grammarChanged
handleGrammarChange: ->
@clearRenderedLines()
@updateDisplay()
@activeEditSession.reloadGrammar()
bindToKeyedEvent: (key, event, callback) ->
binding = {}
@@ -1185,7 +1178,7 @@ class Editor extends View
saveDebugSnapshot: ->
atom.showSaveDialog (path) =>
fs.write(path, @getDebugSnapshot()) if path
fsUtils.write(path, @getDebugSnapshot()) if path
getDebugSnapshot: ->
[

View File

@@ -1,5 +1,5 @@
_ = require 'underscore'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
Subscriber = require 'subscriber'
EventEmitter = require 'event-emitter'
RepositoryStatusTask = require 'repository-status-task'
@@ -48,7 +48,7 @@ class Git
refreshIndex: -> @getRepo().refreshIndex()
getPath: ->
@path ?= fs.absolute(@getRepo().getPath())
@path ?= fsUtils.absolute(@getRepo().getPath())
destroy: ->
if @statusTask?

View File

@@ -1,6 +1,6 @@
$ = require 'jquery'
_ = require 'underscore'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
CSON = require 'cson'
BindingSet = require 'binding-set'
@@ -32,13 +32,13 @@ class Keymap
$(document).command 'open-dev', => atom.openDev()
loadBundledKeymaps: ->
@loadDirectory(fs.resolveOnLoadPath('keymaps'))
@loadDirectory(fsUtils.resolveOnLoadPath('keymaps'))
loadUserKeymaps: ->
@loadDirectory(fs.join(config.configDirPath, 'keymaps'))
@loadDirectory(fsUtils.join(config.configDirPath, 'keymaps'))
loadDirectory: (directoryPath) ->
@load(filePath) for filePath in fs.list(directoryPath, ['.cson', '.json'])
@load(filePath) for filePath in fsUtils.list(directoryPath, ['.cson', '.json'])
load: (path) ->
@add(path, CSON.readObject(path))

View File

@@ -2,24 +2,37 @@ Range = require 'range'
_ = require 'underscore'
require 'underscore-extensions'
{OnigRegExp} = require 'oniguruma'
EventEmitter = require 'event-emitter'
Subscriber = require 'subscriber'
module.exports =
class LanguageMode
buffer = null
grammar = null
editSession = null
currentGrammarScore: null
constructor: (@editSession) ->
@buffer = @editSession.buffer
@reloadGrammar()
@subscribe syntax, 'grammar-added', (grammar) =>
newScore = grammar.getScore(@buffer.getPath(), @buffer.getText())
@setGrammar(grammar, newScore) if newScore > @currentGrammarScore
destroy: ->
@unsubscribe()
setGrammar: (grammar, score) ->
return if grammar is @grammar
@grammar = grammar
@currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText())
@trigger 'grammar-changed', grammar
reloadGrammar: ->
path = @buffer.getPath()
pathContents = @buffer.cachedDiskContents
previousGrammar = @grammar
@grammar = syntax.selectGrammar(path, pathContents)
throw new Error("No grammar found for path: #{path}") unless @grammar
previousGrammar isnt @grammar
if grammar = syntax.selectGrammar(@buffer.getPath(), @buffer.getText())
@setGrammar(grammar)
else
throw new Error("No grammar found for path: #{path}")
toggleLineCommentsForBufferRows: (start, end) ->
scopes = @editSession.scopesForBufferPosition([start, 0])
@@ -158,3 +171,6 @@ class LanguageMode
foldEndRegexForScopes: (scopes) ->
if foldEndPattern = syntax.getProperty(scopes, 'editor.foldEndPattern')
new OnigRegExp(foldEndPattern)
_.extend LanguageMode.prototype, EventEmitter
_.extend LanguageMode.prototype, Subscriber

View File

@@ -5,5 +5,7 @@ class NullGrammar
name: 'Null Grammar'
scopeName: 'text.plain.null-grammar'
getScore: -> 0
tokenizeLine: (line) ->
{ tokens: [new Token(value: line, scopes: ['null-grammar.text.plain'])] }

View File

@@ -1,4 +1,4 @@
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
module.exports =
class Package
@@ -20,4 +20,4 @@ class Package
path: null
constructor: (@path) ->
@name = fs.base(@path)
@name = fsUtils.base(@path)

View File

@@ -1,4 +1,4 @@
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
_ = require 'underscore'
$ = require 'jquery'
Range = require 'range'
@@ -41,7 +41,7 @@ class Project
@rootDirectory?.off()
if path?
directory = if fs.isDirectory(path) then path else fs.directory(path)
directory = if fsUtils.isDirectory(path) then path else fsUtils.directory(path)
@rootDirectory = new Directory(directory)
else
@rootDirectory = null
@@ -56,7 +56,7 @@ class Project
paths = []
onFile = (path) => paths.push(path) unless @isPathIgnored(path)
onDirectory = -> true
fs.traverseTreeSync(@getPath(), onFile, onDirectory)
fsUtils.traverseTreeSync(@getPath(), onFile, onDirectory)
deferred.resolve(paths)
deferred.promise()
@@ -68,11 +68,11 @@ class Project
@ignoreRepositoryPath(path)
ignoreRepositoryPath: (path) ->
config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fs.join(@getPath(), path))
config.get("core.hideGitIgnoredFiles") and git?.isPathIgnored(fsUtils.join(@getPath(), path))
resolve: (filePath) ->
filePath = fs.join(@getPath(), filePath) unless filePath[0] == '/'
fs.absolute filePath
filePath = fsUtils.join(@getPath(), filePath) unless filePath[0] == '/'
fsUtils.absolute filePath
relativize: (fullPath) ->
return fullPath unless fullPath.lastIndexOf(@getPath()) is 0
@@ -191,8 +191,9 @@ class Project
readPath(line) if state is 'readingPath'
readLine(line) if state is 'readingLines'
command = require.resolve('ag')
command = require.resolve('nak')
args = ['--ackmate', regex.source, @getPath()]
args.unshift("--addVCSIgnores") if config.get('core.excludeVcsIgnoredPaths')
new BufferedProcess({command, args, stdout, exit})
deferred

View File

@@ -1,5 +1,5 @@
Git = require 'git-utils'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
module.exports =
loadStatuses: (path) ->
@@ -8,7 +8,7 @@ module.exports =
workingDirectoryPath = repo.getWorkingDirectory()
statuses = {}
for path, status of repo.getStatus()
statuses[fs.join(workingDirectoryPath, path)] = status
statuses[fsUtils.join(workingDirectoryPath, path)] = status
upstream = repo.getAheadBehindCount()
repo.release()
else

View File

@@ -1,6 +1,6 @@
$ = require 'jquery'
{$$} = require 'space-pen'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
_ = require 'underscore'
{View} = require 'space-pen'
@@ -82,7 +82,7 @@ class RootView extends View
@getActivePane().focus()
false
else
@setTitle(null)
@updateTitle()
focusableChild = this.find("[tabindex=-1]:visible:first")
if focusableChild.length
focusableChild.focus()
@@ -115,7 +115,7 @@ class RootView extends View
if item = @getActivePaneItem()
@setTitle("#{item.getTitle?() ? 'untitled'} - #{projectPath}")
else
@setTitle(projectPath)
@setTitle("atom - #{projectPath}")
else
@setTitle('untitled')
@@ -174,4 +174,3 @@ class RootView extends View
eachBuffer: (callback) ->
project.eachBuffer(callback)

View File

@@ -2,11 +2,9 @@ _ = require 'underscore'
jQuery = require 'jquery'
Specificity = require 'specificity'
{$$} = require 'space-pen'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
EventEmitter = require 'event-emitter'
NullGrammar = require 'null-grammar'
nodePath = require 'path'
pathSplitRegex = new RegExp("[#{nodePath.sep}.]")
module.exports =
class Syntax
@@ -18,27 +16,24 @@ class Syntax
syntax
constructor: ->
@grammars = []
@grammarsByFileType = {}
@nullGrammar = new NullGrammar
@grammars = [@nullGrammar]
@grammarsByScopeName = {}
@grammarOverridesByPath = {}
@scopedPropertiesIndex = 0
@scopedProperties = []
@nullGrammar = new NullGrammar
serialize: ->
{ deserializer: @constructor.name, @grammarOverridesByPath }
addGrammar: (grammar) ->
@grammars.push(grammar)
@grammarsByFileType[fileType] = grammar for fileType in grammar.fileTypes
@grammarsByScopeName[grammar.scopeName] = grammar
@trigger 'grammar-added', grammar
removeGrammar: (grammar) ->
if _.include(@grammars, grammar)
_.remove(@grammars, grammar)
delete @grammarsByFileType[fileType] for fileType in grammar.fileTypes
delete @grammarsByScopeName[grammar.scopeName]
_.remove(@grammars, grammar)
delete @grammarsByScopeName[grammar.scopeName]
setGrammarOverrideForPath: (path, scopeName) ->
@grammarOverridesByPath[path] = scopeName
@@ -50,51 +45,10 @@ class Syntax
@grammarOverridesByPath = {}
selectGrammar: (filePath, fileContents) ->
return @grammarsByFileType["txt"] ? @nullGrammar unless filePath
@grammarOverrideForPath(filePath) ?
@grammarByFirstLineRegex(filePath, fileContents) ?
@grammarByPath(filePath) ?
@grammarsByFileType["txt"] ?
@nullGrammar
_.max @grammars, (grammar) -> grammar.getScore(filePath, fileContents)
grammarOverrideForPath: (path) ->
@grammarsByScopeName[@grammarOverridesByPath[path]]
grammarByPath: (path) ->
pathComponents = path.split(pathSplitRegex)
for fileType, grammar of @grammarsByFileType
fileTypeComponents = fileType.split(pathSplitRegex)
pathSuffix = pathComponents[-fileTypeComponents.length..-1]
return grammar if _.isEqual(pathSuffix, fileTypeComponents)
grammarByFirstLineRegex: (filePath, fileContents) ->
try
fileContents ?= fs.read(filePath)
catch e
return
return unless fileContents
lines = fileContents.split('\n')
_.find @grammars, (grammar) ->
regex = grammar.firstLineRegex
return unless regex?
escaped = false
numberOfNewlinesInRegex = 0
for character in regex.source
switch character
when '\\'
escaped = !escaped
when 'n'
numberOfNewlinesInRegex++ if escaped
escaped = false
else
escaped = false
regex.test(lines[0..numberOfNewlinesInRegex].join('\n'))
@grammarOverridesByPath[path]
grammarForScopeName: (scopeName) ->
@grammarsByScopeName[scopeName]

View File

@@ -1,5 +1,5 @@
_ = require 'underscore'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
File = require 'file'
Point = require 'point'
Range = require 'range'
@@ -37,9 +37,8 @@ class Buffer
@lineEndings = []
if path
# throw "Path '#{path}' does not exist" unless fs.exists(path)
if fs.exists(path)
@setPath(path)
throw "Path '#{path}' does not exist" unless fsUtils.exists(path)
@setPath(path)
if initialText?
@setText(initialText)
@updateCachedDiskContents()
@@ -406,7 +405,7 @@ class Buffer
range = new Range(startPosition, endPosition)
keepLooping = true
replacementText = null
iterator(match, range, { stop, replace })
iterator({match, range, stop, replace })
if replacementText?
@change(range, replacementText)

View File

@@ -1,24 +1,25 @@
_ = require 'underscore'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
plist = require 'plist'
Token = require 'token'
CSON = require 'cson'
{OnigRegExp, OnigScanner} = require 'oniguruma'
nodePath = require 'path'
pathSplitRegex = new RegExp("[#{nodePath.sep}.]")
module.exports =
class TextMateGrammar
@readFromPath: (path) ->
fs.readPlist(path)
fsUtils.readPlist(path)
@load: (path, done) ->
fs.readObjectAsync path, (err, object) ->
fsUtils.readObjectAsync path, (err, object) ->
if err
done(err)
else
done(null, new TextMateGrammar(object))
@loadSync: (path) ->
new TextMateGrammar(fs.readObject(path))
new TextMateGrammar(fsUtils.readObject(path))
name: null
fileTypes: null
@@ -38,6 +39,43 @@ class TextMateGrammar
data = {patterns: [data], tempName: name} if data.begin? or data.match?
@repository[name] = new Rule(this, data)
getScore: (path, contents) ->
contents = fsUtils.read(path) if not contents? and fsUtils.isFile(path)
if syntax.grammarOverrideForPath(path) is @scopeName
3
else if @matchesContents(contents)
2
else if @matchesPath(path)
1
else
-1
matchesContents: (contents) ->
return false unless contents? and @firstLineRegex?
escaped = false
numberOfNewlinesInRegex = 0
for character in @firstLineRegex.source
switch character
when '\\'
escaped = !escaped
when 'n'
numberOfNewlinesInRegex++ if escaped
escaped = false
else
escaped = false
lines = contents.split('\n')
@firstLineRegex.test(lines[0..numberOfNewlinesInRegex].join('\n'))
matchesPath: (path) ->
return false unless path?
pathComponents = path.split(pathSplitRegex)
_.find @fileTypes, (fileType) ->
fileTypeComponents = fileType.split(pathSplitRegex)
pathSuffix = pathComponents[-fileTypeComponents.length..-1]
_.isEqual(pathSuffix, fileTypeComponents)
tokenizeLine: (line, ruleStack=[@initialRule], firstLine=false) ->
originalRuleStack = ruleStack
ruleStack = new Array(ruleStack...) # clone ruleStack

View File

@@ -13,7 +13,6 @@ class TextMatePackage extends Package
@getLoadQueue: ->
return @loadQueue if @loadQueue
@loadQueue = async.queue (pack, done) -> pack.loadGrammars(done)
@loadQueue.drain = -> syntax.trigger 'grammars-loaded'
@loadQueue
constructor: ->

View File

@@ -1,5 +1,5 @@
_ = require 'underscore'
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
plist = require 'plist'
Theme = require 'theme'

View File

@@ -1,4 +1,4 @@
fs = require 'fs-utils'
fsUtils = require 'fs-utils'
module.exports =
class Theme
@@ -8,10 +8,10 @@ class Theme
TextMateTheme = require 'text-mate-theme'
AtomTheme = require 'atom-theme'
if fs.exists(name)
if fsUtils.exists(name)
path = name
else
path = fs.resolve(config.themeDirPaths..., name, ['', '.tmTheme', '.css', 'less'])
path = fsUtils.resolve(config.themeDirPaths..., name, ['', '.tmTheme', '.css', 'less'])
throw new Error("No theme exists named '#{name}'") unless path

View File

@@ -23,6 +23,7 @@ class TokenizedBuffer
@id = @constructor.idCounter++
@resetScreenLines()
@buffer.on "changed.tokenized-buffer#{@id}", (e) => @handleBufferChange(e)
@languageMode.on 'grammar-changed', => @resetScreenLines()
resetScreenLines: ->
@screenLines = @buildPlaceholderScreenLinesForRows(0, @buffer.getLastRow())

View File

@@ -1,8 +1,8 @@
fs = require 'fs-utils'
fs = require 'fs'
fsUtils = require 'fs-utils'
$ = require 'jquery'
_ = require 'underscore'
{less} = require 'less'
{spawn} = require 'child_process'
require 'jquery-extensions'
require 'underscore-extensions'
require 'space-pen-extensions'
@@ -32,14 +32,14 @@ window.setUpEnvironment = ->
requireStylesheet 'notification'
requireStylesheet 'markdown'
if nativeStylesheetPath = fs.resolveOnLoadPath(process.platform, ['css', 'less'])
if nativeStylesheetPath = fsUtils.resolveOnLoadPath(process.platform, ['css', 'less'])
requireStylesheet(nativeStylesheetPath)
# This method is only called when opening a real application window
window.startup = ->
directory = _.find ['/opt/boxen', '/opt/github', '/usr/local'], (dir) -> fs.isDirectory(dir)
directory = _.find ['/opt/boxen', '/opt/github', '/usr/local'], (dir) -> fsUtils.isDirectory(dir)
if directory
installAtomCommand(fs.join(directory, 'bin/atom'))
installAtomCommand(fsUtils.join(directory, 'bin/atom'))
else
console.warn "Failed to install `atom` binary"
@@ -73,18 +73,19 @@ window.shutdown = ->
window.git = null
window.installAtomCommand = (commandPath) ->
return if fs.exists(commandPath)
return if fsUtils.exists(commandPath)
bundledCommandPath = fs.resolve(window.resourcePath, 'atom.sh')
bundledCommandPath = fsUtils.resolve(window.resourcePath, 'atom.sh')
if bundledCommandPath?
fs.write(commandPath, fs.read(bundledCommandPath))
spawn('chmod', ['u+x', commandPath])
fsUtils.write(commandPath, fsUtils.read(bundledCommandPath))
fs.chmod(commandPath, 0o755, commandPath)
window.handleWindowEvents = ->
$(window).command 'window:toggle-full-screen', => atom.toggleFullScreen()
$(window).on 'focus', -> $("body").removeClass('is-blurred')
$(window).on 'blur', -> $("body").addClass('is-blurred')
$(window).command 'window:close', => confirmClose()
$(window).command 'window:reload', => reload()
window.deserializeWindowState = ->
RootView = require 'root-view'
@@ -99,7 +100,7 @@ window.deserializeWindowState = ->
window.project = deserialize(windowState.project) ? new Project(pathToOpen)
window.rootView = deserialize(windowState.rootView) ? new RootView
if !windowState.rootView and (!pathToOpen or fs.isFile(pathToOpen))
if !windowState.rootView and (!pathToOpen or fsUtils.isFile(pathToOpen))
rootView.open(pathToOpen)
$(rootViewParentSelector).append(rootView)
@@ -113,10 +114,10 @@ window.stylesheetElementForId = (id) ->
$("head style[id='#{id}']")
window.resolveStylesheet = (path) ->
if fs.extension(path).length > 0
fs.resolveOnLoadPath(path)
if fsUtils.extension(path).length > 0
fsUtils.resolveOnLoadPath(path)
else
fs.resolveOnLoadPath(path, ['css', 'less'])
fsUtils.resolveOnLoadPath(path, ['css', 'less'])
window.requireStylesheet = (path) ->
if fullPath = window.resolveStylesheet(path)
@@ -126,8 +127,8 @@ window.requireStylesheet = (path) ->
throw new Error("Could not find a file at path '#{path}'")
window.loadStylesheet = (path) ->
content = fs.read(path)
if fs.extension(path) == '.less'
content = fsUtils.read(path)
if fsUtils.extension(path) == '.less'
(new less.Parser).parse content, (e, tree) ->
throw new Error(e.message, path, e.line) if e
content = tree.toCSS()