Beispiel #1
0
def expand_abbreviation(editor, syntax=None, profile_name=None):
    """
	Find from current caret position and expand abbreviation in editor
	@param editor: Editor instance
	@type editor: ZenEditor
	@param syntax: Syntax type (html, css, etc.)
	@type syntax: str
	@param profile_name: Output profile name (html, xml, xhtml)
	@type profile_name: str
	@return: True if abbreviation was expanded successfully
	"""
    if syntax is None: syntax = editor.get_syntax()
    if profile_name is None: profile_name = editor.get_profile_name()

    range_start, caret_pos = editor.get_selection_range()
    abbr = find_abbreviation(editor)
    content = ''

    if abbr:
        content = zen_coding.expand_abbreviation(abbr, syntax, profile_name)
        if content:
            editor.replace_content(content, caret_pos - len(abbr), caret_pos)
            return True

    return False
import os
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))
Beispiel #3
0
def expandAbbr(abbr, doc_type='html', profile_name='plain'):
	return zen.expand_abbreviation(abbr, doc_type, profile_name)
Beispiel #4
0
try:
    if 'xsl' in scope:
        doc_type = 'xsl'
    else:
        doc_type = re.findall(r'\bhtml|css|xml\b', scope)[-1]
except:
    doc_type = 'html'

# doc_type = re.search(r'\b(html|css|xml|xsl)\b', scope)
if not doc_type:
    doc_type = 'html'

profile_name = 'xhtml'
"Output profile name"

abbr = os.getenv('TM_SELECTED_TEXT', '')
if abbr:
    result = zen_core.expand_abbreviation(abbr, doc_type, profile_name)
    if result:
        sys.stdout.write(result)
else:
    abbr, start_index = zen_core.find_abbr_in_line(cur_line, cur_index)

    if abbr:
        result = cur_line[0:start_index] + zen_core.expand_abbreviation(
            abbr, doc_type, 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(result + cur_line[cur_index:])