mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Make scope a trailing option to Config::get
This commit is contained in:
committed by
Max Brunsfeld
parent
c489a4662b
commit
c58606907a
@@ -455,15 +455,27 @@ class Config
|
||||
#
|
||||
# Returns the value from Atom's default settings, the user's configuration
|
||||
# file in the type specified by the configuration schema.
|
||||
get: (scopeDescriptor, keyPath) ->
|
||||
if arguments.length == 1
|
||||
# cannot assign to keyPath for the sake of v8 optimization
|
||||
globalKeyPath = scopeDescriptor
|
||||
@getRawValue(globalKeyPath)
|
||||
get: ->
|
||||
if arguments.length > 1
|
||||
if typeof arguments[0] is 'string'
|
||||
keyPath = arguments[0]
|
||||
options = arguments[1]
|
||||
{scope} = options
|
||||
else
|
||||
Grim.deprecate """
|
||||
Passing a scope descriptor as the first argument to Config::get is deprecated.
|
||||
Pass a `scope` in an options hash as the final argument instead.
|
||||
"""
|
||||
scope = arguments[0]
|
||||
keyPath = arguments[1]
|
||||
else
|
||||
value = @getRawScopedValue(scopeDescriptor, keyPath)
|
||||
value ?= @getRawValue(keyPath)
|
||||
value
|
||||
keyPath = arguments[0]
|
||||
|
||||
if scope?
|
||||
value = @getRawScopedValue(scope, keyPath)
|
||||
value ? @getRawValue(keyPath)
|
||||
else
|
||||
@getRawValue(keyPath)
|
||||
|
||||
# Essential: Sets the value for a configuration setting.
|
||||
#
|
||||
@@ -919,22 +931,22 @@ class Config
|
||||
scopeDescriptor = ScopeDescriptor.fromObject(scopeDescriptor)
|
||||
@scopedSettingsStore.getPropertyValue(scopeDescriptor.getScopeChain(), keyPath)
|
||||
|
||||
observeScopedKeyPath: (scopeDescriptor, keyPath, callback) ->
|
||||
oldValue = @get(scopeDescriptor, keyPath)
|
||||
observeScopedKeyPath: (scope, keyPath, callback) ->
|
||||
oldValue = @get(keyPath, {scope})
|
||||
|
||||
callback(oldValue)
|
||||
|
||||
didChange = =>
|
||||
newValue = @get(scopeDescriptor, keyPath)
|
||||
newValue = @get(keyPath, {scope})
|
||||
callback(newValue) unless _.isEqual(oldValue, newValue)
|
||||
oldValue = newValue
|
||||
|
||||
@emitter.on 'did-change', didChange
|
||||
|
||||
onDidChangeScopedKeyPath: (scopeDescriptor, keyPath, callback) ->
|
||||
oldValue = @get(scopeDescriptor, keyPath)
|
||||
onDidChangeScopedKeyPath: (scope, keyPath, callback) ->
|
||||
oldValue = @get(keyPath, {scope})
|
||||
didChange = =>
|
||||
newValue = @get(scopeDescriptor, keyPath)
|
||||
newValue = @get(keyPath, {scope})
|
||||
callback({oldValue, newValue, keyPath}) unless _.isEqual(oldValue, newValue)
|
||||
oldValue = newValue
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ class Cursor extends Model
|
||||
[before, after] = @editor.getTextInBufferRange(range)
|
||||
return false if /\s/.test(before) or /\s/.test(after)
|
||||
|
||||
nonWordCharacters = atom.config.get(@getScopeDescriptor(), 'editor.nonWordCharacters').split('')
|
||||
nonWordCharacters = atom.config.get('editor.nonWordCharacters', scope: @getScopeDescriptor()).split('')
|
||||
_.contains(nonWordCharacters, before) isnt _.contains(nonWordCharacters, after)
|
||||
|
||||
# Public: Returns whether this cursor is between a word's start and end.
|
||||
@@ -636,7 +636,7 @@ class Cursor extends Model
|
||||
# Returns a {RegExp}.
|
||||
wordRegExp: ({includeNonWordCharacters}={}) ->
|
||||
includeNonWordCharacters ?= true
|
||||
nonWordCharacters = atom.config.get(@getScopeDescriptor(), 'editor.nonWordCharacters')
|
||||
nonWordCharacters = atom.config.get('editor.nonWordCharacters', scope: @getScopeDescriptor())
|
||||
segments = ["^[\t ]*$"]
|
||||
segments.push("[^\\s#{_.escapeRegExp(nonWordCharacters)}]+")
|
||||
if includeNonWordCharacters
|
||||
|
||||
@@ -67,10 +67,10 @@ class DisplayBuffer extends Model
|
||||
|
||||
oldConfigSettings = @configSettings
|
||||
@configSettings =
|
||||
scrollPastEnd: atom.config.get(scopeDescriptor, 'editor.scrollPastEnd')
|
||||
softWrap: atom.config.get(scopeDescriptor, 'editor.softWrap')
|
||||
softWrapAtPreferredLineLength: atom.config.get(scopeDescriptor, 'editor.softWrapAtPreferredLineLength')
|
||||
preferredLineLength: atom.config.get(scopeDescriptor, 'editor.preferredLineLength')
|
||||
scrollPastEnd: atom.config.get('editor.scrollPastEnd', scope: scopeDescriptor)
|
||||
softWrap: atom.config.get('editor.softWrap', scope: scopeDescriptor)
|
||||
softWrapAtPreferredLineLength: atom.config.get('editor.softWrapAtPreferredLineLength', scope: scopeDescriptor)
|
||||
preferredLineLength: atom.config.get('editor.preferredLineLength', scope: scopeDescriptor)
|
||||
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.softWrap', ({newValue}) =>
|
||||
@configSettings.softWrap = newValue
|
||||
@@ -82,7 +82,7 @@ class DisplayBuffer extends Model
|
||||
|
||||
subscriptions.add atom.config.onDidChange scopeDescriptor, 'editor.preferredLineLength', ({newValue}) =>
|
||||
@configSettings.preferredLineLength = newValue
|
||||
@updateWrappedScreenLines() if @isSoftWrapped() and atom.config.get(scopeDescriptor, 'editor.softWrapAtPreferredLineLength')
|
||||
@updateWrappedScreenLines() if @isSoftWrapped() and atom.config.get('editor.softWrapAtPreferredLineLength', scope: scopeDescriptor)
|
||||
|
||||
subscriptions.add atom.config.observe scopeDescriptor, 'editor.scrollPastEnd', (value) =>
|
||||
@configSettings.scrollPastEnd = value
|
||||
|
||||
@@ -316,7 +316,7 @@ class LanguageMode
|
||||
@editor.setIndentationForBufferRow(bufferRow, desiredIndentLevel)
|
||||
|
||||
getRegexForProperty: (scopeDescriptor, property) ->
|
||||
if pattern = atom.config.get(scopeDescriptor, property)
|
||||
if pattern = atom.config.get(property, scope: scopeDescriptor)
|
||||
new OnigRegExp(pattern)
|
||||
|
||||
increaseIndentRegexForScopeDescriptor: (scopeDescriptor) ->
|
||||
|
||||
@@ -2812,17 +2812,17 @@ class TextEditor extends Model
|
||||
###
|
||||
|
||||
shouldAutoIndent: ->
|
||||
atom.config.get(@getRootScopeDescriptor(), "editor.autoIndent")
|
||||
atom.config.get("editor.autoIndent", scope: @getRootScopeDescriptor())
|
||||
|
||||
shouldAutoIndentOnPaste: ->
|
||||
atom.config.get(@getRootScopeDescriptor(), "editor.autoIndentOnPaste")
|
||||
atom.config.get("editor.autoIndentOnPaste", scope: @getRootScopeDescriptor())
|
||||
|
||||
shouldShowInvisibles: ->
|
||||
not @mini and atom.config.get(@getRootScopeDescriptor(), 'editor.showInvisibles')
|
||||
not @mini and atom.config.get('editor.showInvisibles', scope: @getRootScopeDescriptor())
|
||||
|
||||
updateInvisibles: ->
|
||||
if @shouldShowInvisibles()
|
||||
@displayBuffer.setInvisibles(atom.config.get(@getRootScopeDescriptor(), 'editor.invisibles'))
|
||||
@displayBuffer.setInvisibles(atom.config.get('editor.invisibles', scope: @getRootScopeDescriptor()))
|
||||
else
|
||||
@displayBuffer.setInvisibles(null)
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class TokenizedBuffer extends Model
|
||||
@currentGrammarScore = score ? grammar.getScore(@buffer.getPath(), @buffer.getText())
|
||||
@subscribe @grammar.onDidUpdate => @retokenizeLines()
|
||||
|
||||
@configSettings = tabLength: atom.config.get(@rootScopeDescriptor, 'editor.tabLength')
|
||||
@configSettings = tabLength: atom.config.get('editor.tabLength', scope: @rootScopeDescriptor)
|
||||
|
||||
@grammarTabLengthSubscription?.dispose()
|
||||
@grammarTabLengthSubscription = atom.config.onDidChange @rootScopeDescriptor, 'editor.tabLength', ({newValue}) =>
|
||||
|
||||
Reference in New Issue
Block a user