Files
gnatstudio/examples/python/misc_text_utils.py
Pat Rogers a2d0e9d29f text utils used by ada expansion and formatting facilities
git-svn-id: svn+ssh://svn.eu/Dev/importfromcvs/trunk@90931 936e1b1b-40f2-da11-902a-00137254ae57
2005-03-02 16:06:51 +00:00

67 lines
1.7 KiB
Python
Executable File

import os
import string
import GPS
import text_utils; #from gps/share
#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