#!/usr/bin/env python # -*- coding: utf-8 -*- ''' Coda plug-in Created on Apr 20, 2009 @author: sergey ''' import os from zencoding import zen_core from zencoding.settings import zen_settings zen_core.newline = os.getenv('CODA_LINE_ENDING', zen_core.newline) zen_core.insertion_point = '$$IP$$' cur_line = 'hello world div>p' cur_index = 17 abbr = zen_core.find_abbr_in_line(cur_line, cur_index) if abbr: print(zen_core.expand_abbr(abbr))
zen_core.newline = os.getenv('TM_LINE_ENDING', zen_core.newline) point_ix = 0 def place_ins_point(text): globals()['point_ix'] += 1 return '$%s' % point_ix zen_core.insertion_point = '$$IP$$' zen_core.sub_insertion_point = '' cur_line = os.getenv('TM_CURRENT_LINE', '') cur_index = int(os.getenv('TM_LINE_INDEX', 0)) # doc_type = re.search(r'\b(html|css|xml|xsl)\b', scope) doc_type = 'html' abbr, start_index = zen_core.find_abbr_in_line(cur_line, cur_index) if abbr: result = cur_line[0:start_index] + zen_core.expand_abbr(abbr, doc_type) 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:]) else: sys.stdout.write(cur_line[0:cur_index] + zen_settings['indentation'] + '$$IP$$' + cur_line[cur_index:])
def act( context, default=None, alpha_numeric=True, extra_characters="", bidirectional=True, mode=None, close_string="", undo_name=None, **syntaxes ): """ Required action method Transforms the word under the cursor (or the word immediately previous to the cursor) into a snippet (or processes it using zen-coding) The snippet offers two placeholders: $SELECTED_TEXT: replaced with the word, or any selected text $WORD: if text is selected, replaced just with the first word """ if default is None: return False range = tea.get_single_range(context, True) if range == None: return False # Check for specific zone override snippet = tea.select_from_zones(context, range, default, **syntaxes) # Fetch the word word, new_range = tea.get_word_or_selection(context, range, alpha_numeric, extra_characters, bidirectional) if word == "": # No word, so nothing further to do return False # If we're using $WORD, make sure the word is just a word if snippet.find("$WORD") >= 0: fullword = word word = tea.parse_word(word) if word is None: word = "" else: fullword = word # We've got some extra work if the mode is HTML or zen # This is a really hacky solution, but I can't think of a concise way to # represent this functionality via XML if mode == "zen" and fullword.find(" ") < 0: # Set up the config variables zen_core.newline = tea.get_line_ending(context) # This allows us to use smart incrementing tab stops in zen snippets global point_ix point_ix = 0 def place_ins_point(text): globals()["point_ix"] += 1 return "$%s" % point_ix zen_core.insertion_point = place_ins_point zen_core.sub_insertion_point = place_ins_point zen_core.selfclosing_string = tea.get_tag_closestring(context) zen_settings["indentation"] = tea.get_indentation_string(context) # Detect the type of document we're working with zones = {"css, css *": "css", "xsl, xsl *": "xsl", "xml, xml *": "xml"} doc_type = tea.select_from_zones(context, range, "html", **zones) # Prepare the snippet snippet = zen_core.expand_abbr(fullword, doc_type) elif (mode == "zen" or mode == "html") and tea.is_selfclosing(word): # Self-closing, so construct the snippet from scratch snippet = "<" + fullword if fullword == word and not fullword in ["br", "hr"]: snippet += " $1" snippet += "$E_XHTML>$0" # Indent the snippet snippet = tea.indent_snippet(context, snippet, new_range) # Special replacement in case we're using $WORD snippet = snippet.replace("$WORD", word) # Construct the snippet snippet = tea.construct_snippet(fullword, snippet) return tea.insert_snippet_over_range(context, snippet, new_range, undo_name)
sys.stderr.write(str(os.environ)) from zencoding import zen_core from zencoding.settings import zen_settings zen_core.newline = os.getenv('TM_LINE_ENDING', zen_core.newline) point_ix = 0 def place_ins_point(text): globals()['point_ix'] += 1 return '$%s' % point_ix zen_core.insertion_point = '$$IP$$' zen_core.sub_insertion_point = '' cur_line = os.getenv('TM_CURRENT_LINE', '') cur_index = int(os.getenv('TM_LINE_INDEX', 0)) # doc_type = re.search(r'\b(html|css|xml|xsl)\b', scope) doc_type = 'html' abbr, start_index = zen_core.find_abbr_in_line(cur_line, cur_index) if abbr: result = cur_line[0:start_index] + zen_core.expand_abbr(abbr, doc_type) 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:]) else: sys.stdout.write(cur_line[0:cur_index] + zen_settings['indentation'] + '$$IP$$' + cur_line[cur_index:])