'If the given position is a _likely_ trigger point, return the
trigger type. Otherwise return None.'

def trg_from_pos(self, buf, pos, implicit=True, DEBUG=False):

    if (pos <= 0):
        return None
    styleClassifier = ((isinstance(buf, UDLBuffer) and _UDLStyleClassifier) or _RubyStyleClassifier)(buf)
    DEBUG = False
    if DEBUG:
        print banner(('Ruby    trg_from_pos(pos=%r,    implicit=%r)' % (pos, implicit)))
    accessor = buf.accessor
    last_pos = (pos - 1)
    last_ch = accessor.char_at_pos(last_pos)
    if DEBUG:
        print ('        last_pos:    %s' % last_pos)
        print ('        last_ch:    %r' % last_ch)
    if (last_ch not in self.trg_chars):
        last_style = accessor.style_at_pos(last_pos)
        if (last_ch.isalnum() or (last_ch == '_')):
            MIN_LENGTH = 3
            if styleClassifier.is_identifier_or_word_style(last_style):
                (start_pos, end_pos) = accessor.contiguous_style_range_from_pos(last_pos)
                if (((pos - start_pos) == MIN_LENGTH) or (not implicit)):
                    ident = accessor.text_range(start_pos, end_pos)
                    prefix = ident[:(pos - start_pos)]
                    if self._is_completable_name(start_pos, accessor, styleClassifier):
                        return Trigger('Ruby', TRG_FORM_CPLN, 'names', start_pos, implicit, length=0, prefix=prefix)
        if DEBUG:
            print ('no:    %r    is    not    in    %r' % (last_ch, self.trg_chars))
        return None
    elif (last_ch == '    '):
        if (last_pos <= 0):
            return None
        penultimate_ch = accessor.char_at_pos((last_pos - 1))
        prev_style = accessor.style_at_pos((last_pos - 1))
        if (styleClassifier.is_operator_style(prev_style) and (penultimate_ch == '<')):
            pass
        elif styleClassifier.is_identifier_or_word_style(prev_style):
            pass
        else:
            if DEBUG:
                print ("no:    %r    is    not    '<    '    or    ending    a    word(i.e.    'include    ')" % (penultimate_ch + last_ch))
            return None
    elif ((last_ch == ':') and (not ((last_pos > 0) and (accessor.char_at_pos((last_pos - 1)) == ':')))):
        if DEBUG:
            penultimate_ch = (((last_pos > 0) and accessor.char_at_pos((last_pos - 1))) or '')
            print ("no:    %r    is    not    '::'" % (penultimate_ch + last_ch))
        return None
    TRIGGER_IN_STRING_CHARS = tuple('\'"/')
    last_style = accessor.style_at_pos(last_pos)
    if DEBUG:
        style_names = buf.style_names_from_style_num(last_style)
        print ('        style:    %s    %s' % (last_style, style_names))
    suppress = False
    if implicit:
        if (last_style in styleClassifier.implicit_completion_skip_styles):
            suppress = True
        elif (last_style in styleClassifier.string_styles()):
            if (last_ch not in TRIGGER_IN_STRING_CHARS):
                suppress = True
        elif (last_ch in TRIGGER_IN_STRING_CHARS):
            suppress = True
    elif (last_style in styleClassifier.completion_skip_styles):
        suppress = True
    if suppress:
        if DEBUG:
            print ('no:    completion    is    suppressed    in    style    at    %s:    %s    %s' % (last_pos, last_style, style_names))
        return None
    WHITESPACE = tuple('     DCTB \n\r')
    EOL = tuple('\n\r')
    if (last_ch == '    '):
        LIMIT = 50
        text = accessor.text_range(max(0, (last_pos - LIMIT)), last_pos)
        if DEBUG:
            print ('        working    text:    %r' % text)
        i = (len(text) - 1)
        while (i > 0):
            if (text[i] in EOL):
                break
            i -= 1
        line = text[i:].lstrip()
        if DEBUG:
            print ('        line:    %r' % line)
        if (penultimate_ch == '<'):
            if (not line.startswith('class')):
                if DEBUG:
                    print "no:    line    does    not    start    with    'class'"
                return None
            if DEBUG:
                print 'complete-available-modules-and-classes'
            return Trigger('Ruby', TRG_FORM_CPLN, 'available-modules-and-classes', pos, implicit)
        elif (line.strip() == 'include'):
            if DEBUG:
                print 'complete-available-modules'
            return Trigger('Ruby', TRG_FORM_CPLN, 'available-modules', pos, implicit)
        else:
            if DEBUG:
                print 'calltip-call-signature'
            return Trigger('Ruby', TRG_FORM_CALLTIP, 'call-signature', pos, implicit)
    elif (last_ch == '.'):
        if (last_pos > 0):
            last_last_pos = (last_pos - 1)
            last_last_ch = accessor.char_at_pos(last_last_pos)
            if DEBUG:
                print ('        prev    char    =    %r' % last_last_ch)
            if (last_last_ch in '"\''):
                return Trigger('Ruby', TRG_FORM_CPLN, 'literal-methods', pos, implicit, literal='String')
            elif (last_last_ch == '}'):
                if ((last_pos > 1) and (accessor.char_at_pos((last_pos - 2)) == '{')):
                    return Trigger('Ruby', TRG_FORM_CPLN, 'literal-methods', pos, implicit, literal='Hash')
                else:
                    return None
            elif (last_last_ch == ']'):
                wrk_line = accessor.text_range(accessor.line_start_pos_from_pos(last_pos), last_last_pos)
                block_count = 1
                for ch in reversed(wrk_line):
                    if (not block_count):
                        if ((ch in WHITESPACE) or (ch in '=,(')):
                            return Trigger('Ruby', TRG_FORM_CPLN, 'literal-methods', pos, implicit, literal='Array')
                        return None
                    if (ch == '['):
                        block_count -= 1
                    elif (ch == ']'):
                        block_count += 1
                else:
                    return Trigger('Ruby', TRG_FORM_CPLN, 'literal-methods', pos, implicit, literal='Array')
                return None
            elif isident(last_last_ch):
                LIMIT = 50
                text = accessor.text_range(max(0, (last_pos - LIMIT)), last_pos)
                if (text.find('def') > (-1)):
                    idx = max(text.rfind('\n'), text.rfind('\r'))
                    if (idx > (-1)):
                        line = text[(idx + 1):]
                    else:
                        line = text
                    if self._method_def_header.search(line):
                        if DEBUG:
                            print '==>    bailing    out,    defining    something'
                        return None
                return Trigger('Ruby', TRG_FORM_CPLN, 'object-methods', pos, implicit)
            elif isdigit(last_last_ch):
                wrk_line = accessor.text_range(accessor.line_start_pos_from_pos(last_pos), last_pos)
                if DEBUG:
                    print "'<digit>.':    numeric    literal    or    identifier"
                    print ('check    for    leading    number    in    %r' % wrk_line)
                if self._leading_float_re.search(wrk_line):
                    return Trigger('Ruby', TRG_FORM_CPLN, 'literal-methods', pos, implicit, literal='Float')
                elif self._leading_number_re.search(wrk_line):
                    return (((not implicit) and Trigger('Ruby', TRG_FORM_CPLN, 'literal-methods', pos, implicit, literal='Fixnum')) or None)
                else:
                    return Trigger('Ruby', TRG_FORM_CPLN, 'object-methods', pos, implicit)
            else:
                return None
    elif (last_ch == '('):
        LIMIT = 100
        text = accessor.text_range(max(0, (last_pos - LIMIT)), last_pos)
        if DEBUG:
            print ('        working    text:    %r' % text)
        i = (len(text) - 1)
        while ((i >= 0) and (text[i] in WHITESPACE)):
            i -= 1
        RUBY_SPECIAL_METHOD_END_CHARS = '?!'
        if ((i >= 0) and (not (isident(text[i]) or isdigit(text[i]) or (text[i] in RUBY_SPECIAL_METHOD_END_CHARS)))):
            if DEBUG:
                print ("no:    first    non-ws    char    before    trigger    point    is    not    an    ident    char:    '%s'" % text[i])
            return None
        end = (i + 1)
        if (text[i] in RUBY_SPECIAL_METHOD_END_CHARS):
            i -= 1
        while (i >= 0):
            if isdigit(text[i]):
                pass
            elif (not isident(text[i])):
                if ((i >= 1) and (text[(i - 1):(i + 1)] == '@@')):
                    start = (i - 1)
                elif (text[i] in '$@'):
                    start = i
                else:
                    start = (i + 1)
                identifier = text[start:end]
                break
            i -= 1
        else:
            identifier = text[:end]
        if DEBUG:
            print ('        identifier:    %r' % identifier)
        if (not identifier):
            if DEBUG:
                print 'no:    no    identifier    preceding    trigger    point'
            return None
        elif isdigit(identifier[0]):
            if DEBUG:
                print 'no:    token    preceding    trigger    point    is    not    a    legal    identifier'
            return None
        if (identifier in self.RUBY_KEYWORDS):
            if DEBUG:
                print ('no:    no    trigger    on    paren    after    keyword:    %r' % identifier)
            return None
        line = text[:end].splitlines(0)[(-1)]
        if DEBUG:
            print ('        trigger    line:    %r' % line)
        if line.lstrip().startswith('def'):
            if DEBUG:
                print 'no:    no    trigger    on    Ruby    func    definition'
            return None
        if DEBUG:
            print 'calltip-call-signature'
        return Trigger('Ruby', TRG_FORM_CALLTIP, 'call-signature', pos, implicit)
    elif (last_ch in ('"', "'")):
        LIMIT = 50
        text = accessor.text_range(max(0, (last_pos - LIMIT)), last_pos)
        if DEBUG:
            print ('        working    text:    %r' % text)
        i = (len(text) - 1)
        while ((i >= 0) and (text[i] in WHITESPACE)):
            i -= 1
        LEN_REQUIRE = 7
        i += 1
        if ((i > LEN_REQUIRE) and (text[(i - LEN_REQUIRE):i] == 'require') and (text[((i - 1) - LEN_REQUIRE)] in WHITESPACE)):
            pass
        elif ((i == LEN_REQUIRE) and (text[:i] == 'require')):
            pass
        else:
            if DEBUG:
                print "no:    quote    not    preceded    by    bare    'require'"
            return None
        if DEBUG:
            print 'complete-lib-paths'
        return Trigger('Ruby', TRG_FORM_CPLN, 'lib-paths', pos, implicit)
    elif (last_ch == '/'):
        LIMIT = 75
        text = accessor.text_range(max(0, (last_pos - LIMIT)), last_pos)
        if DEBUG:
            print ('        working    text:    %r' % text)
        i = (len(text) - 1)
        while (i > 0):
            if (text[i] in EOL):
                break
            elif (not styleClassifier.is_ruby_style_at_pos(i)):
                if (i < last_pos):
                    i += 1
                break
            i -= 1
        line = text[i:].lstrip()
        if DEBUG:
            print ('        line:    %r' % line)
        LEN_REQUIRE = 7
        if ((not line.startswith('require')) or (line[LEN_REQUIRE] not in WHITESPACE) or (line[LEN_REQUIRE:].lstrip()[0] not in ("'", '"'))):
            if DEBUG:
                print ('no:    line    doesn\'t    start    with    /require\\s+[\'"]/:    <<%r>>' % line)
            return None
        if DEBUG:
            print 'complete-lib-subpaths'
        return Trigger('Ruby', TRG_FORM_CPLN, 'lib-subpaths', pos, implicit)
    elif (last_ch == ':'):
        LIMIT = 50
        text = accessor.text_range(max(0, (last_pos - LIMIT)), last_pos)
        if DEBUG:
            print ('        working    text:    %r' % text)
        i = (len(text) - 2)
        while (i >= 0):
            if isident(text[i]):
                break
            elif isdigit(text[i]):
                i -= 1
            else:
                if DEBUG:
                    print ("no:    '::'    not    preceded    with    identifier:    %r" % text[i])
                return None
        else:
            if DEBUG:
                print ("no:    '::'    not    preceded    with    identifier:    %r" % text[i])
            return None
        if DEBUG:
            print 'complete-module-names'
        return Trigger('Ruby', TRG_FORM_CPLN, 'module-names', pos, implicit, length=2)
    elif (last_ch == '@'):
        if ((last_pos > 0) and (accessor.char_at_pos((last_pos - 1)) == '@')):
            if DEBUG:
                print 'complete-class-vars'
            return Trigger('Ruby', TRG_FORM_CPLN, 'class-vars', pos, implicit, length=2)
        else:
            if DEBUG:
                print 'complete-instance-vars'
            return Trigger('Ruby', TRG_FORM_CPLN, 'instance-vars', pos, implicit)
    elif (last_ch == '$'):
        if DEBUG:
            print 'complete-global-vars'
        return Trigger('Ruby', TRG_FORM_CPLN, 'global-vars', pos, implicit)
    return None
