"""
Go_to_Column.py - A Jython macro for jEdit which allows the user 
to move the caret to a specified column on the current line.

Copyright (C) 2003 Ollie Rutherfurd <oliver@rutherfurd.net>

$Id: Go_to_Column.py 58 2003-11-03 21:49:26Z oliver $
"""

from org.gjt.sp.jedit import Macros

def gotoColumn(view):
	textArea = view.getTextArea()
	line = textArea.getCaretLine()
	line_len = textArea.getLineLength(line) + 1
	col = None
	while 1:
		col = Macros.input(view, 'Column (between 1 and %d):' % line_len)
		if col is None:
			return
		try:
			col = int(col)
			if 1 <= col <= line_len:
				break
		except ValueError:
			pass
	col = col - 1
	textArea.setCaretPosition(textArea.getLineStartOffset(line) + col)
	textArea.requestFocus()

if __name__ in ('__main__','main'):
	gotoColumn(init.view)

# :indentSize=4:lineSeparator=\n:noTabs=false:tabSize=4:

