Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
Merge branch 'case-insensitivity'
Browse files Browse the repository at this point in the history
Resolves #27.
  • Loading branch information
execjosh committed Jul 25, 2015
2 parents 19409ef + ee04238 commit e291869
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/file-types.coffee
Expand Up @@ -9,6 +9,9 @@ module.exports =
$debug:
type: 'boolean'
default: no
$caseSensitive:
type: 'boolean'
default: no

debug: no

Expand Down Expand Up @@ -43,6 +46,7 @@ module.exports =

loadConfig: (config = {}) ->
@debug = config.$debug is yes
@caseSensitive = config.$caseSensitive is yes
@snp = new ScopeNameProvider()
for fileType, scopeName of config
# Skip special settings
Expand All @@ -60,7 +64,7 @@ module.exports =

_tryToSetGrammar: (editor) ->
filename = basename editor.getPath()
scopeName = @snp.getScopeName filename
scopeName = @snp.getScopeName filename, caseSensitive: @caseSensitive
unless scopeName?
@_log "no custom scopeName for #{filename}...skipping"
return
Expand Down
29 changes: 22 additions & 7 deletions lib/scope-name-provider.coffee
Expand Up @@ -13,18 +13,29 @@ class ScopeNameProvider
return # void

registerMatcher: (matcher, scopeName) ->
regexp = new RegExp matcher
@_matchers[scopeName] ?= []
@_matchers[scopeName].push regexp
@_matchers[scopeName].push matcher
@_scopeNames[scopeName] = scopeName
return # void

getScopeName: (filename) ->
getScopeName: (filename, opts = {}) ->
ext = extname filename
scopeName = @_exts[ext]

if opts.caseSensitive
scopeName = @_exts[ext]
else
matches = Object.keys(@_exts).filter (e) ->
e.toLowerCase() is ext.toLowerCase()
if matches.length >= 1
scopeName = @_exts[matches[0]]
if matches.length > 1
atom.notifications.addWarning '[file-types] Multiple Matches',
detail: "Assuming '#{matches[0]}' (#{scopeName}) for file '#{filename}'."
dismissable: true

return scopeName if scopeName?

@_matchFilename filename
@_matchFilename filename, opts

getScopeNames: ->
Object.keys @_scopeNames
Expand All @@ -33,7 +44,11 @@ class ScopeNameProvider
# private
#

_matchFilename: (filename) ->
_matchFilename: (filename, opts = {}) ->
for scopeName, matchers of @_matchers
for matcher in matchers
return scopeName if matcher.test filename
if opts.caseSensitive
regexp = new RegExp matcher
else
regexp = new RegExp matcher, 'i'
return scopeName if regexp.test filename

0 comments on commit e291869

Please sign in to comment.