Exemple #1
0
def merge_lines(editor):
    """
	Merge lines spanned by user selection. If there's no selection, tries to find
	matching tags and use them as selection
	@param editor: Editor instance
	@type editor: ZenEditor
	"""
    start, end = editor.get_selection_range()
    if start == end:
        # find matching tag
        pair = html_matcher.match(editor.get_content(), editor.get_caret_pos(),
                                  editor.get_profile_name())
        if pair and pair[0] is not None:
            start, end = pair

    if start != end:
        # got range, merge lines
        text = editor.get_content()[start:end]
        lines = map(lambda s: re.sub(r'^\s+', '', s),
                    zen_coding.split_by_lines(text))
        text = re.sub(r'\s{2,}', ' ', ''.join(lines))
        editor.replace_content(text, start, end)
        editor.create_selection(start, start + len(text))
        return True

    return False
Exemple #2
0
def process_snippet(item, profile, level=0):
	"""
	Processes element with <code>snippet</code> type
	@type item: ZenNode
	@type profile: dict
	@param level: Depth level
	@type level: int
	"""
	data = item.source.value;
		
	if not data:
		# snippet wasn't found, process it as tag
		return process_tag(item, profile, level)
		
	item.start = placeholder
	item.end = placeholder
	
	padding = item.parent.padding if item.parent else get_indentation() * level 
	
	if not is_very_first_child(item):
		item.start = get_newline() + padding + item.start
	
	# adjust item formatting according to last line of <code>start</code> property
	parts = data.split(child_token)
	lines = zen_coding.split_by_lines(parts[0] or '')
	padding_delta = get_indentation()
		
	if len(lines) > 1:
		m = re.match(r'^(\s+)', lines[-1])
		if m:
			padding_delta = m.group(1)
	
	item.padding = padding + padding_delta
	
	return item
Exemple #3
0
def process_snippet(item, profile, level=0):
    """
	Processes element with <code>snippet</code> type
	@type item: ZenNode
	@type profile: dict
	@param level: Depth level
	@type level: int
	"""
    data = item.source.value

    if not data:
        # snippet wasn't found, process it as tag
        return process_tag(item, profile, level)

    item.start = placeholder
    item.end = placeholder

    padding = item.parent.padding if item.parent else get_indentation() * level

    if not is_very_first_child(item):
        item.start = get_newline() + padding + item.start

    # adjust item formatting according to last line of <code>start</code> property
    parts = data.split(child_token)
    lines = zen_coding.split_by_lines(parts[0] or '')
    padding_delta = get_indentation()

    if len(lines) > 1:
        m = re.match(r'^(\s+)', lines[-1])
        if m:
            padding_delta = m.group(1)

    item.padding = padding + padding_delta

    return item
	def set_caret_pos(self, pos):
		"""
		Set new caret position
		@type pos: int
		"""
		# figure out line and column vars
		head = zen.split_by_lines(self.get_content()[0:pos])
		line = max(len(head), 1)
		column = pos - len(zen.get_newline().join(head[0:-1]))
		
		subprocess.Popen(['open', 'txmt://open/?line=%d&column=%d' % (line, column)]).communicate()
Exemple #5
0
def unindent_text(text, pad):
	"""
	Removes padding at the beginning of each text's line
	@type text: str
	@type pad: str
	"""
	lines = zen_coding.split_by_lines(text)
	
	for i,line in enumerate(lines):
		if line.startswith(pad):
			lines[i] = line[len(pad):]
	
	return zen_coding.get_newline().join(lines)
Exemple #6
0
def unindent_text(text, pad):
    """
	Removes padding at the beginning of each text's line
	@type text: str
	@type pad: str
	"""
    lines = zen_coding.split_by_lines(text)

    for i, line in enumerate(lines):
        if line.startswith(pad):
            lines[i] = line[len(pad):]

    return zen_coding.get_newline().join(lines)
 def unindent(self, context, text):
     """
     Unindent content, thus preparing text for tag wrapping
     @param text: str
     @return str
     """
     pad = self.get_current_line_padding(context)
     lines = zen.split_by_lines(text)
     
     for i,line in enumerate(lines):
         if line.find(pad) == 0:
             lines[i] = line[len(pad):]
     
     return zen.get_newline().join(lines)
Exemple #8
0
def merge_lines(editor):
	"""
	Merge lines spanned by user selection. If there's no selection, tries to find
	matching tags and use them as selection
	@param editor: Editor instance
	@type editor: ZenEditor
	"""
	start, end = editor.get_selection_range()
	if start == end:
		# find matching tag
		pair = html_matcher.match(editor.get_content(), editor.get_caret_pos(), editor.get_profile_name())
		if pair and pair[0] is not None:
			start, end = pair
	
	if start != end:
		# got range, merge lines
		text = editor.get_content()[start:end]
		lines = map(lambda s: re.sub(r'^\s+', '', s), zen_coding.split_by_lines(text))
		text = re.sub(r'\s{2,}', ' ', ''.join(lines))
		editor.replace_content(text, start, end)
		editor.create_selection(start, start + len(text))
		return True
	
	return False