Exemple #1
0
    def set_tags(cls):
        """ Set tags for current heading
		"""
        heading = Document.current_heading()
        if not heading:
            return

        # retrieve tags
        res = None
        if heading.tags:
            res = vim.eval(
                'input("Tags: ", ":%s:", "customlist,Org_complete_tags")' %
                ':'.join(heading.tags))
        else:
            res = vim.eval(
                'input("Tags: ", "", "customlist,Org_complete_tags")')

        if res == None:
            # user pressed <Esc> abort any further processing
            return

        # remove empty tags
        heading.tags = filter(lambda x: x.strip() != '',
                              res.strip().strip(':').split(':'))

        return 'OrgSetTags'
Exemple #2
0
	def realign_all_tags(cls):
		"""
		Updates tags when user finishes editing a heading
		"""
		for h in Document.headings():
			if h.tags:
				h.tags = h.tags
Exemple #3
0
    def realign_all_tags(cls):
        """
		Updates tags when user finishes editing a heading
		"""
        for h in Document.headings():
            if h.tags:
                h.tags = h.tags
Exemple #4
0
	def realign_tags(cls):
		"""
		Updates tags when user finished editing a heading
		"""
		heading = Document.current_heading()
		if not heading:
			return

		if vim.current.window.cursor[0] == heading.start_vim:
			heading.tags = heading.tags
Exemple #5
0
    def complete_tags(cls):
        """ build a list of tags and store it in variable b:org_tag_completion
		"""
        heading = Document.current_heading()
        if not heading:
            return

        leading_portion = vim.eval('a:ArgLead')
        cursor = int(vim.eval('a:CursorPos'))

        # extract currently completed tag
        idx_orig = leading_portion.rfind(':', 0, cursor)
        if idx_orig == -1:
            idx = 0
        else:
            idx = idx_orig

        current_tag = leading_portion[idx:cursor].lstrip(':')
        head = leading_portion[:idx + 1]
        if idx_orig == -1:
            head = ''
        tail = leading_portion[cursor:]

        # extract all tags of the current file
        all_tags = set()
        for h in Document.headings():
            for t in h.tags:
                all_tags.add(t)

        ignorecase = bool(
            int(settings.get('org_tags_completion_ignorecase', '0')))
        possible_tags = []
        current_tags = heading.tags
        for t in all_tags:
            if ignorecase:
                if t.lower().startswith(current_tag.lower()):
                    possible_tags.append(t)
            elif t.startswith(current_tag):
                possible_tags.append(t)

        vim.command(
            'let b:org_complete_tags = [%s]' %
            ', '.join(['"%s%s:%s"' % (head, i, tail) for i in possible_tags]))
Exemple #6
0
    def realign_tags(cls):
        """
		Updates tags when user finished editing a heading
		"""
        heading = Document.current_heading()
        if not heading:
            return

        if vim.current.window.cursor[0] == heading.start_vim:
            heading.tags = heading.tags
Exemple #7
0
	def complete_tags(cls):
		""" build a list of tags and store it in variable b:org_tag_completion
		"""
		heading = Document.current_heading()
		if not heading:
			return

		leading_portion = vim.eval('a:ArgLead')
		cursor = int(vim.eval('a:CursorPos'))

		# extract currently completed tag
		idx_orig = leading_portion.rfind(':', 0, cursor)
		if idx_orig == -1:
			idx = 0
		else:
			idx = idx_orig

		current_tag = leading_portion[idx: cursor].lstrip(':')
		head = leading_portion[:idx + 1]
		if idx_orig == -1:
			head = ''
		tail = leading_portion[cursor:]

		# extract all tags of the current file
		all_tags = set()
		for h in Document.headings():
			for t in h.tags:
				all_tags.add(t)

		ignorecase = bool(int(settings.get('org_tags_completion_ignorecase', '0')))
		possible_tags = []
		current_tags = heading.tags
		for t in all_tags:
			if ignorecase:
				if t.lower().startswith(current_tag.lower()):
					possible_tags.append(t)
			elif t.startswith(current_tag):
				possible_tags.append(t)

		vim.command('let b:org_complete_tags = [%s]' % ', '.join(['"%s%s:%s"' % (head, i, tail) for i in possible_tags]))
Exemple #8
0
	def toggle_todo_state(cls, direction=DIRECTION_FORWARD):
		""" Toggle state of TODO item

		:returns: The changed heading
		"""
		lineno, colno = vim.current.window.cursor

		# get heading
		heading = Document.current_heading()
		if not heading:
			vim.eval('feedkeys("^", "n")')
			return

		# get todo states
		todo_states, done_states = Todo._get_states()
		all_states = todo_states + done_states
		if len(all_states) < 2:
			echom('No todo keywords configured.')
			return

		# current_state and rest of heading
		current_state, rest = Todo._split_heading(heading.text, all_states)

		# get new state
		new_state = Todo._get_next_state(current_state, all_states, direction)

		# set new headline
		if not new_state:
			new_heading = ' '.join(('*' * heading.level, rest))
		else:
			new_heading = ' '.join(('*' * heading.level, new_state, rest))
		vim.current.buffer[heading.start] = new_heading

		# move cursor along with the inserted state only when current position
		# is in the heading; otherwite do nothing
		if heading.start_vim == lineno:
			if current_state is None:
				offset = len(new_state)
			elif new_state is None:
				offset = -len(current_state)
			else:
				offset = len(current_state) - len(new_state)
			vim.current.window.cursor = (lineno, colno + offset)

		# plug
		plug = 'OrgToggleTodoForward'
		if direction == DIRECTION_BACKWARD:
			plug = 'OrgToggleTodoBackward'
		return plug
Exemple #9
0
    def toggle_todo_state(cls, direction=DIRECTION_FORWARD):
        """ Toggle state of TODO item

		:returns: The changed heading
		"""
        lineno, colno = vim.current.window.cursor

        # get heading
        heading = Document.current_heading()
        if not heading:
            vim.eval('feedkeys("^", "n")')
            return

        # get todo states
        todo_states, done_states = Todo._get_states()
        all_states = todo_states + done_states
        if len(all_states) < 2:
            echom('No todo keywords configured.')
            return

        # current_state and rest of heading
        current_state, rest = Todo._split_heading(heading.text, all_states)

        # get new state
        new_state = Todo._get_next_state(current_state, all_states, direction)

        # set new headline
        if not new_state:
            new_heading = ' '.join(('*' * heading.level, rest))
        else:
            new_heading = ' '.join(('*' * heading.level, new_state, rest))
        vim.current.buffer[heading.start] = new_heading

        # move cursor along with the inserted state only when current position
        # is in the heading; otherwite do nothing
        if heading.start_vim == lineno:
            if current_state is None:
                offset = len(new_state)
            elif new_state is None:
                offset = -len(current_state)
            else:
                offset = len(current_state) - len(new_state)
            vim.current.window.cursor = (lineno, colno + offset)

        # plug
        plug = 'OrgToggleTodoForward'
        if direction == DIRECTION_BACKWARD:
            plug = 'OrgToggleTodoBackward'
        return plug
Exemple #10
0
	def set_tags(cls):
		""" Set tags for current heading
		"""
		heading = Document.current_heading()
		if not heading:
			return

		# retrieve tags
		res = None
		if heading.tags:
			res = vim.eval('input("Tags: ", ":%s:", "customlist,Org_complete_tags")' % ':'.join(heading.tags))
		else:
			res = vim.eval('input("Tags: ", "", "customlist,Org_complete_tags")')

		if res == None:
			# user pressed <Esc> abort any further processing
			return

		# remove empty tags
		heading.tags = filter(lambda x: x.strip() != '', res.strip().strip(':').split(':'))

		return 'OrgSetTags'