Ejemplo n.º 1
0
	def testExtract(self):
		abbr = 'ul#nav>li.$$item$$$*3>a+span'
		abbr2 = 'table>tr>td[colspan=2 title="Hello world"]>span'
		
		self.assertEqual(abbr, zen.extract_abbreviation(abbr));
		self.assertEqual(abbr, zen.extract_abbreviation('<p>' +  abbr))
		self.assertEqual(abbr, zen.extract_abbreviation('hello ' + abbr))
		self.assertEqual(abbr2, zen.extract_abbreviation('<div>' + abbr2))
		self.assertEqual(abbr2, zen.extract_abbreviation('hello ' + abbr2))
Ejemplo n.º 2
0
def find_abbreviation(editor):
	"""
	Search for abbreviation in editor from current caret position
	@param editor: Editor instance
	@type editor: ZenEditor
	@return: str
	"""
	start, end = editor.get_selection_range()
	if start != end:
		# abbreviation is selected by user
		return editor.get_content()[start:end]
	
	# search for new abbreviation from current caret position
	cur_line_start, cur_line_end = editor.get_current_line_range()
	return zen_coding.extract_abbreviation(editor.get_content()[cur_line_start:start])
Ejemplo n.º 3
0
def find_abbreviation(editor):
	"""
	Search for abbreviation in editor from current caret position
	@param editor: Editor instance
	@type editor: ZenEditor
	@return: str
	"""
	start, end = editor.get_selection_range()
	if start != end:
		# abbreviation is selected by user
		return editor.get_content()[start:end];

	# search for new abbreviation from current caret position
	cur_line_start, cur_line_end = editor.get_current_line_range()
	return zen_coding.extract_abbreviation(editor.get_content()[cur_line_start:start])
from zencoding import zen_core
from zen_editor import ZenEditor

editor = ZenEditor()
"""
In order to make "Expand Abbreviation" more natural to
TextMate's bundle system we have to forget about predefined Zen Coding actions
and write our own
"""

abbr = os.getenv('TM_SELECTED_TEXT', '')
if abbr:
    result = zen_core.expand_abbreviation(abbr, editor.get_syntax(),
                                          editor.get_profile_name())
    if result:
        sys.stdout.write(editor.add_placeholders(result))
else:
    cur_line = os.getenv('TM_CURRENT_LINE', '')
    cur_index = int(os.getenv('TM_LINE_INDEX', 0))
    line = cur_line[0:cur_index]
    abbr = zen_core.extract_abbreviation(line)

    if abbr:
        result = line[0:-len(abbr)] + zen_core.expand_abbreviation(
            abbr, editor.get_syntax(), editor.get_profile_name())
        cur_line_pad = re.match(r'^(\s+)', cur_line)
        if cur_line_pad:
            result = zen_core.pad_string(result, cur_line_pad.group(1))

        sys.stdout.write(
            editor.add_placeholders(result) + cur_line[cur_index:])
Ejemplo n.º 5
0
def extractAbbr(line):
	return zen.extract_abbreviation(line)
import sys
import re
from zencoding import zen_core
from zen_editor import ZenEditor

editor = ZenEditor()

"""
In order to make "Expand Abbreviation" more natural to
TextMate's bundle system we have to forget about predefined Zen Coding actions
and write our own
"""

abbr = os.getenv('TM_SELECTED_TEXT', '')
if abbr:
	result = zen_core.expand_abbreviation(abbr, editor.get_syntax(), editor.get_profile_name())
	if result:
		sys.stdout.write(editor.add_placeholders(result))
else:
	cur_line = os.getenv('TM_CURRENT_LINE', '')
	cur_index = int(os.getenv('TM_LINE_INDEX', 0))
	line = cur_line[0:cur_index]
	abbr = zen_core.extract_abbreviation(line)

	if abbr:
		result = line[0:-len(abbr)] + zen_core.expand_abbreviation(abbr, editor.get_syntax(), editor.get_profile_name())
		cur_line_pad = re.match(r'^(\s+)', cur_line)
		if cur_line_pad:
			result = zen_core.pad_string(result, cur_line_pad.group(1))
			
		sys.stdout.write(editor.add_placeholders(result) + cur_line[cur_index:])