File: misc_text_utils.py

package info (click to toggle)
gnat-gps 18-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,716 kB
  • sloc: ada: 362,679; python: 31,031; xml: 9,597; makefile: 1,030; ansic: 917; sh: 264; java: 17
file content (70 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download
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
"""miscellaneous text utilities, on top of text_utils, used by other plug-ins
"""


import GPS
import text_utils

# inserts text at current position in current file with a newline at the end


def insert_line(text):
    GPS.Editor.insert_text("\n" + text)
# end insert_line


# replaces current line in current_file with specified new line
def replace_line(current_file, new_line):
    line_num = GPS.Editor.cursor_get_line(current_file)
    line = GPS.Editor.get_chars(current_file, line_num, 0)
    if line[len(line) - 1] == '\n':
        GPS.Editor.replace_text(current_file, line_num,
                                0, new_line, 0, len(line) - 1)
    else:
        GPS.Editor.replace_text(current_file, line_num,
                                0, new_line, 0, len(line))
    # end if
# end replace_line


# get current line from current file
def get_line():
    file = GPS.current_context().file().name()
    line_num = GPS.current_context().location().line()
    str = GPS.Editor.get_chars(file, line_num, 0)
    return str[:-1]  # omit the '\n'
# end get_line


# move up 'count' lines in the current file
def up(count=1):
    file = GPS.current_context().file().name()
    line = GPS.current_context().location().line()
    GPS.Editor.cursor_set_position(file, line - count)
# end up


# move down 'count' lines in the current file
def down(count=1):
    text_utils.next_line(count)
# end down


# attempt to move up 'count' lines in the current file, returning
# success/failure indication
def attempt_up(count=1):
    line = GPS.current_context().location().line()
    if line - count > 0:
        file = GPS.current_context().file().name()
        GPS.Editor.cursor_set_position(file, line - count)
        return True
    else:
        return False
    # end if
# end attempt_up


# return 'width' blanks
def blanks(width):
    return ' ' * width
# end blanks