'Completes brackets if auto_match is enabled; also implements the
"smart_bracket_auto_trigger" logic, which tries to complete the nearest
open bracket intelligently.
:param view:
the current view
:param edit:
the current edit
:param insert_char:
the character to try to automatch'

def complete_auto_match(self, view, edit, insert_char):

    if sublime.load_settings('Preferences.sublime-settings').get('auto_match_enabled', True):
        if insert_char:
            self.insert_at_end(view, edit, self.get_match_char(insert_char))
            if (insert_char in self.MATCH_CHARS):
                new_regions = []
                for sel in view.sel():
                    if (not sel.empty()):
                        new_regions.append(sel)
                    else:
                        new_point = (sel.end() - 1)
                        new_regions.append(getRegion(new_point, new_point))
                self.update_selections(view, new_regions)
                return
        elif get_setting('smart_bracket_auto_trigger', True):
            new_regions = []
            for sel in view.sel():
                word_region = self.get_current_word(view, sel)
                close_bracket = self.get_closing_bracket(view, word_region)
                if close_bracket:
                    view.insert(edit, word_region.end(), close_bracket)
                    if sel.empty():
                        if word_region.empty():
                            new_regions.append(getRegion(word_region.end(), word_region.end()))
                        else:
                            new_point = (word_region.end() + len(close_bracket))
                            new_regions.append(getRegion(new_point, new_point))
                    else:
                        new_regions.append(getRegion(sel.begin(), (word_region.end() + len(close_bracket))))
                else:
                    new_regions.append(sel)
            self.update_selections(view, new_regions)
