# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#

# Settings to assign based on grammar name.
fileTypes =
  "GitHub Markdown": (editor) ->
    editor.setSoftWrap(true)
    editor.setTabLength(4)

  "Java": (editor) ->
    editor.setTabLength(4)

  "Python": (editor) ->
    editor.setTabLength(4)

# Apply grammar-specific settings.
#
# editor - Editor to which to apply the grammar-specific settings.
applyGrammarSettings = (editor) ->
  func(editor) for name, func of fileTypes when name is editor.getGrammar().name

# Executes for each and every Editor, past and future.
atom.workspace.eachEditor (editor) ->
  applyGrammarSettings(editor)

  editor.on 'grammar-changed', ->
    applyGrammarSettings(editor)

# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#

# Settings to assign based on grammar name.
grammarSettings =
  'GitHub Markdown':
    softWrap: true
    tabLength: 4
  Java:
    tabLength: 4
  Python:
    tabLength: 4

# Apply the settings to the editor session.
#
# editor - Editor to which to apply the settings.
# settings - The settings to apply.
applySettingsForGrammar = (editor, settings) ->
  for key, value of settings
    switch key
      when 'softWrap' then editor.setSoftWrap(value)
      when 'tabLength' then editor.setTabLength(value)

# Apply grammar-specific settings.
#
# editor - Editor to which to apply the grammar-specific settings.
applySettings = (editor) ->
  settings = grammarSettings[editor.getGrammar().name]
  return unless settings?

  applySettingsForGrammar(editor, settings)

# Executes for each and every Editor, past and future.
atom.workspace.eachEditor (editor) ->
  applySettings(editor)

  editor.on 'grammar-changed', ->
    applySettings(editor)

Simplify the grammar settings code even further
Simplify the grammar settings code even further

Since we're now using standard CoffeeScript object notation, the
code can be simplified even further to make things more modular and
obvious.
