This file is indexed.

/usr/share/gps/library/copy_paste.py is in gnat-gps-common 6.1.2016-1ubuntu1.

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
""" This plug-in provides various menus, contextual or not, to cut, copy and
paste text.

In particular, it also provide the capability to copy some text with the
corresponding line numbers. For example, if you select a whole buffer that
contains

procedure Void is
begin
   null;
end Void;

and activate the /Edit/Copy with line numbers menu, the following entry will
be added to the clipboard:

1. procedure Void is
2. begin
3.    null;
4. end Void;

Note that line numbers will be aligned to the biggest one, e.g.

 8. procedure Two is
 9. begin
10.    null;
11. end Two;

"""

###########################################################################
# No user customization below this line
############################################################################

import GPS
import gps_utils

GPS.Preference("Plugins/copy paste/stdmenu").create(
    "Contextual menu", "boolean",
    """If enabled, contextual menus will be created for copying, cutting and
pasting text. They will correspond to the /Edit/Copy, /Edit/Cut and
/Edit/Paste menus. You must restart GPS to take changes into account.""",
    True)

GPS.Preference("Plugins/copy paste/greyedout").create(
    "Grey out contextual menu", "boolean",
    """If disabled, contextual menu entries are hidden when not applicable.
If enabled, the entries are still visible by greyed out.
You must restart GPS to take changes into account.""",
    True)

GPS.Preference("Plugins/copy paste/copy_with_line_nums").create(
    "Copy with line numbers", "boolean",
    """If enabled a contextual menu to copy some text with the line numbers
will be created.
Otherwise, the capability will only be accessible from the /Edit/Copy with
line numbers menu and possibly the associated key shortcut.""",
    False)


def on_area(context):
    buf = GPS.EditorBuffer.get(open=False)
    if not buf:
        return False

    start = buf.selection_start()
    end = buf.selection_end()
    return start != end


@gps_utils.interactive(
    name='Copy with line numbers',
    menu='/Edit/Copy with line numbers',
    filter=on_area)
def copy_with_line_numbers():
    buffer = GPS.EditorBuffer.get()
    loc_start = buffer.selection_start()
    loc_end = buffer.selection_end().forward_char(-1)
    selection_start = loc_start.line()
    selection_end = loc_end.line()
    result = ""

    max_len = len(str(selection_end))

    for line in range(selection_start, selection_end + 1):
        if line == selection_end:
            end = loc_end
        else:
            end = loc_start.end_of_line()

        prefix = ""
        for j in range(len('%s' % line), max_len):
            prefix = prefix + " "

        result = result + '%s%s. %s' % (
            prefix, line, buffer.get_chars(loc_start, end))
        loc_start = loc_start.forward_line(1)

    GPS.Clipboard.copy(result)


@gps_utils.hook('gps_started')
def __gps_started():
    global grey_out_contextual

    if GPS.Preference("Plugins/copy paste/stdmenu").get():
        grey_out_contextual = GPS.Preference(
            "Plugins/copy paste/greyedout").get()

        # ??? Should still show them when inapplicable if grey_out_contextual
        GPS.Action('cut to clipboard').contextual('Cut', group=-1)
        GPS.Action('copy to clipboard').contextual('Copy', group=-1)
        GPS.Action('paste from clipboard').contextual('Paste', group=-1)
        GPS.Action('Copy with line numbers').contextual(
            'Copy with line numbers', group=-1)