This file is indexed.

/usr/share/gps/plug-ins/locations_view_utils.py is in gnat-gps-common 5.0-13.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
"""This plug-in adds a menu File->Messages->Export Locations to editor
   which opens an editor with the contents of the Locations view.
"""


import GPS

def message_compare (a, b):
    """ Comparison function between two messages: compare messages based on
        line, then column, then text.
    """
    if a.get_line() < b.get_line():
        return -1
    if a.get_column() < b.get_column():
        return -1
    if a.get_text() < b.get_text():
        return -1
    return 1

def remove_markup(text):
    """ Remove pango markup from text """

    remove = False
    result = ""
    for c in text:
        if c == '<':
            remove=True
        elif c == '>':
            remove=False
        else:
            if not remove:
                result += c

    return result

def export_locations_to_editor (menu):
    """ Export all messages listed in the Locations view to an editor.
    """

    categories = {}
    files      = {}

    # Get all messages

    msgs = GPS.Message.list()

    # Filter them and organize them by category and file
    for m in msgs:
        if m.get_flags() & 2 == 0:
            file     = m.get_file()
            category = m.get_category()

            if category in categories:
                if file in categories[category]:
                    categories[category][file]+=[m]
                else:
                    categories[category][file]=[m]
            else:
                categories[category]={file:[m]}

    if not categories:
        GPS.MDI.dialog ("The Locations view is empty.")
        return

    # Construct a string that we will write in the editor

    text = ""

    categories_list = [c for c in categories]
    categories_list.sort()

    for c in categories_list:
        text += c + "\n"

        files_list = [f for f in categories[c]]
        files_list.sort()

        for f in files_list:
             text += "    " + f.name() + "\n"
             messages = categories[c][f]
             messages.sort (message_compare)

             for m in messages:
                 text += "        %s:%s %s\n" % (
                    m.get_line(),
                    m.get_column(),
                    remove_markup(m.get_text()))

        text += "\n"

    # Open an editor

    GPS.execute_action ("/File/new")
    buf = GPS.EditorBuffer.get()

    # Write the contents
    buf.insert (GPS.EditorLocation (buf, 1, 1), text)


GPS.Menu.create ("/File/Messages/Export Locations to editor", export_locations_to_editor)