import sublime, sublime_plugin, os

try:
  import expand_region_handler
except:
  from . import expand_region_handler

class ExpandRegionCommand(sublime_plugin.TextCommand):
  def run(self, edit, debug=False):
    
    name, extension = os.path.splitext(self.view.file_name())

    region = self.view.sel()[0]
    string = self.view.substr(sublime.Region(0, self.view.size()))
    start = region.begin()
    end = region.end()

    result = expand_region_handler.expand(string, start, end, extension[1:])
    if result:
      self.view.sel().add(sublime.Region(result["start"], result["end"]))
      if debug:
        print("startIndex: {0}, endIndex: {1}, type: {2}".format(result["start"], result["end"], result["type"]))
@@ -215,14 +215,8 @@
 %0A   
- name,
  ext
@@ -223,16 +223,72 @@
 ension =
+ %22%22%0A    if (self.view.file_name()):%0A      name, fileex =
  os.path
@@ -319,16 +319,45 @@
 _name())
+%0A      extension = fileex%5B1:%5D
 %0A%0A    re
@@ -571,20 +571,16 @@
 xtension
-%5B1:%5D
 )%0A    if

Fix exception, when view has no filename (is not saved), fix #27