def find_nearest_symbols(view, selector, location, above_only=True):
    """Find nearest unique symbols by selector.

    The function is a wrapper around `sublime.View.find_by_selector()` to
    return unique symbols. It is an alternative to `sublime.View.symbols()`
    which does not require symbols to be defined in a _*.tmPreference_ file.

    Arguments:
        view (sublime.View):
            the view the symbol is defined in
        selector (string):
            the scope query to pass to view.find_by_selector
        location (int):
            the text position to use to decide which find results to include
        above_only (bool):
            if True, skip all symbols followed by location (default: True)

    Returns:
        dict {symbol: region}:
            the dictionary using the symbol as key and its region as value
    """
    symbols = {}
    for region in view.find_by_selector(selector):
        # ignore declarations following the current cursor position
        if above_only and region.a > location:
            break
        symbol = view.substr(region)
        # check whether we already caught a symbol with a lower distance
        sym = symbols.get(symbol)
        if sym and abs(sym.a - location) < abs(region.a - location):
            continue
        # finally add the new symbol or update an existing one
        symbols[symbol] = region
    return symbols