"""
Quote.py - A Jython macro for jEdit that puts quotes
around the currently selected text, or if there
is no selection, the current word.

Copyright (C) 2002 Ollie Rutherfurd <oliver@rutherfurd.net>

$Id: Quote.py 28 2003-03-25 22:40:28Z oliver $
"""

__author__ = 'Ollie Rutherfurd'
__version__ = '$Revision: 1.5 $'[11:-2]

from org.gjt.sp.jedit import Macros


def quoteCurrent(view):

	textArea = view.getTextArea()
	text = textArea.getSelectedText()

	# if nothing selected, select current word
	if text is None:
		textArea.selectWord()
		text = textArea.getSelectedText()

	# pick appropriate quotes
	# TODO: check mode to see what quotes are valid...
	if text.find('"') == -1:
		textArea.setSelectedText('"' + text + '"')
	elif text.find("'") == -1:
		textArea.setSelectedText("'" + text + "'")
	else:
		Macros.error(view,"Don't know how to quote.")


if __name__ in ('__main__','main'):
	quoteCurrent(init.view)

# :indentSize=4:lineSeparator=\n:noTabs=false:tabSize=4:

