mirror of
https://github.com/atom/atom.git
synced 2026-02-13 16:14:59 -05:00
Store TM bundle start/end comment strings in scoped properties
Previously, we had a custom method on the `TextMateBundle` class for retrieving these variables from the bundle. Now we're using Atom's `syntax.getProperty` mechanism. The idea is to map TextMate concepts to their Atom equivalent, rather than building everything directly around TextMate.
This commit is contained in:
@@ -67,14 +67,14 @@ class LanguageMode
|
||||
|
||||
toggleLineCommentsForBufferRows: (start, end) ->
|
||||
scopes = @editSession.scopesForBufferPosition([start, 0])
|
||||
return unless commentStartString = TextMateBundle.lineCommentStartStringForScope(scopes[0])
|
||||
return unless commentStartString = syntax.getProperty(scopes, "editor.commentStart")
|
||||
|
||||
buffer = @editSession.buffer
|
||||
commentStartRegexString = _.escapeRegExp(commentStartString).replace(/(\s+)$/, '($1)?')
|
||||
commentStartRegex = new OnigRegExp("^(\\s*)(#{commentStartRegexString})")
|
||||
shouldUncomment = commentStartRegex.test(buffer.lineForRow(start))
|
||||
|
||||
if commentEndString = TextMateBundle.lineCommentEndStringForScope(scopes[0])
|
||||
if commentEndString = syntax.getProperty(scopes, "editor.commentEnd")
|
||||
if shouldUncomment
|
||||
commentEndRegexString = _.escapeRegExp(commentEndString).replace(/^(\s+)/, '($1)?')
|
||||
commentEndRegex = new OnigRegExp("(#{commentEndRegexString})(\\s*)$")
|
||||
|
||||
@@ -17,5 +17,5 @@ class Package
|
||||
@path = fs.directory(@path) unless fs.isDirectory(@path)
|
||||
|
||||
load: ->
|
||||
# WIP: Going to load scoped properties into `syntax` global here
|
||||
@getScopedProperties()
|
||||
for { selector, properties } in @getScopedProperties()
|
||||
syntax.addProperties(selector, properties)
|
||||
|
||||
@@ -42,7 +42,8 @@ class Syntax
|
||||
matchingProperties.concat([@globalProperties])
|
||||
|
||||
matchingPropertiesForElement: (element, candidates) ->
|
||||
matchingScopedProperties = candidates.filter ({selector}) -> jQuery.find.matchesSelector(element, selector)
|
||||
matchingScopedProperties = candidates.filter ({selector}) ->
|
||||
jQuery.find.matchesSelector(element, selector)
|
||||
matchingScopedProperties.sort (a, b) ->
|
||||
if a.specificity == b.specificity
|
||||
b.index - a.index
|
||||
|
||||
@@ -58,12 +58,6 @@ class TextMateBundle
|
||||
values = @getPreferenceInScope(scope, preferenceName)
|
||||
(_.find values, ({name}) -> name is valueName)?['value']
|
||||
|
||||
@lineCommentStartStringForScope: (scope) ->
|
||||
@getPreferenceValueInScope(scope, 'shellVariables', 'TM_COMMENT_START')
|
||||
|
||||
@lineCommentEndStringForScope: (scope) ->
|
||||
@getPreferenceValueInScope(scope, 'shellVariables', 'TM_COMMENT_END')
|
||||
|
||||
@indentRegexForScope: (scope) ->
|
||||
if source = @getPreferenceInScope(scope, 'increaseIndentPattern')
|
||||
new OnigRegExp(source)
|
||||
|
||||
@@ -2,17 +2,18 @@ Package = require 'package'
|
||||
TextMateBundle = require 'text-mate-bundle'
|
||||
fs = require 'fs'
|
||||
plist = require 'plist'
|
||||
_ = require 'underscore'
|
||||
|
||||
module.exports =
|
||||
class TextMatePackage extends Package
|
||||
@testName: (packageName) ->
|
||||
/(\.|_|-)tmbundle$/.test(packageName)
|
||||
|
||||
@translateScopeSelector: (scopeSelector) ->
|
||||
@cssSelectorForScopeSelector: (scopeSelector) ->
|
||||
scopeSelector.split(', ').map((commaFragment) ->
|
||||
commaFragment.split(' ').map((spaceFragment) ->
|
||||
spaceFragment.split('.').map((dotFragment) ->
|
||||
'.' + dotFragment
|
||||
'.' + dotFragment.replace(/\+/g, '\\+')
|
||||
).join('')
|
||||
).join(' ')
|
||||
).join(', ')
|
||||
@@ -30,11 +31,25 @@ class TextMatePackage extends Package
|
||||
scopedProperties = []
|
||||
if fs.exists(@preferencesPath)
|
||||
for preferencePath in fs.list(@preferencesPath)
|
||||
plist.parseString fs.read(preferencePath), (e, data) ->
|
||||
plist.parseString fs.read(preferencePath), (e, data) =>
|
||||
if e
|
||||
console.warn "Failed to parse preference at path '#{preferencePath}'", e.stack
|
||||
else
|
||||
{ scope, settings } = data[0]
|
||||
selector = TextMatePackage.translateScopeSelector(scope) if scope?
|
||||
scopedProperties.push({selector: selector, properties: settings})
|
||||
if properties = @translateProperties(settings)
|
||||
selector = TextMatePackage.cssSelectorForScopeSelector(scope) if scope?
|
||||
scopedProperties.push({selector, properties})
|
||||
scopedProperties
|
||||
|
||||
translateProperties: (textMateSettings) ->
|
||||
if textMateSettings.shellVariables
|
||||
shellVariables = {}
|
||||
for {name, value} in textMateSettings.shellVariables
|
||||
shellVariables[name] = value
|
||||
textMateSettings.shellVariables = shellVariables
|
||||
|
||||
editorProperties = _.compactObject(
|
||||
commentStart: _.valueForKeyPath(textMateSettings, 'shellVariables.TM_COMMENT_START')
|
||||
commentEnd: _.valueForKeyPath(textMateSettings, 'shellVariables.TM_COMMENT_END')
|
||||
)
|
||||
{ editor: editorProperties } if _.size(editorProperties) > 0
|
||||
|
||||
@@ -92,3 +92,9 @@ _.mixin
|
||||
object = object[key]
|
||||
return unless object?
|
||||
object
|
||||
|
||||
compactObject: (object) ->
|
||||
newObject = {}
|
||||
for key, value of object
|
||||
newObject[key] = value if value?
|
||||
newObject
|
||||
|
||||
Reference in New Issue
Block a user